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.
ConfigVersions
Allows for easy storing and on-demand loading of configuration versions.
from pathlib import Path
from confz import ConfZFileSource
from flexigurator import ConfigVersions, DirectorySource
class Config(ConfZ): # type: ignore
a: int
b: int
class Configs(ConfigVersions):
CONFIG_CLASS = Config
BASE = dict(a=1, b=2) # Optional base version which is loaded before other versions
test = ConfZFileSource("configs/test.yaml")
folder = DirectorySource(Path("configs/versions"))
with Configs().version("test"):
print(Config()) # Configuration from the ConfZFileSource is now loaded
with Configs().version("folder.version_1"):
print(Config()) # Configuration from "configs/versions/version_1.yaml" is loaded
placeholder
When having nested, optional BaseModel
s 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
Built Distribution
File details
Details for the file flexigurator-0.5.2.tar.gz
.
File metadata
- Download URL: flexigurator-0.5.2.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-1012-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 555f5cb6691227252ba80bcd285750d44de7a58fcec8465309198b1a0090d957 |
|
MD5 | 443a418ba8d83267055ce6511c0a334e |
|
BLAKE2b-256 | 1ec86d4e937baad51f8744c04807080d6871dfdf1d61a0b98aad92c64868ff5a |
File details
Details for the file flexigurator-0.5.2-py3-none-any.whl
.
File metadata
- Download URL: flexigurator-0.5.2-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-1012-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbce6fc5a794282c51bba1ceab855fd8794e8b9b8b4dbc32582f690824d90bd7 |
|
MD5 | be9471d8087dcad76e90f7c38bedc8a8 |
|
BLAKE2b-256 | 55423bade8d29afc1e94b58790dd5323a973186652fb692635226361759ce8c1 |