Skip to main content

Validate environment variables at startup with typed, clear error messages. Zero dependencies.

Project description

envguard

Validate environment variables at startup with typed, clear error messages. Zero dependencies.

from envguard import EnvGuard

class Env(EnvGuard):
    DATABASE_URL: str
    PORT: int = 8080
    DEBUG: bool = False
    ALLOWED_HOSTS: list = []

env = Env()
print(env.PORT)  # 8080 (int, not string)

If DATABASE_URL is missing, you get this instead of a cryptic KeyError somewhere deep in your app:

EnvGuardError:
Missing required environment variables:
  - DATABASE_URL (str): not set

Install

pip install envguard

Usage

Subclass style (recommended)

from envguard import EnvGuard

class Env(EnvGuard):
    # Required — raises if not set
    DATABASE_URL: str
    API_KEY: str

    # Optional — uses default if not set
    PORT: int = 8080
    DEBUG: bool = False
    LOG_LEVEL: str = "INFO"
    ALLOWED_HOSTS: list = []

env = Env()

One-liner style

from envguard import guard

env = guard(DATABASE_URL=str, PORT=int, DEBUG=bool)
print(env.DATABASE_URL)

Supported types

Type Example env value Python value
str "hello" "hello"
int "8080" 8080
float "3.14" 3.14
bool "true", "1", "yes" True
bool "false", "0", "no" False
list "a,b,c" ["a", "b", "c"]

Error messages

All errors are collected and reported together — you won't fix one missing var only to discover another:

EnvGuardError:
Missing required environment variables:
  - DATABASE_URL (str): not set
  - API_KEY (str): not set

Invalid environment variable values:
  - PORT: expected int, got 'abc'
  - DEBUG: expected bool, got 'maybe'

Why not pydantic-settings?

pydantic-settings is great but pulls in Pydantic as a dependency (~2MB). envguard is a single file with zero dependencies — useful when you want validation without adding weight to your project.

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

envproof-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

envproof-0.1.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for envproof-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aae127b76759c2638c1a7ce38fd0518dda2fb136545a7cc7a9f4d144dcec6271
MD5 557a84207974c4cbe314de6b32567f4d
BLAKE2b-256 12e633b828a5bcd20171fa99392a66422751e44ac1adcb1e12995ce4fc4f0d47

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for envproof-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 186c769e40e8d6b7578f6c14c1283b13254ed2e6a37bbcd75ecca1db2537c42e
MD5 754395f9256fc9423d077e4bb4d2e28a
BLAKE2b-256 e84bcf6f7a09c5760e410f155b2ab00bd252561fbd3757d79974ff179025226d

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