Schema-based environment variable validation with type coercion and helpful error messages
Project description
philiprehberger-env-validator
Schema-based environment variable validation with type coercion and helpful error messages.
Installation
pip install philiprehberger-env-validator
Usage
Basic Validation
from philiprehberger_env_validator import Schema, validate
schema = (
Schema()
.string("DATABASE_URL", description="PostgreSQL connection string")
.integer("PORT", default=3000)
.boolean("DEBUG", default=False)
.string("NODE_ENV", choices=["development", "staging", "production"])
)
config = validate(schema)
print(config["PORT"]) # 3000 (int, not string)
Field Types
schema = (
Schema()
.string("API_KEY")
.integer("MAX_CONNECTIONS")
.float_field("RATE_LIMIT")
.boolean("VERBOSE")
.url("WEBHOOK_URL")
.email("ADMIN_EMAIL")
)
Custom Validation
schema = Schema().string(
"API_KEY",
pattern=r"^sk-[a-zA-Z0-9]{32}$",
validator=lambda v: len(v) > 10,
)
Optional Fields
schema = (
Schema()
.string("REQUIRED_VAR")
.string("OPTIONAL_VAR", required=False, default="fallback")
)
Custom Source
config = validate(schema, source={"PORT": "8080", "DEBUG": "true"})
Error Handling
from philiprehberger_env_validator import ValidationError
try:
config = validate(schema)
except ValidationError as e:
for error in e.errors:
print(error)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_env_validator-0.1.4.tar.gz.
File metadata
- Download URL: philiprehberger_env_validator-0.1.4.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8921e0ea582dc6cacbb2dd0c6823f2755e15cf5d6878e0a7f5081f39e7cc4ffd
|
|
| MD5 |
0ada7ca4ccf3d3b287f15e6e4bff4470
|
|
| BLAKE2b-256 |
c3d6884468f462b81ace313e2c2a92b2ef6fe9e57dfe19b060c7ece77caa04ca
|
File details
Details for the file philiprehberger_env_validator-0.1.4-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_env_validator-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0db689b05359ae709d90d6e3f6e75f84c0b267d3a0877bdeaac145b7217ca1de
|
|
| MD5 |
7e2c9b41949c1ff35c3a692981fd40bd
|
|
| BLAKE2b-256 |
6990742d7e0c9982fc9571f437e84eafd89344a2013c350177e5322a6fdd139a
|