Minimalist environment variable validation for Python, inspired by envalid
About
Venvalid is a minimalist and developer-friendly environment variable validator for Python — inspired by the simplicity and clarity of envalid from the Node.js world.
It lets you define a schema for your environment variables and ensures they are present, well-formed, and ready to use — before your app even starts.
Why Venvalid?
Venvalid was designed with Python developers in mind, offering a modern, clean, and extensible API to handle .env configurations. It stands out from other libraries by:
- ✅ Using Python native types (
str,bool,int,list,Path,Decimal,datetime, etc.) - ✅ Supporting default values, enum constraints, and custom validation
- ✅ Allowing custom dotenv loading with override support
- ✅ Raising clear and styled error messages that prevent app boot on misconfig
- ✅ Having zero external dependencies — just Python
Installation
pip install venvalid
or
uv add venvalid
Quick Example
from venvalid import str_, int_, bool_, venvalid
from venvalid.dotenv import load_env_file
# Define schema
config = venvalid({
"DEBUG": bool_(default=False),
"PORT": int_(default=8000),
"SECRET_KEY": str_(),
"ENVIRONMENT": str_(allowed=["dev", "prod", "test"], default="dev"),
})
print(config["DEBUG"]) # -> False
print(config["PORT"]) # -> 8000
print(config["ENVIRONMENT"]) # -> "dev"
Usage
You can use venvalid to validate configuration before mounting the app:
from fastapi import FastAPI
from venvalid import str_, int_, bool_, venvalid
from venvalid.dotenv import load_env_file
config = venvalid({
"DEBUG": bool_(default=False),
"PORT": int_(default=8000),
"ENVIRONMENT": str_(allowed=["dev", "prod", "test"], default="dev"),
})
app = FastAPI()
@app.get("/")
def read_root():
return {
"env": config["ENVIRONMENT"],
"debug": config["DEBUG"],
"port": config["PORT"],
}
Supported Types
You can use both built-in types and helper functions:
str,int,bool,listpath_()→ forpathlib.Pathdecimal_()→ forDecimaldatetime_()→ fordatetimejson_()→ for JSON/dict strings
All helpers accept:
default=...allowed=[...]validate=callable
Advanced Options
"ENVIRONMENT": str_(allowed=["dev", "prod"], default="dev"),
"FEATURE_FLAG": bool_(default=False),
"API_KEY": str_(validate=lambda v: v.startswith("sk-")),
If any variable is missing or invalid, venvalid will stop execution and print a meaningful error message.
.env Loading
If you want to load variables from a .env file (without relying on python-dotenv), use:
from venvalid.dotenv import load_env_file
load_env_file(".env") # default
load_env_file(".env.prod", override=True) # optional override
Metadata
Release files for venvalid 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| venvalid-0.3.0.tar.gz | 11.0 kB | Without provenance | Details for venvalid-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| venvalid-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for venvalid-0.3.0-py3-none-any.whl |
Total release size: 18.9 kB
Release files / venvalid-0.3.0.tar.gz
| Download URL | venvalid-0.3.0.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d32c16026910b4b37626e49bc07210423de5dc4cf966c91824aa15f732caf6b5
|
|
BLAKE2b-256 checksum How to use checksums |
0ba75c398792f16ec3022e1f4b14620319befda0d2878f218a91a5c30ac98b64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / venvalid-0.3.0-py3-none-any.whl
| Download URL | venvalid-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92846333a4082d899086cdfafd88c5ec72d9ad4ffae670ecd6885e122b2c7e47
|
|
BLAKE2b-256 checksum How to use checksums |
0129d8b146c6f0b58bc680aabf218b247aa04ec13984c760a44225d7c89db00f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for venvalid 0.3.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.