Handle configuration for multiple libraries
Project description
Gifnoc
Gifnoc is a unified configuration system for Python modules.
The main objective of gifnoc is to unify configuration files, environment variables and command-line options, across multiple modules. For example, module A and module B can both define their own configuration models through gifnoc, map some environment variables to keys in that configuration, and then you may configure A and B in the same file.
Gifnoc also aims to validate configuration through a typed model based on dataclasses and implemented by the apischema package, a dependency of gifnoc.
Features
- Typed configuration using dataclasses and
apischema - Use a single configuration tree for multiple libraries
- Multiple configuration files can be easily merged
- Easily embed configuration files in each other
Example
main.py
from dataclasses import dataclass
import gifnoc
@dataclass
class User:
name: str
email: str
admin: bool
@dataclass
class Server:
port: int = 8080
host: str = "localhost"
users: list[User]
server_config = gifnoc.define(
field="server",
model=Server,
environ={
APP_PORT="port",
APP_HOST="host",
}
)
if __name__ == "__main__":
with gifnoc.gifnoc(
# Environment variable for the configuration path (defaults to GIFNOC_FILE)
envvar="APP_CONFIG",
# Command-line argument for the configuration path (can give multiple)
config_argument="--config",
# You can easily register command-line arguments to parts of the configuration
options_map={"--port": "server.port"},
):
# The `server_config` object will always refer to the `server` key in the
# current configuration
print("Port:", server_config.port)
config.yaml
server:
port: 1234
host: here
users:
- name: Olivier
email: ob@here
admin: true
# You can write a file path instead of an object
- mysterio.yaml
mysterio.yaml
- name: Mysterio
email: me@myster.io
admin: false
Usage:
python main.py --config config.yaml
APP_CONFIG=config.yaml python main.py
APP_PORT=8903 python main.py --config config.yaml
python main.py --config config.yaml --port 8903
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.
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 gifnoc-0.1.3.tar.gz.
File metadata
- Download URL: gifnoc-0.1.3.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.2 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6602b7b70e7aa00a45d1b44132b0d5b0786d65bc526298859bd8343b284ecea3
|
|
| MD5 |
f256df0e9ef68df37f4f87cb8529b2e4
|
|
| BLAKE2b-256 |
f06a1d5292abe651830d368f3b11f22362c229c7e1caec2eedfdebcb6fdaf825
|
File details
Details for the file gifnoc-0.1.3-py3-none-any.whl.
File metadata
- Download URL: gifnoc-0.1.3-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.2 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
373042e4f00b6c331ae9aae580723cbdbd01acfd326f984a9622127f8ed93ac6
|
|
| MD5 |
8c7fdac19c1de9ae0fc7ef4898c516e2
|
|
| BLAKE2b-256 |
1afbe8dd73a78495ee6093ece240255f1fa609c14a084d6916eafd033b6b0b51
|