TOMLSerializer 📝
A powerful and flexible Python library for serializing Python objects to TOML format with robust type handling support.
✨ Features
- 🔄 Serializes Python dataclasses to TOML format and back
- 🏷️ Preserves type information during serialization
- 📦 Supports complex data types including:
- 🔢 Basic types (int, float, str, bool)
- 📚 Collections (list, dict, set, tuple)
- 📂 Path objects
- 🎯 Callable functions
- ❓ Optional fields
- 🔀 Union types
- 🪢 Nested data structures
- 🕳️ Empty collections
- 👨👦 Inheritance hierarchies
🚀 Installation
pip install tomlserializer # Package name may vary
🏃 Quick Start
from dataclasses import dataclass
from pathlib import Path
from tomlserializer import TOMLSerializer
@dataclass
class Config:
name: str
values: list[int]
output_path: Path
enabled: bool
# Create an instance
config = Config(
name="example",
values=[1, 2, 3],
output_path=Path("/tmp/output"),
enabled=True
)
# Save to TOML
TOMLSerializer.save(config, "config.toml")
# Load from TOML
loaded_data = TOMLSerializer.load_typed_dict("config.toml")
🔧 Advanced Usage
🛠️ Custom Type Registration
You can register custom type handlers for serialization and deserialization:
def custom_type_to_toml(value):
return str(value)
def custom_type_from_toml(value):
return CustomType(value)
TOMLSerializer.register_type(CustomType, custom_type_to_toml, custom_type_from_toml)
🌟 Supporting Complex Types
The library handles various complex scenarios:
@dataclass
class ComplexConfig:
# Optional fields
optional_value: Optional[int] = None
# Union types
flexible_field: Union[str, int]
# Nested collections
nested_dict: Dict[str, Dict[str, int]]
# Function references
callback: Callable
👨👦 Inheritance Support
@dataclass
class BaseConfig:
base_field: str
@dataclass
class DerivedConfig(BaseConfig):
derived_field: int
# Both base and derived fields are preserved during serialization
📋 Type Support
The library includes built-in support for:
- 🔢 Basic types (int, float, str, bool)
- 📚 Collection types (list, dict, set, tuple)
- 📂 Pathlib Path objects
- 🎯 Python functions (via module path resolution)
- ❌ None values
- ❓ Optional fields
- 🔀 Union types
⚠️ Error Handling
The library includes robust error handling for:
- 🚫 Invalid file paths
- 🔄 Type conversion errors
- ❗ Missing required fields
- 🏗️ Invalid TOML syntax
🤝 Contributing
Contributions are welcome! Please feel free to submit pull requests.
Metadata
Release files for tomlserializer 0.3
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 | |
|---|---|---|---|---|
| tomlserializer-0.3.tar.gz | 64.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tomlserializer-0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 69.9 kB
Release files / tomlserializer-0.3.tar.gz
| Download URL | tomlserializer-0.3.tar.gz |
|---|---|
| Size | 64.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af24cbcd9935a9711f94ac505390ca0912eb9b1c9364d61e9e4cac1003d8b05b
|
|
BLAKE2b-256 checksum How to use checksums |
b65c4a789baec9fac0eb514fbf46839f5c0064848a31ec956aae2fb04cd47acf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / tomlserializer-0.3-py3-none-any.whl
| Download URL | tomlserializer-0.3-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02b24d6f61e725e009b1741a8c40a4a1ee3df9c729bc0b14fbedfb456c219270
|
|
BLAKE2b-256 checksum How to use checksums |
15df89d6685330ed71d3566a14c27ac8aa7dd025f8695efc91e68377c6eb889b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for tomlserializer 0.3
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.