Application configuration inspired by Microsoft.Extensions.Configuration (.NET).
Project description
confeasy
Application configuration inspired by Microsoft.Extensions.Configuration (.NET).
The main idea is to have the following workflow:
- Define one or more configuration sources from where the actual configuration is created (or downloaded).
- Build the configuration. This basically means put everything into a big flat dictionary where lastly defined sources could override values from previous ones if they match on the configuration key.
- Use resulting configuration: a. Directly, picking up individual values by their key. b. Bind all or portion of the configuration to a strongly typed class instance (typically a dataclass) and use this instance instead of the configuration itself. The benefit is better intellisense in IDEs and more decoupling.
Getting started
Install the package.
poetry add confeasy
# or similar command for your package manager of choice
In python, usually around application start:
# DbOptions class is an illustrative example of strongly typed configuration.
class DbOptions:
def __init__(self):
self.connnection_string: str = ""
self.max_connections: int = 100
from confeasy import Builder
from confeasy.jsonfile import JsonFile
from confeasy.tomlfile import TomlFile
from confeasy.envars import EnvironmentVariables
from confeasy.cmdline import CommandLine
# Order of the configuration sources matters; later sources can overwrite values from earlier ones.
builder = (Builder()
.add_source(JsonFile()
.required("settings.json")
.optional("setting.local.json"))
.add_source(TomlFile()
.optional("other_settings.toml"))
.add_source(EnvironmentVariables("MYAPP_"))
.add_source(CommandLine()))
config = builder.build()
# Bind configuration to a class instance and pass the instance to other objects.
options = config.bind(DbOptions(), prefix="db")
# OR pick up individual values:
db_conn_str = config.get_value("db.connection_string")
Out-of-the-box configuration sources
- JSON files
- TOML files
- INI files
- command line arguments
- environment variables
Additional configuration sources
- confeasy.azure_appc - using Azure AppConfiguration service; PyPI | source
Development
For developer related information, check Developer Guide.
Note:
- YAML files will not be supported unless a parsing module is available in the standard library.
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 confeasy-1.0.0.tar.gz.
File metadata
- Download URL: confeasy-1.0.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01b4f0c3d8beca6ef9b282276feccd848eb3cf881488b195d7a898910d32d8cf
|
|
| MD5 |
84405df0460f3f3d0bbfd8d485f84af2
|
|
| BLAKE2b-256 |
1d84e7d9afb6c6a5cf555551dad5553fc30140ea33e95a4602970cad38de790c
|
File details
Details for the file confeasy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: confeasy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f53faa543cc2be18f9aa67d006a994b28c2b87079928d8da4726d453b76d1bd3
|
|
| MD5 |
c673793dab891a780532d8870b140b81
|
|
| BLAKE2b-256 |
f4fbaf4137f9f1a781e9c35c88f70f7e1947524ba41a3324daebb518ae148a09
|