Skip to main content

Python Configuration solution.

Project description

Flexigurator

Flexigurator is a collection of useful tools when working with configuration. Flexigurator builds on top of ConfZ and Pydantic while adding some extra functionality to make your life easier when testing and deploying.

Examples

config_patch

When using ConfZ to define a configuration singleton using a .yaml file,

# config.yaml
some_string: default
some_int: 42
from confz import ConfZ, ConfZFileSource

class Config(ConfZ):
    some_string: str
    some_int: int

    CONFIG_SOURCES = ConfZFileSource("config.yaml")

configuration variables can be easily hotswapped using patch_config:

from flexigurator import patch_config


data = dict(some_int=9001)


with patch_config(Config, data):
    Config().some_int     # 9001

    
Config().some_int     # 42

Importantly, the new data does not need to be complete.

placeholder

When having nested, optional BaseModels in your Config,

class Config(ConfZ):
    ui: UIConfig | None
    server: ServerConfig | None    

it would be nice if trying to load configuration automatically throws an exception if it is not configured. The placeholder method provides such functionality, and it can be used as follows:

from flexigurator import placeholder, patch_config


class Config(ConfZ):
    ui: UIConfig = placeholder(UIConfig)
    server: ServerConfig = placeholder(UIConfig)
    

Config().server.ip_address  # NotConfiguredException!

This removes the need for None-checking as exception handling is done behind the scenes.

ConfigForm

ConfigForm allows for the easy creation of forms for ConfZ or BaseModel classes. Forms are generated using Json Editor and are served using FastAPI. Having instantiated ConfigForm,

# form.py
from flexigurator import ConfigForm


app = ConfigForm(Config, "save/path", "templates/path")

The server can be started using (for instance) Uvicorn:

uvicorn form:app

Installation

Flexigurator is available on PyPi and can be installed using pip:

pip install flexigurator

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

flexigurator-0.3.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

flexigurator-0.3.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file flexigurator-0.3.2.tar.gz.

File metadata

  • Download URL: flexigurator-0.3.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1038-azure

File hashes

Hashes for flexigurator-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d4bf0d7db3d12165367552e2e412eef63f88b0bdf224113c44ceb2344a72afff
MD5 78b11dc18f547d0305af739246f3e9ff
BLAKE2b-256 58a5a27e8fa239b86f9f0dc687e42fc99ad12e0d5877ed34991763b5092065d2

See more details on using hashes here.

File details

Details for the file flexigurator-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: flexigurator-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1038-azure

File hashes

Hashes for flexigurator-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4aecd2922106bef22c11008ffe46353d47f05170a7068e3286566889dcc2b35d
MD5 c222d7a8047ea682516890774241e42c
BLAKE2b-256 7000dcd808e17e525575a59c03eca88b48227a5550d3c6883ec8727106e43c68

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page