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 serieux package, a dependency of gifnoc.
Features
- Typed configuration using dataclasses and
serieux - 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, field
import gifnoc
@dataclass
class User:
name: str
email: str
admin: bool
@dataclass
class Server:
# Server post
port: int = 8080
# Server hostname
host: str = "localhost"
# List of users
users: list[User] = field(default_factory=list)
# Define a configuration key
server_config = gifnoc.define("server", Server)
if __name__ == "__main__":
# Load configuration from the file in $APP_CONFIG, if it exists
# set_sources overrides any previous configuration
# Each source can be a dictionary, ${envfile:...}, a Path object
gifnoc.set_sources("${envfile:APP_CONFIG}")
# Overlay configuration from environment variables
# add_overlay adds on top of existing configuration
gifnoc.add_overlay({
"server.port": "${env:APP_PORT}",
"server.host": "${env:APP_HOST}",
})
# Overlay configuration with --config, add options with mapping
# --port will automatically use the type and documentation of Server.port
gifnoc.cli(mapping={"server.port": "--port"})
# server_config dynamically updates as sources/overlays are changed
print("Port:", server_config.port)
print("Host:", server_config.host)
# You can apply local changes with a context manager, e.g. for testing:
with gifnoc.overlay({"server.port": 90909}):
print("Port:", server_config.port) # Port: 90909
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.6.3.tar.gz.
File metadata
- Download URL: gifnoc-0.6.3.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c795da2459772911b381929d7b2d366b2b6007e6a367652d8f68f26414e9c98
|
|
| MD5 |
8b848545b4b2d2f17481293d13698a91
|
|
| BLAKE2b-256 |
bc764e249bfc8f530b3fefecefa50871639f75d2bec156a7e2ac9971e9abec1f
|
Provenance
The following attestation bundles were made for gifnoc-0.6.3.tar.gz:
Publisher:
publish.yml on breuleux/gifnoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gifnoc-0.6.3.tar.gz -
Subject digest:
7c795da2459772911b381929d7b2d366b2b6007e6a367652d8f68f26414e9c98 - Sigstore transparency entry: 664206093
- Sigstore integration time:
-
Permalink:
breuleux/gifnoc@023a32825173225aa4d250ec91d0c505f3cc3c85 -
Branch / Tag:
refs/tags/v0.6.3 - Owner: https://github.com/breuleux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@023a32825173225aa4d250ec91d0c505f3cc3c85 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gifnoc-0.6.3-py3-none-any.whl.
File metadata
- Download URL: gifnoc-0.6.3-py3-none-any.whl
- Upload date:
- Size: 9.2 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 |
05b71f27ec2a9f6515aeecf2faa6377f6e5cf86461f2aaff9340726135eef4ff
|
|
| MD5 |
b16b4d3949238d36f80b74f4ebd3b6b7
|
|
| BLAKE2b-256 |
c895797b37187bdc0dbde7656318a98883a7f46a5925c736a827bf3f4916e44c
|
Provenance
The following attestation bundles were made for gifnoc-0.6.3-py3-none-any.whl:
Publisher:
publish.yml on breuleux/gifnoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gifnoc-0.6.3-py3-none-any.whl -
Subject digest:
05b71f27ec2a9f6515aeecf2faa6377f6e5cf86461f2aaff9340726135eef4ff - Sigstore transparency entry: 664206103
- Sigstore integration time:
-
Permalink:
breuleux/gifnoc@023a32825173225aa4d250ec91d0c505f3cc3c85 -
Branch / Tag:
refs/tags/v0.6.3 - Owner: https://github.com/breuleux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@023a32825173225aa4d250ec91d0c505f3cc3c85 -
Trigger Event:
push
-
Statement type: