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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file envcfglib-0.1.4.tar.gz.
File metadata
- Download URL: envcfglib-0.1.4.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c83a66e3847420b12e00a19c9b8648644dc8b9d216071833182e6537dfd2abf4
|
|
| MD5 |
e287cb45ca6738ac892349b823d948cf
|
|
| BLAKE2b-256 |
578217af1108fae129ad8dea3db1ae2e7539ffc4fc63e74fe13186c35be51886
|
Provenance
The following attestation bundles were made for envcfglib-0.1.4.tar.gz:
Publisher:
publish.yml on jotonedev/envcfglib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
envcfglib-0.1.4.tar.gz -
Subject digest:
c83a66e3847420b12e00a19c9b8648644dc8b9d216071833182e6537dfd2abf4 - Sigstore transparency entry: 474643716
- Sigstore integration time:
-
Permalink:
jotonedev/envcfglib@5b00dbbec4334ed2e8e498dde0a1d9f0c06a15f9 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/jotonedev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5b00dbbec4334ed2e8e498dde0a1d9f0c06a15f9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file envcfglib-0.1.4-py3-none-any.whl.
File metadata
- Download URL: envcfglib-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ab8f9cb30c41723a0effaf889a642fdb6d0d5504db7d40f7297890f2ab601e7
|
|
| MD5 |
6fe2f2d2257441b6622974ffa7729848
|
|
| BLAKE2b-256 |
f30687022af3f3edfaf2114722f7a76d5cbbbb17d41ee2f4e9e0083725ec459f
|
Provenance
The following attestation bundles were made for envcfglib-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on jotonedev/envcfglib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
envcfglib-0.1.4-py3-none-any.whl -
Subject digest:
0ab8f9cb30c41723a0effaf889a642fdb6d0d5504db7d40f7297890f2ab601e7 - Sigstore transparency entry: 474643721
- Sigstore integration time:
-
Permalink:
jotonedev/envcfglib@5b00dbbec4334ed2e8e498dde0a1d9f0c06a15f9 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/jotonedev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5b00dbbec4334ed2e8e498dde0a1d9f0c06a15f9 -
Trigger Event:
push
-
Statement type: