Hamburger Cross Icon
Python Project Guardrails - Lunar Policy for Devex Build And Ci

Python Project Guardrails

✓ Policy Beta Devex Build And Ci

Enforce Python-specific project standards including lockfile presence, linter configuration, and Python version requirements.

Add python to your lunar-config.yml:
uses: github://earthly/lunar-lib/policies/python@v1.0.5

Included Guardrails

This policy includes 4 guardrails that enforce standards for your devex build and ci.

Guardrail

lockfile-exists

Ensures the project has a dependency lockfile (poetry.lock, Pipfile.lock, or pinned requirements.txt) for reproducible builds.

lockfile poetry.lock Pipfile.lock reproducibility
View Guardrail
Guardrail

linter-configured

Ensures a Python linter is configured (ruff, flake8, or pylint). Linters catch bugs and enforce consistent code style.

linter ruff flake8 pylint code quality
View Guardrail
Guardrail

min-python-version

Ensures the project uses at least the minimum required Python version. Helps maintain security and compatibility standards.

python version compatibility security
View Guardrail
Guardrail

min-python-version-cicd

Ensures the Python version used in CI/CD commands meets the minimum required version for build environments.

python version ci/cd compatibility security
View Guardrail

How Guardrails Fit into Lunar

Lunar guardrails define your engineering standards as code. They evaluate data collected by integrations and produce pass/fail checks with actionable feedback.

Policies support gradual enforcement—from silent scoring to blocking PRs or deployments—letting you roll out standards at your own pace without disrupting existing workflows.

Learn How Lunar Works →
1
↓ Integrations Gather Data
Collectors extract metadata from code, CI pipelines, tool outputs, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
✓ Guardrails Enforce Standards This Policy
Real-time feedback in PRs and AI workflows

Required Integrations

This policy evaluates data gathered by one or more of the following integration(s). Make sure to enable them in your lunar-config.yml.

Configuration

Configure this policy in your lunar-config.yml.

Inputs

Input Required Default Description
min_python_version Optional 3.9 Minimum Python version ("3.9", "3.12.8") or one per release line ("3.11.14, 3.12.12, 3.13.9")
min_python_version_cicd Optional 3.9 Minimum Python version for CI/CD commands, in the same forms as min_python_version

Documentation

View on GitHub

Python Project Guardrails

Enforce Python-specific project standards including lockfile presence, linter configuration, and Python version requirements.

Overview

This policy validates Python projects against best practices for dependency management and project structure. It ensures projects have proper lockfiles for reproducible builds, a configured linter for code quality, and meet minimum Python version requirements in both the project and CI/CD environments.

Policies

This plugin provides the following policies (use include to select a subset):

Policy Description Failure Meaning
lockfile-exists Validates a lockfile exists Missing dependency pinning
linter-configured Ensures a linter is configured No linter setup
min-python-version Ensures minimum Python version Python version too old
min-python-version-cicd Ensures minimum Python version in CI/CD CI/CD Python version too old

Minimum per release line

min-python-version and min-python-version-cicd take one minimum, or one per release line (major.minor) separated by commas, spaces or newlines. A single minimum is one floor for every line: 3.11.14 passes a vulnerable 3.13.0. With a list, each version is held to its own line's minimum:

with:
  min_python_version_cicd: "3.11.14, 3.12.12, 3.13.9"
Version Result
3.12.12, 3.13.10 Passes: meets its line's minimum
3.13.0, 3.13.0rc1 Fails: below its line's minimum
3.10.19, 3.9.25 Fails: older than every listed line
3.14.0, 3.15.0a1 Passes: newer than every listed line, as with a single minimum

A line between two listed lines has no minimum and fails. min-python-version reads .lang.python.version, which the python collector takes from the Python installed where it runs, not from the project. Use min-python-version-cicd to check the Python your CI runs.

Required Data

This policy reads from the following Component JSON paths:

Path Type Provided By
.lang.python object python collector
.lang.python.poetry_lock_exists boolean python collector
.lang.python.pipfile_lock_exists boolean python collector
.lang.python.linter_configured boolean python collector
.lang.python.version string python collector
.lang.python.cicd.cmds array python collector

Installation

Add to your lunar-config.yml:

policies:
  - uses: github://earthly/lunar-lib/policies/python@v1.0.0
    on: ["domain:your-domain"]  # replace with your own domain or tags
    enforcement: report-pr
    include:
      - lockfile-exists
      - linter-configured
      - min-python-version
      - min-python-version-cicd
    with:
      min_python_version: "3.9"       # Minimum Python version (default: "3.9")
      min_python_version_cicd: "3.9"  # Minimum CI/CD Python version (default: "3.9")

Examples

Passing Example

{
  "lang": {
    "python": {
      "version": "3.12.1",
      "build_systems": ["poetry"],
      "pyproject_exists": true,
      "poetry_lock_exists": true,
      "linter_configured": true,
      "linter": "ruff",
      "type_checker_configured": true,
      "type_checker": "mypy"
    }
  }
}

Failing Example

{
  "lang": {
    "python": {
      "version": "3.8.5",
      "build_systems": ["pip"],
      "requirements_txt_exists": true,
      "poetry_lock_exists": false,
      "pipfile_lock_exists": false,
      "linter_configured": false
    }
  }
}

Failure messages:

  • "No dependency lockfile found. Use one of: poetry.lock, Pipfile.lock, or pin all versions in requirements.txt"
  • "No Python linter configured. Set up one of: Ruff, Flake8, or Pylint"
  • "Python version 3.8.5 is below minimum 3.9. Update to Python 3.9 or higher."

Remediation

lockfile-exists

  1. For Poetry projects: run poetry lock to generate poetry.lock
  2. For Pipenv projects: run pipenv lock to generate Pipfile.lock
  3. For pip projects: pin all versions in requirements.txt (e.g., flask==3.0.0)

linter-configured

  1. Ruff (recommended): Add [tool.ruff] to pyproject.toml or create .ruff.toml
  2. Flake8: Create .flake8 or add [flake8] to setup.cfg
  3. Pylint: Create .pylintrc

min-python-version

  1. Update your project to use a newer Python version
  2. Update python_requires in setup.py or pyproject.toml
  3. Update your .python-version file (if using pyenv)

min-python-version-cicd

  1. Update your CI/CD pipeline to use a newer Python version
  2. For GitHub Actions: update python-version in your workflow
  3. For Docker-based builds: update your base Python image version

Open Source

This policy 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 AGENTS.md, engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 300+ built-in guardrails.

Works with any process
check AI agent rules & prompt files
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Auto-ID My Guardrails
Paste your AGENTS.md or manual process doc and get guardrails in minutes
Book a Demo