Skip to main content

Pydantic-powered, type-safe environment variable loader

Project description

envantic

Pydantic-powered, type-safe environment variable loader

Install

pip install envantic

Usage

  1. Import EnvModel from the envantic package.
  2. Define a model that extends EnvModel.
  3. 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

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

envantic-0.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

envantic-0.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file envantic-0.1.2.tar.gz.

File metadata

  • Download URL: envantic-0.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for envantic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3d2666551e22a5ce342c9d9039f26699f7f98f4a798a88d105b5d59907708586
MD5 01a78a549fae9d7561062abe07eada90
BLAKE2b-256 56f0e9e3a36fba2eb255e8f8a1221b34212a154d638e28e5ee684ae99d8124aa

See more details on using hashes here.

File details

Details for the file envantic-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: envantic-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for envantic-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 af2e796bdc95a4786a2dea673c47075a1be9e78fdc0d61f645f9738fb39879da
MD5 2dbf0afb7bd85193f7b4a995a8cdaa5d
BLAKE2b-256 ea26fc1162072cfefe01bf3954f3ce483557e7880530cfe89e05d95e3058124f

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