Parsing & Validation
Content parsing decorators and strategies. Validation types (ValidationResult, MetadataValidationFailureMode) are documented with the Registry. See also the Validation guide.
hother.streamblocks.core.parsing
Parsing decorators for content models.
ParseStrategy
Bases: StrEnum
Strategy for handling parsing errors.
Source code in src/hother/streamblocks/core/parsing.py
parse_as_json
parse_as_json(
*,
strategy: ParseStrategy = PERMISSIVE,
handle_non_dict: bool = True,
) -> Callable[[type[T]], type[T]]
Decorator to parse content from JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
ParseStrategy
|
How to handle parsing errors (STRICT or PERMISSIVE) |
PERMISSIVE
|
handle_non_dict
|
bool
|
If True, wrap non-dict values in {"value": ...} |
True
|
Example
@parse_as_json() ... class MyContent(BaseContent): ... status: int ... data: dict[str, Any]
Source code in src/hother/streamblocks/core/parsing.py
parse_as_yaml
parse_as_yaml(
*,
strategy: ParseStrategy = PERMISSIVE,
handle_non_dict: bool = True,
) -> Callable[[type[T]], type[T]]
Decorator to parse content from YAML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
ParseStrategy
|
How to handle parsing errors (STRICT or PERMISSIVE) |
PERMISSIVE
|
handle_non_dict
|
bool
|
If True, wrap non-dict values in {"value": ...} |
True
|
Example
@parse_as_yaml() ... class MyContent(BaseContent): ... key: str ... value: int