Skip to main content

EnvGuardian

A lightweight python environment variables validator

EnvGuardian is a lightweight Python library designed to ensure the presence of all required environment variables when your project is executed, thereby minimizing the occurrence of runtime errors. This functionality proves particularly valuable in scenarios where environment variables are specified in a .env or .env.example file, ensuring that all team members possess up-to-date versions of the mandatory variables in .env files.

By leveraging EnvGuardian, your development team can rest assured that the necessary environment variables are appropriately set before the project is run, safeguarding against common errors resulting from missing or incorrectly configured environment variables. This proactive approach not only enhances the stability and reliability of your applications but also promotes seamless collaboration among team members by streamlining the management of environment configurations.

Installation

pip install envguardian

Usage

In your project root create an Env.py file and define a variable called env_schema like so

# Env.py
from envguardian import Env

env_schema = {
    'DB_NAME': Env.string(),
    'ENVIRONMENT': Env.enum(['development', 'stage']),
    'PORT': Env.integer(),
    'DEBUG': Env.boolean(),
    'SOME_VAR': Env.float()
}

Somewhere else in your project, ideally, the entry point of your project, validate like so

from envguardian import Env

Env.validate()

If the validation fails, expect something like this, .validate() will throw a ValueError Exception.

Exception: {'DB_NAME': '`None` is not a string', 'ENVIRONMENT': "`None` is not one of: ['development', 'stage']", 'PORT': '`None` is not an integer', 'SOME_VAR': '`None` is not a float'}

You can also use EnvGuardian to get environment variables with their correct type, provided you have defined them in env_schema and the variable is present in environment variables.

from envguardian import Env

print(type(Env.get('DEBUG')))

Output : <class 'bool'>

Metadata

Release files for envguardian 1.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 envguardian 1.1.0
File Size Uploaded Provenance Actions
envguardian-1.1.0.tar.gz 3.1 kB Without provenance Details for envguardian-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for envguardian 1.1.0
File Interpreter ABI Platform Actions
envguardian-1.1.0-py3-none-any.whl Python 3 none any Details for envguardian-1.1.0-py3-none-any.whl

Total release size: 7.3 kB

Release files / envguardian-1.1.0.tar.gz

Download URL envguardian-1.1.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7c9c59736c7c49e4906a345c528b59f5e4064aa6c62e6d1ae9128249124279e9
BLAKE2b-256 checksum
How to use checksums
6c8bb83f87e60bad47a8d805ddb0c87ee2dbfa4741bd1e184d7195bea1e509d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/20.6.0

Release files / envguardian-1.1.0-py3-none-any.whl

Download URL envguardian-1.1.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73d556b177e8f8436c3e00a85e95e3e7b35f45cf49ee7225862448468a08b258
BLAKE2b-256 checksum
How to use checksums
095cdc244d6c8c6f74f7b7f48f5788ba3584984d28dba8867ac36507b4ddcb60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/20.6.0

Security for envguardian 1.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

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