Skip to main content

dotenv-contract

A small, dependency-free Python CLI for checking environment variable declarations against a template. Catch configuration drift before starting an app or running a CI job, without printing variable values.

Installation

Requires Python 3.11 or newer. Once a release is available on PyPI:

python -m pip install dotenv-contract

To install from a source checkout, preferably in a virtual environment:

python -m pip install .

Quick start

Given .env.example:

APP_PORT=
DATABASE_URL=
DEBUG=

And a local .env containing:

APP_PORT=8080
LOCAL_OVERRIDE=1

Run:

dotenv-contract .env.example .env

Output (names only):

{"missing": ["DATABASE_URL", "DEBUG"], "unexpected": ["LOCAL_OVERRIDE"]}

Strict matching is the default. To permit a missing optional template key and local overrides:

dotenv-contract .env.example .env --optional DEBUG --allow-extra

Repeat --optional KEY for each optional key. Missing required keys still fail validation.

When a deployment or CI job injects environment variables into the process:

dotenv-contract .env.example --process-env --optional DEBUG

This checks required template keys and ignores unrelated process variables. Name matching follows the operating system's environment rules.

Exit codes

Code Meaning
0 Contract satisfied
1 Missing or unexpected declarations
2 Invalid input or unreadable file

A blank value counts as a declaration. Both files must be UTF-8, with one assignment per line. Blank lines, comments, an optional export prefix, and single-line quoted values are supported. Duplicate keys and malformed quoted values are rejected. Only whitespace or a # comment may follow a closing quote.

Scope and limits

This tool checks names, not value types or validity. It does not expand, execute, or print values. It is not a secret scanner or a full dotenv parser; multiline quoted values are intentionally rejected. Reports may include variable names and file paths, so treat those as potentially sensitive when sharing logs.

Development

python -m pip install -e .
python -m unittest -v

The module can also be run directly from the checkout using python -m dotenv_contract.

Contributions and reproducible bug reports are welcome. Use synthetic values in examples, tests, and issue reports. Never commit real .env files.

License and provenance

MIT licensed. See LICENSE. Development has included AI assistance; see the commit history for attribution.

Metadata

Release files for dotenv-contract 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dotenv-contract 0.1.0
File Size Uploaded Provenance Actions
dotenv_contract-0.1.0.tar.gz 4.8 kB With provenance Details for dotenv_contract-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dotenv-contract 0.1.0
File Interpreter ABI Platform Actions
dotenv_contract-0.1.0-py3-none-any.whl Python 3 none any Details for dotenv_contract-0.1.0-py3-none-any.whl

Total release size: 9.9 kB

Release files / dotenv_contract-0.1.0.tar.gz

Download URL dotenv_contract-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0c0fa2894899c72c489fee84c8f5e2ed7d259f1ea12982a2fd1f36e4b3e847e6
BLAKE2b-256 checksum
How to use checksums
25513761f55265379b49164c7fb14a9880b262e6e2221532b16bc31bdd48804e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / dotenv_contract-0.1.0-py3-none-any.whl

Download URL dotenv_contract-0.1.0-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df74539fe775b8decc148554040c11ae7b59e6b3053b4f65cfc9a423a39a3c27
BLAKE2b-256 checksum
How to use checksums
035d72fb738e27caf27bbe9c86160f3280a6b9311b7a8fc6f9d6abecd3f53bf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for dotenv-contract 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dotenv_contract-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page