tukuy.types
- class tukuy.types.DateTransformOptions(format: str = '%Y-%m-%d', timezone: str | None = None)
Bases:
TransformOptionsOptions for date transformations.
- format: str = '%Y-%m-%d'
- timezone: str | None = None
- class tukuy.types.ExtractorOptions(selector: str | Dict[str, Any], attribute: str = 'text', fallback: str | List[str] | None = None)
Bases:
TransformOptionsOptions for data extraction.
- attribute: str = 'text'
- fallback: str | List[str] | None = None
- selector: str | Dict[str, Any]
- class tukuy.types.ExtractorProtocol(*args, **kwargs)
Bases:
ProtocolProtocol defining the interface for data extractors.
- extract_data(data: Any, pattern: Dict[str, Any]) Dict[str, Any]
Extract data according to the given pattern.
- Parameters:
data – The data to extract from (HTML, JSON, etc.)
pattern – The pattern describing what to extract
- Returns:
Dictionary of extracted data
- extract_property(data: Any, property_def: Dict[str, Any]) Any
Extract a single property from data.
- Parameters:
data – The data to extract from
property_def – The property definition
- Returns:
The extracted property value
- class tukuy.types.NumberTransformOptions(decimals: int = 2, strip_non_numeric: bool = True)
Bases:
TransformOptionsOptions for number transformations.
- decimals: int = 2
- strip_non_numeric: bool = True
- class tukuy.types.PatternOptions(pattern: str, template: str | None = None, flags: int = 0)
Bases:
TransformOptionsOptions for pattern-based transformations.
- flags: int = 0
- pattern: str
- template: str | None = None
- class tukuy.types.PluginProtocol(*args, **kwargs)
Bases:
ProtocolProtocol defining the interface for plugins.
- cleanup() None
Clean up the plugin.
- get_transformer(name: str, params: Dict[str, Any]) TransformerProtocol | None
Get a transformer by name with the given parameters.
- Parameters:
name – The transformer name
params – Parameters for the transformer
- Returns:
The transformer instance or None if not found
- initialize() None
Initialize the plugin.
- property name: str
Get the plugin name.
- property transformers: Dict[str, Any]
Get the transformers provided by this plugin.
- class tukuy.types.TextTransformOptions(strip: bool = True, case_sensitive: bool = True)
Bases:
TransformOptionsOptions for text transformations.
- case_sensitive: bool = True
- strip: bool = True
- class tukuy.types.TransformOptions
Bases:
object- Description:
Base class for transformer options.
Version: v1 Status: Production Last Updated: 2024-03-24
- class tukuy.types.TransformResult(value: T | None = None, error: Exception | None = None)
Bases:
Generic[T]- Description:
Container for transformation results with error handling.
Version: v1 Status: Production Last Updated: 2024-03-24
- Type Parameters:
T: The type of the transformed value
- __init__(value
Optional[T] = None, error: Optional[Exception] = None): Initialize a new TransformResult with an optional value or error.
- failed()
bool Property indicating if the transformation failed.
- __str__() str
String representation of the result.
- property failed: bool
no-index:
- class tukuy.types.TransformerProtocol(*args, **kwargs)
Bases:
Protocol[T,U]- Description:
Protocol defining the interface for transformers.
Version: v1 Status: Production Last Updated: 2024-03-24
- Type Parameters:
T: The input type that this transformer accepts U: The output type that this transformer produces
- name() str
Get the transformer name.
- transform(value
T, context: Optional[TransformContext] = None) -> TransformResult[U]: Transform the input value according to the transformer’s rules.
- validate(value
T) -> bool: Validate if the input value is acceptable for this transformer.
- get_validation_errors(value
T) -> List[str]: Get list of validation errors for the input value.
- get_validation_errors(value: T) List[str]
Get list of validation errors for the input value.
- Parameters:
value – The input value to validate
- Returns:
List of validation error messages, empty if valid
- property name: str
no-index:
- transform(value: T, context: Dict[str, Any] | None = None) TransformResult[U]
Transform the input value according to the transformer’s rules.
- Parameters:
value – The input value to transform
context – Optional context for the transformation
- Returns:
TransformResult containing either the transformed value or an error
- validate(value: T) bool
Validate the input value.
- Parameters:
value – The input value to validate
- Returns:
True if the value is valid for this transformer, False otherwise
- class tukuy.types.ValidatorProtocol(*args, **kwargs)
Bases:
Protocol[T]Protocol defining the interface for validators.
- get_validation_errors(value: T) List[str]
Get list of validation errors for the input value.
- Parameters:
value – The input value to validate
- Returns:
List of validation error messages, empty if valid
- validate(value: T) bool
Validate the input value.
- Parameters:
value – The input value to validate
- Returns:
True if the value is valid, False otherwise
- validate_with_context(value: T, context: Dict[str, Any]) bool
Validate the input value with additional context.
- Parameters:
value – The input value to validate
context – Additional context for validation
- Returns:
True if the value is valid, False otherwise