Skip to main content

A minimal and developer-friendly environment variable validator for Python, inspired by envalid.

Project description

Venvalid logo

PyPI Downloads

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, list
  • path_() → for pathlib.Path
  • decimal_() → for Decimal
  • datetime_() → for datetime
  • json_() → 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

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

venvalid-0.3.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

venvalid-0.3.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file venvalid-0.3.0.tar.gz.

File metadata

  • Download URL: venvalid-0.3.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for venvalid-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d32c16026910b4b37626e49bc07210423de5dc4cf966c91824aa15f732caf6b5
MD5 39be3b8470aa41392aa4ccd6a0b23dec
BLAKE2b-256 0ba75c398792f16ec3022e1f4b14620319befda0d2878f218a91a5c30ac98b64

See more details on using hashes here.

File details

Details for the file venvalid-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: venvalid-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for venvalid-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92846333a4082d899086cdfafd88c5ec72d9ad4ffae670ecd6885e122b2c7e47
MD5 f67855ecd96d911b7dcc8017e1266d31
BLAKE2b-256 0129d8b146c6f0b58bc680aabf218b247aa04ec13984c760a44225d7c89db00f

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