Skip to main content

Configuration from environment variables

Project description

envcfglib

A simple library to load configuration from environment variables.

Installation

This package targets Python 3.12+.

pip install envcfglib

Quick start

Load values from the environment with optional conversion (factory) and defaults.

from envcfglib import Config

config = Config()

# Load an integer value from the environment (raises if missing)
# export APP_PORT=8080
config.load_configuration("APP_PORT", factory=int)

# Retrieve the value (already converted by the factory at load-time)
port = config.get_value("APP_PORT")
print(port)  # e.g., 8080

Factories and defaults

You can control conversion either when loading or when retrieving.

from envcfglib import Config

config = Config()

# Provide a default if the variable is not set
config.load_configuration("DEBUG", default="false")

# Convert when getting the value
is_debug = config.get_value("DEBUG", factory=lambda x: str(x).lower() == "true")
print(is_debug)  # False

# Or convert during load
config.load_configuration("RETRIES", factory=int, default=3)
print(config.get_value("RETRIES"))  # 3

Multiple instances

Config implements a singleton-per-key pattern. Creating instances with different keys allows you to conceptually group configuration, but all loaded values are accessible from any instance.

from envcfglib import Config

app1 = Config("APP1")
app2 = Config("APP2")

# Suppose these are in the environment
# export APP1_VAR=alpha
# export APP2_VAR=beta

app1.load_configuration("VAR")
app2.load_configuration("VAR")

print(app1.get_value("VAR"))  # alpha
print(app2.get_value("VAR"))  # beta

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

envcfglib-0.1.5.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

envcfglib-0.1.5-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file envcfglib-0.1.5.tar.gz.

File metadata

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

File hashes

Hashes for envcfglib-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a38ea7945cd92631a413cb54f26e0eef98456383be3fb63a8fb75936deadaa9a
MD5 4efcef1c37cbdf1153288f085a627673
BLAKE2b-256 cfd386eb1e6a29186c5f1a784ea102d16790a4f63bd0d1affbea2e1aeded0b4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for envcfglib-0.1.5.tar.gz:

Publisher: publish.yml on jotonedev/envcfglib

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

File details

Details for the file envcfglib-0.1.5-py3-none-any.whl.

File metadata

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

File hashes

Hashes for envcfglib-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0764e9ac47019a4d6a77b50b242e29885c69c27b408bb1953b5de5dde981b3a7
MD5 a5e2f9fed46fa01c0f2caf4cb054b887
BLAKE2b-256 f5bc405ce06bfda2f71c7710f12841b5fce85bbbc6f0807f3847b280640018af

See more details on using hashes here.

Provenance

The following attestation bundles were made for envcfglib-0.1.5-py3-none-any.whl:

Publisher: publish.yml on jotonedev/envcfglib

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