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.1.tar.gz (23.6 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.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for enfig-1.0.1.tar.gz
Algorithm Hash digest
SHA256 da01909bcbeadeb9fa470833939a9c8e569c044cfa21e3b53a3d31414af47685
MD5 04cdab24dd5ad506e37849c1fafa4357
BLAKE2b-256 caf5b7eed5d13a3c644b5776898479abd19c7a3662838e0e003c97f3a4c555a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for enfig-1.0.1.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.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for enfig-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b20c0b1ae7836e10374de8b29ca54f24add0f0a9ff4d7a6dd8db44fc8b4f86cd
MD5 9a6d877dbddca4208b71df5a6b1ff1b5
BLAKE2b-256 740e3bb88d301917fea221859de9496e91a9a8b41b92170b7c8a74b6901f7383

See more details on using hashes here.

Provenance

The following attestation bundles were made for enfig-1.0.1-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