confiddle
Hierarchical configuration for Python that's inspired by .NET and powered by Pydantic.
What is it?
It's a hierarchical configuration loader that should be familiar to folks in dotnet-land, but adapted for Python and leveraging Pydantic to build and validate the configuration data. Confiddle fiddles with the configuration so you don't have to!
Configurations can be loaded dynamically from a variety of sources:
- JSON configuration files (ex:
config.json) - Environment-specific JSON configuration files (ex:
config.dev.jsonorconfig.prod.json) - Environment variables
- Argparse
- Click
- Dictionaries
Those configurations are then merged together (shallowly, with later configurations overriding earlier ones), and used to build up the provided Pydantic model.
This is all customizable, too! With some easy tweaks, you can configure which configuration sources are loaded, what order they're loaded in, and the environment that your program is targeting. Confiddle will even bootstrap itself, so you can configure Confiddle's behavior the same way you'd load any other set of configurations.
Installation
pip install confiddle (preferably inside your project's venv 🙂)
Example
A web service that layers three configuration sources - base JSON defaults, a production-specific JSON override, and a runtime environment variable.
// config.json - shared across all environments
{
"app_name": "my-web-service",
"workers": 4,
"admin_username": "admin"
}
// config.dev.json - local development overrides
{
"host": "localhost",
"port": 8080,
"debug": true
}
// config.prod.json - production overrides
{
"host": "1.2.3.4",
"port": 80,
"debug": false
}
## Injected by the platform's secrets manager
export MYAPP:ADMIN_PASSWORD="hunter2"
## app_config.py
from pydantic import BaseModel, Field
class AppConfig(BaseModel):
app_name: str
workers: int
host: str
port: int
debug: bool
admin_username: str
admin_password: str = Field(default="", exclude=True)
## main.py
from confiddle import (
Confiddle,
ConfiddleConfigModel,
ProviderConfigModel,
ConfigEnvironment,
JsonProviderConfig,
EnvVarProviderConfig,
)
from app_config import AppConfig
confiddle = Confiddle(
ConfiddleConfigModel(
app=ProviderConfigModel(
## `directory_path="."` searches for config JSON files at the current working directory
json_file_provider=JsonProviderConfig(directory_path="."),
## `prefix="MYAPP"` filters out any environment variable that doesn't have the "MYAPP" prefix
env_var_provider=EnvVarProviderConfig(prefix="MYAPP"),
),
## This tells it to only load production configurations, like config.prod.json above.
## Note that it'll still load the base configurations regardless, like config.json above.
environment=ConfigEnvironment.PROD,
)
)
config = confiddle.load_config(AppConfig)
## State of `config` after loading:
## config.app_name -> "my-web-service" (from config.json)
## config.workers -> 4 (from config.json)
## config.admin_username -> "admin" (from config.json)
## config.host -> "1.2.3.4" (from config.prod.json)
## config.port -> 80 (from config.prod.json)
## config.debug -> False (from config.prod.json)
## config.admin_password -> "hunter2" (from MYAPP:ADMIN_PASSWORD env var)
And that's it! Confiddle uses the configuration files and Pydantic models that you're already using, but formalizes the ingestion process, making all the magic happen in just a few lines of code.
Documentation
- API Reference - API docs, hierarchy behavior, environments, and bootstrapping
- Examples - common usage patterns and recipes
Metadata
Release files for confiddle 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| confiddle-0.2.1.tar.gz | 37.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| confiddle-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.0 kB
Release files / confiddle-0.2.1.tar.gz
| Download URL | confiddle-0.2.1.tar.gz |
|---|---|
| Size | 37.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
459fd363fd6dffe63104d946055df250309e73bb8e911ce0d51da611c0b55ca6
|
|
BLAKE2b-256 checksum How to use checksums |
0d737f02d562e8dc5f42ed7bde01af12229e4d07eb55001bd6e60cba65397d1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / confiddle-0.2.1-py3-none-any.whl
| Download URL | confiddle-0.2.1-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
021f4630745bfe9282fef0acd83af139c1d4b968ec1adc0952ca29b15a33548e
|
|
BLAKE2b-256 checksum How to use checksums |
b0faaf57dc6ac10e24e12716df31c35a3877f85680c0015b3844b3d96fe74024
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for confiddle 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.