Hamburger Cross Icon
Python Collector - Lunar Collector

Python Collector

Collector Beta LanguagesBuild

Analyze Python projects to collect build tool info, dependencies, test coverage, and CI/CD command tracking. Enforce Python-specific engineering standards.

Add 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.

Collector ci-before-command

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.

python ci pip poetry ci commands build tracking
Book a demo
Collector ci-after-command

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.

pytest coverage test coverage coverage.xml
Book a demo
Collector code

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.

python project pyproject.toml requirements.txt poetry pip
Book a demo
Collector code

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.

python dependencies pip poetry supply chain packages
Book a demo

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
1
Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "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 GitHub

Python 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.

View Repository

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.

Works with any process
check Infrastructure conventions
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Automate Now
Turn any process doc into guardrails
Book a Demo