An elegant application configurator for the more civilized age
Project description
envenom
envenom
is an elegant application configurator for the more civilized age.
envenom
is written with simplicity and type safety in mind. It allows
you to express your application configuration declaratively in a dataclass-like
format while providing your application with type information about each entry,
its nullability and default values.
envenom
is designed with modern usecases in mind, allowing for pulling configuration
from environment variables or files for more sophisticated deployments on platforms
like Kubernetes.
Quickstart guide
main.py
:
from envenom import config, optional, required, with_default
from envenom.parsers import as_boolean
@config(namespace="postgres")
class DatabaseCfg:
host: str = required()
port: int = with_default(int, default=5432)
database: str = required()
username: str | None = optional()
password: str | None = optional()
server_side_cursors: bool = with_default(as_boolean, default=True)
if __name__ == "__main__":
db_cfg = DatabaseCfg()
print(f"host: {repr(db_cfg.host)} {type(db_cfg.host)}")
print(f"port: {repr(db_cfg.port)} {type(db_cfg.port)}")
print(f"database: {repr(db_cfg.database)} {type(db_cfg.database)}")
print(f"username: {repr(db_cfg.username)} {type(db_cfg.username)}")
print(f"password: {repr(db_cfg.password)} {type(db_cfg.password)}")
print(
f"server_side_cursors: {repr(db_cfg.server_side_cursors)} "
f"{type(db_cfg.server_side_cursors)}"
)
Run python main.py
:
Traceback (most recent call last):
...
raise MissingConfiguration(self.env_name)
envenom.errors.MissingConfiguration: 'POSTGRES__HOST'
Run:
POSTGRES__HOST="postgres" \
POSTGRES__DATABASE="database-name" \
POSTGRES__USERNAME="user" \
POSTGRES__SERVER_SIDE_CURSORS="f" \
python main.py
host: 'postgres' <class 'str'>
port: 5432 <class 'int'>
database: 'database-name' <class 'str'>
username: 'user' <class 'str'>
password: None <class 'NoneType'>
server_side_cursors: False <class 'bool'>
Getting started
See the wiki for more info.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.