Python Collector
Analyze Python projects to collect build tool info, dependencies, test coverage, and CI/CD command tracking. Enforce Python-specific engineering standards.
python to your lunar-config.yml:uses: github://earthly/lunar-lib/collectors/python@v1.0.0
What This Integration Collects
This integration includes 4 collectors that gather metadata from your systems.
cicd
Records every Python/pip/poetry/uv command executed in CI pipelines along with the Python version. Writes command strings and version info to .lang.python.cicd for audit trails and build reproducibility analysis.
test-coverage
Extracts coverage percentage from coverage.xml (pytest-cov output) after test runs complete. Parses the XML coverage report and writes results to .lang.python.tests.coverage and .testing.coverage.
project
Analyzes Python project structure by detecting pyproject.toml, requirements.txt, setup.py, Pipfile, lockfiles, and linter/type-checker configuration. Extracts the Python version and build systems. Writes project metadata to .lang.python.
dependencies
Extracts direct dependencies from requirements.txt and pyproject.toml. Captures package name and version for each dependency. Writes the dependency list to .lang.python.dependencies.
How Collectors Fit into Lunar
Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.
Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.
Learn How Lunar Works →Example Collected Data
This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:
{
"lang": {
"python": {
"version": "3.12.1",
"build_systems": ["poetry"],
"pyproject_exists": true,
"requirements_txt_exists": false,
"setup_py_exists": false,
"pipfile_exists": false,
"poetry_lock_exists": true,
"pipfile_lock_exists": false,
"python_version_file_exists": true,
"linter_configured": true,
"linter": "ruff",
"type_checker_configured": true,
"type_checker": "mypy",
"source": { "tool": "python", "integration": "code" },
"cicd": {
"cmds": [{ "cmd": "pytest --cov=src", "version": "3.12.1" }],
"source": { "tool": "python", "integration": "ci" }
},
"tests": {
"coverage": {
"percentage": 85.5,
"source": { "tool": "coverage", "integration": "ci" }
}
},
"dependencies": {
"direct": [
{ "path": "flask", "version": "3.0.0", "indirect": false }
],
"transitive": [],
"source": { "tool": "pip", "integration": "code" }
}
}
},
"testing": {
"coverage": {
"percentage": 85.5,
"source": { "tool": "coverage", "integration": "ci" }
},
"source": { "tool": "pytest", "integration": "ci" }
}
}
Documentation
View on GitHubPython Collector
Collects Python project information, CI/CD commands, dependencies, and test coverage.
Overview
This collector gathers metadata about Python projects including build tool detection, dependency lists, test coverage metrics, and CI/CD command tracking. It runs on both code changes (for static analysis of project structure) and CI hooks (to capture runtime metrics like test coverage and command versions).
Note: The CI-hook collectors (test-coverage, cicd) don't run tests—they observe and collect data from pytest/python commands that your CI pipeline already runs.
Collected Data
This collector writes to the following Component JSON paths:
| Path | Type | Description |
|---|---|---|
.lang.python |
object | Python project metadata (version, build systems, native file detection) |
.lang.python.cicd |
object | CI/CD command tracking with Python version |
.lang.python.tests |
object | Test coverage information |
.lang.python.dependencies |
object | Direct dependencies |
.testing.coverage |
object | Normalized cross-language coverage data |
.testing.source |
object | Test execution source metadata |
Collectors
This plugin provides the following collectors (use include to select a subset):
| Collector | Hook Type | Description |
|---|---|---|
project |
code | Collects Python project structure (pyproject.toml, requirements.txt, lockfiles, linter config) |
dependencies |
code | Collects Python dependency list from requirements.txt or pyproject.toml |
cicd |
ci-before-command | Tracks Python/pip/poetry commands run in CI with version info |
test-coverage |
ci-after-command | Extracts coverage from coverage.xml after pytest runs |
Installation
Add to your lunar-config.yml:
collectors:
- uses: github://earthly/lunar-lib/collectors/python@v1.0.0
on: [python] # Or use domain: ["domain:your-domain"]
# include: [project, dependencies] # Only include specific subcollectors
Open Source
This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.
Common Use Cases
Explore guardrails that use data from Python Collector.
Ready to Automate Your Standards?
See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.