Metadata-Version: 2.4
Name: dotenv-contract
Version: 0.1.0
Summary: Check environment variable declarations without printing their values
License-Expression: MIT
Project-URL: Repository, https://github.com/SammyRyuga/dotenv-contract
Project-URL: Issues, https://github.com/SammyRyuga/dotenv-contract/issues
Keywords: dotenv,environment,configuration,validation,cli
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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:

```sh
python -m pip install dotenv-contract
```

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

```sh
python -m pip install .
```

## Quick start

Given `.env.example`:

```dotenv
APP_PORT=
DATABASE_URL=
DEBUG=
```

And a local `.env` containing:

```dotenv
APP_PORT=8080
LOCAL_OVERRIDE=1
```

Run:

```sh
dotenv-contract .env.example .env
```

Output (names only):

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

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

```sh
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:

```sh
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

```sh
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](https://github.com/SammyRyuga/dotenv-contract/blob/main/LICENSE). Development has included AI assistance; see the commit history for attribution.
