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
    DISABLE_AUTOTUNE: bool = 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.0.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.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: enfig-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4cc5826627ad311463417794c960c6fdd9b9a4a7774b559c6810281f16ff349e
MD5 27c11f2d16e7cf7e5ee9177717f290d8
BLAKE2b-256 c6ec5fef53e7b0a076dc6522b8bf6b830a1a92acb1e86f896ab70b5c09e74f07

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: enfig-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac3a6209f630c04182dbc94cd8cc391f9198d99d29026f1c362f17503056bb15
MD5 ce1f72a8df8086cb6439963633b6c6d7
BLAKE2b-256 9feae39904568e1274d32bcab2a8a00ee0cd7229bc74117b39b581de7dee90a0

See more details on using hashes here.

Provenance

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