Modern python configuration file manager using Pydantic and python type hints.
Pydaconf is a simple yet powerful open-source Python library for loading application configurations. It leverages modern Python features, including type hints and the awesome data validation Pydantic models for clarity and maintainability. Pydaconf provides seamless configuration loading from YAML, TOML, and JSON files while supporting dynamic secret injection via a pluggable architecture.
Install using pip install pydaconf[all]
For more installation options see the Install section in the documentation.
- Create config file in toml, yaml or json
domain: pydaconf.com
openai_token: ENV:///OPENAI_TOKEN
database:
host: eu-central-db01.{{ domain }}
username: svc_db01
password: SEALED:///gAAAAABnpRqHdho_dFB7iMs_Ufv5nu59LwqQfE3YCjaDTyg-YrYsEpK8bfvdKsdrj6kCxrAjezCGAdVM0FhzwyfYFIgqnquw8w==
- Create Pydantic Model and load the configuration
from pydaconf import PydaConf
from pydantic import BaseModel
class DbConfig(BaseModel):
host: str
username: str
password: str
class Config(BaseModel):
domain: str
openai_token: str
database: DbConfig
provider = PydaConf[Config]()
provider.from_file("config.yaml")
print(provider.config.database.password)
See documentation for more details.
Templates Example |
---|
contact_email: user@{{ domain }} |
db_server: {{ backend.server }} |
first_username: {{ users[0].username }} |
Plugin | Description |
---|---|
ENV | Inject secret from environment variable |
SEALED | Inject a sealed secret. Secrets can be encrypted with a symmetric key and stored in a file. The provider expects the key in the PYDACONF_SEALED_KEY environment variable. |
FILE_CONTENT | Inject content from a file. This is useful in scenarios where the secret is mounted on the file system, such as in k8s containers. |
Plugin | Description | Install | Info |
---|---|---|---|
K8S_SECRET | Pydaconf plugin for Kubernetes Secrets | pip install pydaconf-plugins-k8s | Docs |
VAULT | Pydaconf plugin for Vault and OpenBao | pip install pydaconf-plugins-vault | Docs |