🐼 serde-dataclass 🐻
TOML and JSON serialization for Python dataclasses is provided through a small, explicit API.
Comment-preserving TOML output, renamed keys, nested dataclasses, and typed round-trips are supported.
Documentation
Project documentation is provided through MkDocs.
pip install -e .[docs]
mkdocs serve
Detailed usage is documented in docs/.
Installation
pip install serde-dataclass
For development and example dependencies:
pip install -e .[dev]
Quick Start
from dataclasses import dataclass, field
from enum import Enum
from typing import Literal
from serde_dataclass import TomlDataclass
class Mode(str, Enum):
DEV = "dev"
PROD = "prod"
@dataclass
class Database:
host: str = field(metadata={"description": "Database host"})
port: int = field(default=5432, metadata={"description": "Database port"})
@dataclass
class AppConfig(TomlDataclass):
"""Application configuration"""
app_name: str = field(
default="demo",
metadata={"description": "Application name", "toml": "app-name"},
)
log_level: Literal["debug", "info", "warning", "error"] = field(
default="info",
metadata={"description": "Logging verbosity", "toml": "log-level"},
)
mode: Mode = field(default=Mode.DEV, metadata={"description": "Runtime mode"})
database: Database = field(
default_factory=lambda: Database(host="localhost"),
metadata={"description": "Database settings"},
)
cfg = AppConfig()
text = cfg.to_toml()
loaded = AppConfig.from_toml(text)
assert loaded == cfg
print(text)
Example output:
# Application configuration
app-name = "demo" # Application name
log-level = "info" # Logging verbosity
mode = "dev" # Runtime mode
# Database settings
[database]
host = "localhost" # Database host
port = 5432 # Database port
Summary
TomlDataclassandJsonDataclassare provided as base mixins.- Root comments, field comments, renamed keys, and nested dataclasses are supported.
Enum,Literal,Optional, lists, tuples, sets, anddict[str, T]are supported.- Custom loading is configured through
dacite.Config. - Custom serialization is integrated through
json.JSONEncoderandtomlkitencoders.
Notes
- TOML comments are emitted only for TOML serialization.
- Dictionary keys are required to be strings.
- Fields with
Nonevalues are omitted from TOML output.
Development
pytest -q
License
MIT
Metadata
Release files for serde-dataclass 0.0.4
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 |
|---|---|---|---|---|
| serde_dataclass-0.0.4.tar.gz | 13.1 kB | Without provenance | Details for serde_dataclass-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| serde_dataclass-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for serde_dataclass-0.0.4-py3-none-any.whl |
Total release size: 21.8 kB
Release files / serde_dataclass-0.0.4.tar.gz
| Download URL | serde_dataclass-0.0.4.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4ecaafb1b5a75505544364ae931fe5685dcbdc730ccd6c793d1f111c8983f38
|
|
BLAKE2b-256 checksum How to use checksums |
97b8eb2389bbe02f72e06cd50fccf833b88c0edb8f547ac2f8a23544bd8c5097
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / serde_dataclass-0.0.4-py3-none-any.whl
| Download URL | serde_dataclass-0.0.4-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3138f31162c83c9df3ae7110c650db8b60e49c214f8d3e01251e9fc8f9c29f90
|
|
BLAKE2b-256 checksum How to use checksums |
1cbb19a0d2d7b4473088561d743026400a98fd3d3e3787a984188b760510011f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for serde-dataclass 0.0.4
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.