Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gifnoc-0.1.3.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

gifnoc-0.1.3-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

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

Hashes for gifnoc-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6602b7b70e7aa00a45d1b44132b0d5b0786d65bc526298859bd8343b284ecea3
MD5 f256df0e9ef68df37f4f87cb8529b2e4
BLAKE2b-256 f06a1d5292abe651830d368f3b11f22362c229c7e1caec2eedfdebcb6fdaf825

See more details on using hashes here.

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

Hashes for gifnoc-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 373042e4f00b6c331ae9aae580723cbdbd01acfd326f984a9622127f8ed93ac6
MD5 8c7fdac19c1de9ae0fc7ef4898c516e2
BLAKE2b-256 1afbe8dd73a78495ee6093ece240255f1fa609c14a084d6916eafd033b6b0b51

See more details on using hashes here.

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