API Reference¶
All three packages expose the same three-function interface. Only the types and profile options differ.
Functions¶
render_data¶
Parse a t-string template and return Python objects.
Parameters:
| Parameter | Type | Description |
|---|---|---|
template |
Template |
A PEP 750 template string (t"...") |
profile |
JsonProfile \| TomlProfile \| YamlProfile \| str \| None |
Spec version profile (see Profile types). None uses the default for the format |
Returns: Parsed Python data (dict, list, str, int, float, bool, None, or temporal types for TOML).
render_text¶
Parse a t-string template and return valid formatted text.
Parameters: Same as render_data.
Returns: A str containing valid JSON, TOML, or YAML text.
render_result¶
Parse a t-string template and return both data and text.
Parameters: Same as render_data.
Returns: A RenderResult with .data and .text attributes.
Types¶
RenderResult¶
from tstring_core import RenderResult
@dataclass(frozen=True, slots=True)
class RenderResult(Generic[TData]):
text: str
data: TData
| Attribute | Type | Description |
|---|---|---|
text |
str |
Rendered text in the target format |
data |
TData |
Parsed Python data |
Profile types¶
| Type | Values | Package |
|---|---|---|
JsonProfile |
Literal["rfc8259"] |
json_tstring |
TomlProfile |
Literal["1.0", "1.1"] |
toml_tstring |
YamlProfile |
Literal["1.2.2"] |
yaml_tstring |
Value types¶
| Type | Definition | Package |
|---|---|---|
JsonValue |
dict \| list \| str \| int \| float \| bool \| None |
tstring_core |
TomlValue |
dict \| list \| str \| int \| float \| bool \| datetime \| date \| time |
tstring_core |
YamlValue |
dict \| list \| str \| int \| float \| bool \| None |
tstring_core |
Exceptions¶
All exceptions are re-exported from tstring-bindings:
| Exception | When |
|---|---|
TemplateParseError |
Template syntax is invalid for the target format |
TemplateSemanticError |
Valid syntax but invalid semantics (e.g., non-string JSON key) |
UnrepresentableValueError |
Python value can't be represented in the target format |
Errors carry Diagnostic objects with source spans and expression labels.
Unknown profile strings raise ValueError before the Rust backend is invoked.