Skip to main content

align-dotenv

Keep your .env files aligned with their templates — without losing local values.

The template controls structure and known variables. Your local file controls existing values and whether each variable is active or commented out. Unknown local variables are kept by default. Unsupported local syntax causes a safe failure, not data loss.

Install

Python 3.10–3.14 is supported.

uv tool install align-dotenv
# or
pipx install align-dotenv
# or
python -m pip install align-dotenv

For development from a checkout:

python -m pip install .
# or
uv tool install .

Use

align-dotenv .env --template .env.example
align-dotenv .env --template .env.example --check
align-dotenv .env --template .env.example --unknown keep    # default
align-dotenv .env --template .env.example --unknown remove  # explicitly drop unknown keys
align-dotenv .env --template .env.example --unknown error   # fail, listing key names only

For example, with .env.example:

# Required setting
REQUIRED=template

# OPTIONAL=template

and a local .env:

OPTIONAL='local choice'
REQUIRED=local

alignment produces:

# Required setting
REQUIRED=local

OPTIONAL='local choice'

--check never writes: exit 0 means aligned, 1 means a change is needed. Invalid inputs, unsupported syntax, and --unknown error with unknown keys exit 2.

Syntax and safety

Understand it, preserve it, or refuse to modify it. The supported syntax is single-line KEY=value, export KEY=value, # KEY=value, and # export KEY=value, with keys matching [A-Za-z_][A-Za-z0-9_]*. Values are kept as raw text; this is not a full shell or dotenv parser. Unsupported meaningful local content (such as shell directives, line continuations, or unclosed quoted values) stops the operation without modifying the file. Errors show line numbers, not offending lines or values. Ordinary local comments and blank lines may be omitted because the template defines the layout. The final assignment wins if a key appears repeatedly.

The existing target must be a regular file, not a symlink or the template itself. Known lines use the template's line endings and final newline; unknown lines kept by default retain their original representation, so mixed endings are possible. Changes replace the target atomically in its directory, preserve its mode bits, and skip the write if already aligned.

Develop

PYTHONPATH=src python -m unittest discover -s tests -v
python -m compileall -q src tests

See CONTRIBUTING.md for contributor guidance.

Metadata

Release files for align-dotenv 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 align-dotenv 0.1.0
File Size Uploaded
align_dotenv-0.1.0.tar.gz 8.3 kB Details

Built distribution (wheel)

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

Total release size: 16.8 kB

Release files / align_dotenv-0.1.0.tar.gz

Download URL align_dotenv-0.1.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9a46d3a75e5e368bd24636c71d99e39ac3ef291e37b112bd3a81b53796c9ae91
BLAKE2b-256 checksum
How to use checksums
0231555fe47f5d8d2523ae3a84962e99aa32b678cf7da5f49335ee4f12fe387c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 29, 2026.

Transparency log

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

Download URL align_dotenv-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d91b3d1487fd3fedab2f8f840d9d6fe14be98a44dc978ff00326523fdbde34eb
BLAKE2b-256 checksum
How to use checksums
ed5cf53ce70d7470ed1f9f9522d6c3307a6540534473d76579b5c5ad83b2f05c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

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