toml_tools
Class info¶
Re-exported classes¶
| Class | Module | Description |
|---|---|---|
| ParseErrorInfo | configz.parse_errors | Structured information about a parse error. |
| TomlDumpError | configz.toml_tools.base | Unified exception for all TOML serialization errors. |
| TomlLoadError | configz.toml_tools.base | Unified exception for all TOML parsing errors. |
| TomlRsProvider | configz.toml_tools.toml_rs_provider.provider | TOML-RS implementation of the TOML provider interface. |
🛈 DocStrings¶
Package for TOML-related tools with validation support.
Provides a unified interface for TOML serialization/deserialization with automatic selection of the best available backend and type validation.
ParseErrorInfo
dataclass
¶
Structured information about a parse error.
Source code in src/configz/parse_errors.py
format
¶
Format error with source context for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_lines
|
int
|
Number of lines to show before/after the error line. |
2
|
use_color
|
bool
|
Whether to include ANSI color codes. |
True
|
Source code in src/configz/parse_errors.py
TomlDumpError
¶
TomlLoadError
¶
Bases: Exception
Unified exception for all TOML parsing errors.
Source code in src/configz/toml_tools/base.py
source_path
property
¶
Path to the source file that caused the error.
format
¶
Format error with source context for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_lines
|
int
|
Number of lines to show before/after the error line. |
2
|
use_color
|
bool
|
Whether to include ANSI color codes. |
True
|
Source code in src/configz/toml_tools/base.py
dump_toml
¶
Serialize data to a TOML string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data to serialize |
required |
pretty
|
bool
|
Whether to format the output with pretty formatting |
False
|
backend
|
BackendType
|
TOML backend to use for serialization |
'auto'
|
Returns:
| Type | Description |
|---|---|
str
|
The serialized TOML string |
Raises:
| Type | Description |
|---|---|
TomlDumpError
|
If serialization fails |
Source code in src/configz/toml_tools/__init__.py
get_toml_provider
¶
get_toml_provider(backend: BackendType = 'auto') -> type[TomlProviderBase]
Get the specified TOML provider or the best available one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendType
|
The TOML backend to use. If "auto", uses the best available. |
'auto'
|
Returns:
| Type | Description |
|---|---|
type[TomlProviderBase]
|
A TOML provider implementation |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the requested backend is not available |
Source code in src/configz/toml_tools/__init__.py
load_toml
¶
load_toml(
data: str | bytes | TextIOWrapper | Path,
return_type: type[T] | None = None,
backend: BackendType = "auto",
) -> T
Load TOML data with optional type validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes | TextIOWrapper | Path
|
The TOML data to parse (string, bytes, file-like object, or Path) |
required |
return_type
|
type[T] | None
|
Optional type to validate the data against |
None
|
backend
|
BackendType
|
TOML backend to use for parsing |
'auto'
|
Returns:
| Type | Description |
|---|---|
T
|
The parsed and validated data |
Raises:
| Type | Description |
|---|---|
TomlLoadError
|
If parsing fails |
TypeError
|
If validation against return_type fails |