Skip to main content

Validate your .env against a typed schema (required, int, url, enum, …) before the app boots — catch bad config up front. Zero dependencies.

Project description

envward

Validate your .env against a typed schema before the app boots. A missing DATABASE_URL, a PORT=abc, a NODE_ENV=prodd typo — these don't fail loudly, they fail deep in startup with a cryptic stack trace, or worse, silently in production. envward checks the whole environment against a small schema up front and tells you exactly what's wrong, in one place. Zero dependencies, no network.

pip install envward

$ envward

.env  checked against env.schema.json

   API_KEY   missing  required string
   NODE_ENV  "prodd" is not one of: development, production, test
   PORT      70000 is above max 65535

3 problem(s), 3 key(s) valid

Exits non-zero when anything is invalid, so it drops straight into a boot script or CI step. Unlike a drift checker (which finds missing keys), envward validates the values: types, ranges, formats, and allowed sets.

This is the Python build. A behavior-equivalent Node build is on npm: npx envward (https://github.com/jjdoor/envward).

Get started in one command

# Infer a starter schema from your existing .env, then edit it:
envward --init > env.schema.json

--init guesses a type for each key from its current value (8080int, https://…url, truebool, …) and marks them all required. Tighten it from there.

The schema

A plain JSON file (env.schema.json by default), one rule per key:

{
  "PORT":         { "type": "int", "required": true, "min": 1, "max": 65535 },
  "DATABASE_URL": { "type": "url", "required": true },
  "NODE_ENV":     { "type": "enum", "values": ["development", "production", "test"] },
  "DEBUG":        { "type": "bool" },
  "API_KEY":      { "type": "string", "required": true, "minLength": 16 },
  "ADMIN_EMAIL":  { "type": "email" }
}
Type Accepts
string anything; constraints: minLength, maxLength, pattern (regex)
int integer; constraints: min, max
number integer or float; constraints: min, max
bool true / false / 1 / 0 (case-insensitive)
url scheme://…
email name@host.tld
enum one of values (required array)

required defaults to false. An empty value (KEY=) counts as missing.

Usage

envward                              # validate .env against env.schema.json
envward --env .env.prod --schema prod.schema.json
envward --strict                     # also flag keys in .env not declared in the schema
envward --json                       # machine-readable
envward --init > env.schema.json     # scaffold a schema from the current .env

Options

Flag Effect
--env <file> .env file to check (default .env)
--schema <file> JSON schema file (default env.schema.json)
--strict Keys present in .env but absent from the schema are problems
--init Print a schema scaffold inferred from the .env
--json Emit { valid, problems, summary } as JSON
--quiet Print only the one-line summary
-v, --version · -h, --help

Use it as a gate

# refuse to boot with a broken .env, or fail CI:
envward && python -m myapp
envward --env .env.ci --strict

Exit codes

Code Meaning
0 every key valid
1 one or more validation problems
2 error (missing/invalid schema, unreadable file)

A validator should fail when validation fails, so envward exits 1 on problems by default — no flag needed.

Notes

  • Same tool, two builds. A behavior-equivalent Node build is on npm (npx envward); use whichever your stack already has.
  • .env parsing strips a single pair of surrounding quotes and an optional export prefix. Inline comments after a value are not stripped — quote values that contain #.
  • pattern is a regex matched in ASCII mode (\d = [0-9]) and as an unanchored search — wrap it in ^…$ to match the whole value. For identical results across both builds keep to a portable subset (avoid inline (?i) flags, lookbehind, and named groups, which differ between the JS and Python engines; a malformed pattern is reported as a schema error, exit 2).
  • Numeric min/max are compared at 64-bit float precision — ample for config; keep bounds within ±2^53.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

envward-0.1.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

envward-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file envward-0.1.0.tar.gz.

File metadata

  • Download URL: envward-0.1.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for envward-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f91d4ef9ded1cc55857ea598695147a9e7cd48aba4ad45dffbe1bb4d52cc87c9
MD5 521f741625ac527fa964e904b94310ad
BLAKE2b-256 db73edb703aedb5a7fd62a1420377a32a062e030d11282f716347a8573864b03

See more details on using hashes here.

File details

Details for the file envward-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: envward-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for envward-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cfd23216eb81bfa12c7f9348aab5af28a303dc9e1a172f9fa346f75f6911921
MD5 196d7a790ec6cb4b4bfb12157b1a6fbd
BLAKE2b-256 78d10d98f61b6cb2202ce4a96402a2bb8546ac83c5993029d9c7105df438cb61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page