envantic
Pydantic-powered, type-safe environment variable loader
Install
pip install envantic
Usage
- Import
EnvModelfrom the envantic package. - Define a model that extends
EnvModel. - Instantiate the model with either
.from_dotenv()or.from_env()factory methods.
Quick start
from pydantic import BaseModel
from envantic import EnvModel
class Settings(EnvModel):
__env_prefix__ = "APP_"
host: str = "127.0.0.1" # APP_HOST
port: int = 8000 # APP_PORT
debug: bool = False # APP_DEBUG
# export APP_PORT=5000 APP_DEBUG=true
s = Settings.from_dotenv() # or Settings.from_env() to ignore .env file
print(s.host) # 127.0.0.1
print(s.port) # 5000
print(s.debug) # True
Custom env key per field
from pydantic import Field
from envantic import EnvModel
class Settings(EnvModel):
__env_prefix__ = "APP_"
host: str = Field("127.0.0.1", json_schema_extra={"env": "SERVER_HOST"}) # APP_SERVER_HOST
port: int = Field(8000, json_schema_extra={"prefix": False}) # PORT
debug: bool = Field(False, json_schema_extra={"env": "TEST", "prefix": False}) # TEST
# export APP_SERVER_HOST=0.0.0.0 PORT=3000 TEST=true
s = Settings.from_dotenv() # or Settings.from_env() to ignore .env file
print(s.host) # 0.0.0.0
print(s.port) # 3000
print(s.debug) # True
License
MIT
Metadata
Release files for envantic 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| envantic-0.1.2.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| envantic-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / envantic-0.1.2.tar.gz
| Download URL | envantic-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d2666551e22a5ce342c9d9039f26699f7f98f4a798a88d105b5d59907708586
|
|
BLAKE2b-256 checksum How to use checksums |
56f0e9e3a36fba2eb255e8f8a1221b34212a154d638e28e5ee684ae99d8124aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Release files / envantic-0.1.2-py3-none-any.whl
| Download URL | envantic-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af2e796bdc95a4786a2dea673c47075a1be9e78fdc0d61f645f9738fb39879da
|
|
BLAKE2b-256 checksum How to use checksums |
ea26fc1162072cfefe01bf3954f3ce483557e7880530cfe89e05d95e3058124f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|