A simple, file-composition-based configuration library.
Project description
Of course. Here is a very simple, clean Markdown README that you can copy and paste directly.
dictconf
A simple, file-composition-based configuration library for Python, inspired by Hydra.
Installation
Install the library using pip:
pip install dictconf
To include optional features like dacite support, install with the extra:
pip install "dictconf[dacite]"
For development, install all tools with:
pip install -e ".[dev]"
Quick Start
This library works by composing configuration from multiple YAML files.
1. Create Your Config Files
Create a directory structure like this:
your_project/
├── conf/
│ ├── config.yaml
│ └── db/
│ ├── mysql.yaml
│ └── sqlite.yaml
└── main.py
conf/config.yaml
This is your main entry point. It defines the default components to use and can override any value.
# Define the default components to load
defaults:
- db: sqlite
# Define or override configuration values
server:
host: 127.0.0.1
port: 8080
url: "http://${server.host}:${server.port}" # Variable interpolation
conf/db/sqlite.yaml (The default database)
db:
driver: sqlite
path: /var/data/app.db
timeout: 5000
conf/db/mysql.yaml (An alternative database)
db:
driver: mysql
host: db.prod.local
user: root
password: "changeme"
2. Load the Configuration in Python
main.py
from config import load_config
import sys
# Load config from the 'conf' directory.
# CLI arguments are automatically used for overrides.
cfg = load_config("conf")
# Access values with dot notation
print(f"Database Driver: {cfg.db.driver}")
print(f"Server URL: {cfg.server.url}")
if cfg.db.driver == "mysql":
print(f"Database User: {cfg.db.user}")
3. Run Your Application
Run with default settings:
$ python main.py
Database Driver: sqlite
Server URL: http://127.0.0.1:8080
Run with command-line overrides:
You can swap components (db=mysql) and override specific values (server.port=9000).
$ python main.py db=mysql server.port=9000 db.user=admin
Database Driver: mysql
Server URL: http://127.0.0.1:9000
Database User: admin
Key Features
- YAML Composition: Build your configuration from small, reusable files.
- CLI Overrides: Easily swap components or change any value from the command line.
- Variable Interpolation: Reference other config values using
${...}syntax. - Dot-Notation Access: Access nested configuration values easily (e.g.,
cfg.db.host).
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 dictconf-0.1.0.tar.gz.
File metadata
- Download URL: dictconf-0.1.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
176b78e3a7d4ff9eb1d53fc3aca085004e7243204363b62e5d4ebe86b0e94c7c
|
|
| MD5 |
eac3fb46bb2f9b9849edf8ec8ca6f5d7
|
|
| BLAKE2b-256 |
6ba45149b05604eeae927e0da9e6273049c9c90f5df6bb85f50c03df1013c8e3
|
File details
Details for the file dictconf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dictconf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ada02b99fcc6cf32dd6e2889920975c0273ec518a514f4305dc4231afd2fbe12
|
|
| MD5 |
3bc95adfd6dc6c36a2e71a23ba01b7f7
|
|
| BLAKE2b-256 |
c08af9631075cd442be0f0c4f9181cdc374bbb1720c9644c35a5ee28a6aed7a6
|