Skip to main content

Lean, zero dependency environment parsing library.

Project description

Coverage Status Ruff License: MIT

Enfig - Environment Config

Lean, zero dependency environment parsing library based on annotations, inspired by pydantic.

Environmental variables are being parsed and casted automatically to the corresponding type when class variables are being accessed.

Examples:

import os
import enfig

# Just for demonstration, of course env vars should already be set outside the application.
os.environ["COLOR"] = "RED"
os.environ["TEMPERATURE"] = "50"
os.environ["DISABLE_AUTOTUNE"] = "y"


class Config(enfig.BaseConfig):
    COLOR: str
    TEMPERATURE: int
    DISABLE_AUTOTUNE: bool


assert Config.COLOR == "RED"
assert Config.TEMPERATURE == 50
assert Config.DISABLE_AUTOTUNE is True

The Config class casts the values automatically. Moreover, you can test if all mandatory variables have been set and have the correct type.

import os
import enfig

os.environ["COLOR"] = "RED"
os.environ["DISABLE_AUTOTUNE"] = "I can't sing but I pretend to be a singer"
os.environ["WEIGHT"] = "haha invalid"


class Config(enfig.BaseConfig):
    COLOR: str
    TEMPERATURE: int
    WEIGHT: float
    AMOUNT: int | None = None
    DISABLE_AUTOTUNE: bool | None = None


try:
    Config.validate()
except enfig.ValidationError as error:
    for attribute_error in error.errors:
        print(attribute_error)

Output:

DISABLE_AUTOTUNE: Invalid value, required type: `bool`
TEMPERATURE: Not set, required type: `int`
WEIGHT: Invalid value, required type: `float`

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

enfig-1.0.2.tar.gz (37.5 kB view details)

Uploaded Source

Built Distribution

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

enfig-1.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file enfig-1.0.2.tar.gz.

File metadata

  • Download URL: enfig-1.0.2.tar.gz
  • Upload date:
  • Size: 37.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for enfig-1.0.2.tar.gz
Algorithm Hash digest
SHA256 113592810f5aad1d1cc9189922c900a8ba0f3461b00bcc101c93463b23456d02
MD5 a5efa1efb338da5925d0e8f194de0060
BLAKE2b-256 3f2c046a9a16b824b789715caab317b8bb92d7ed60994f4a15b50aea2b733d7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for enfig-1.0.2.tar.gz:

Publisher: CD.yml on datek/enfig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enfig-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: enfig-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for enfig-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8b14d5ecc7876f3e72efb811437e1874a37533f1c5f77b96d61d95050a1685f9
MD5 6032e92333c3a98d85aa356fad8adc6c
BLAKE2b-256 1047bf8e562f895485bc26465b630765b189e695f35bee437a7d4758ecf46924

See more details on using hashes here.

Provenance

The following attestation bundles were made for enfig-1.0.2-py3-none-any.whl:

Publisher: CD.yml on datek/enfig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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