Article · python / dotenv / configuration
EnvContract: it works locally, so why will it not start on the server?
Compare missing, extra, duplicate and empty dotenv keys in two local files without sharing values, and understand what the result can prove.
Your application starts on your computer but stops during startup on the server. The code appears identical, so the latest change becomes the first suspect. Before investigating a larger problem, there is a smaller question to ask: does the target file contain the environment variable names the application expects? A name may be missing, misspelled or present with an empty value.
Answering that question should not require pasting an entire configuration into a conversation. The file may contain credentials and connection details. EnvContract is a small Python CLI that compares keys in two local dotenv files. It reports missing, extra, repeated and empty keys without printing their values, keeping this first investigation focused on the configuration contract.
Define the expected keys first
The first input is a reference file describing the expected names. Our example contains APP_MODE, DATABASE_URL, API_TOKEN and LOG_LEVEL. Its values are synthetic demonstration text. The reference does not need production credentials: its purpose here is to make the expected set of names explicit.
You remain responsible for keeping that reference accurate. If a new application version requires another variable but nobody updates the reference, the checker cannot discover the requirement. Reviewing the reference alongside code that introduces a configuration key helps keep the expectation visible. It also gives people comparing different environments a common starting point.
Four different findings in one example
The bundled reference.env contains the four expected keys. In target.env, API_TOKEN is absent, DATABASE_URL is empty, LOG_LEVEL appears twice and LEGACY_FLAG is an additional name. This is a synthetic teaching example, not configuration collected from a real server.
The report labels these cases missing, extra, duplicate and empty. Duplicate and empty findings include line numbers. A later assignment does not erase an earlier assignment from the report, so you can see that repetition exists without the tool guessing which value the application will ultimately use.
An extra name is not automatically harmful or obsolete. It may belong to another component, or the reference may need updating. Treat findings as review prompts, not deletion instructions. Check the application's requirements, then make any necessary changes through your usual editor and change process. EnvContract does not modify files or invent replacement values.
Run the comparison locally
Extract the package and run the following command from its directory. Both input paths are explicit; the tool does not search directories for dotenv files. It uses only the Python standard library, so no additional Python package installation is needed. Supply paths, never credential values, as arguments.
python3 envcontract.py examples/reference.env examples/target.envThis example exits with 1. Add --json to receive a machine-readable report. The separate target-fixed.env fixture contains the same four expected names with nonempty synthetic values and exits with 0. The checker has not repaired anything: you have selected a different, already prepared input file.
Read the three exit codes carefully
0 means no findings within the supported comparison. 1 means at least one finding. 2 means an unreadable or unsupported input, invalid command usage or a supported output failure. Malformed input never produces a partially successful comparison. In JSON, findings becomes null, with a fixed error code and input role reported separately.
Empty values are checked in both files. A reference placeholder such as API_TOKEN= is a finding too; use harmless, nonempty examples for a clean baseline. Names are case-sensitive. Values are not compared for equality, and neither endpoint availability nor credential validity is checked.
The supported format is deliberately narrow
EnvContract accepts single-line KEY=VALUE assignments in UTF-8, an optional initial BOM, LF or CRLF, comments, and single or double quotes closed on the same physical line. Each file is limited to 1 MiB. Multiline values, export, backticks and backslash escapes are rejected. The included guide documents the exact subset.
Expressions such as ${NAME} remain literal text. Nothing is expanded or executed, so the existence of a value that another loader might resolve is not established. Your application's loader may use different rules; the dotenv documentation describes features outside this subset. Do not rewrite production configuration merely to satisfy this checker.
Keep the report's limits visible
Reports omit values, raw input lines and file paths. However, key names can reveal internal details, so inspect reports before sharing them. Selected values enter local process memory for parsing and emptiness checks. The tool does not protect against a compromised computer, external tracing or disclosure through another channel.
Existing alternatives include dotenv-linter, which checks and compares dotenv files, and dotenv-safe, which verifies expected names in the Node.js environment after loading. EnvContract claims neither novelty nor superiority. Its scope is two explicit files, standard-library Python and reports without values.
The EnvContract package and GitHub repository include code, synthetic fixtures and the detailed guide. It was tested on Linux with Python 3.14.8; Windows and macOS were not tested. A clean report does not guarantee startup or security. Use this as an initial check, then continue with the application's own configuration validation and operational checks.