confdantic
Confdantic is a Python library that enhances Pydantic's capabilities for working with JSON, YAML, and TOML formats by preserving field descriptions as comments when serializing to YAML or TOML.
Installation
Using pip
pip install confdantic
Using uv
uv add confdantic
From source
pip install git+https://github.com/zigai/confdantic.git
# or
uv add git+https://github.com/zigai/confdantic.git
Example
from typing import Literal
from pydantic import Field
from confdantic import Confdantic
class DatabaseConfig(Confdantic):
host: str = Field(
"localhost",
description="The hostname or IP address of the database server",
)
port: int = Field(
5432,
description="The port number on which the database server is listening.",
)
username: str
password: str
class ApplicationConfig(Confdantic):
debug: bool = Field(False, description="Enable debug mode")
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR"] = Field(
"INFO", description="Logging level"
)
database: DatabaseConfig
allowed_hosts: list[str] = Field(
default_factory=list,
description="A list of host/domain names that this application can serve.",
)
config = ApplicationConfig(
database=DatabaseConfig(username="admin", password="secret"),
allowed_hosts=["example.com"],
)
config.save("config.yaml", comments=True)
config.save("config.toml", comments=True)
config.yaml
debug: false # Enable debug mode
log_level: INFO # Logging level | choices: DEBUG, INFO, WARNING, ERROR
database:
host: localhost # The hostname or IP address of the database server
port: 5432 # The port number on which the database server is listening.
username: admin
password: secret
allowed_hosts: # A list of host/domain names that this application can serve.
- example.com
config.toml
debug = false # Enable debug mode
log_level = "INFO" # Logging level | choices: DEBUG, INFO, WARNING, ERROR
allowed_hosts = ["example.com"] # A list of host/domain names that this application can serve.
[database]
host = "localhost" # The hostname or IP address of the database server
port = 5432 # The port number on which the database server is listening.
username = "admin"
password = "secret"
License
Metadata
Release files for confdantic 0.1.5
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 | Actions |
|---|---|---|---|---|
| confdantic-0.1.5.tar.gz | 80.6 kB | Without provenance | Details for confdantic-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| confdantic-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for confdantic-0.1.5-py3-none-any.whl |
Total release size: 88.4 kB
Release files / confdantic-0.1.5.tar.gz
| Download URL | confdantic-0.1.5.tar.gz |
|---|---|
| Size | 80.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02491e053ecf61afd3295d114ddae77df3414de0d8939c7f3fd5ea2a11053e8b
|
|
BLAKE2b-256 checksum How to use checksums |
2e45d6ce17fdb0694aa7a62fad7d98e8107821eb15792cddf076cb8b3c5a194c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / confdantic-0.1.5-py3-none-any.whl
| Download URL | confdantic-0.1.5-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b77378abaaaef7315aa5ad301f979fd42e7bb8fc539e12f1fd0019c53523856a
|
|
BLAKE2b-256 checksum How to use checksums |
ac88fe74019dad15bfe3bafcf0b4cc5651d246a337c93761b2ad43bbfc518aff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for confdantic 0.1.5
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.