A flexible data transformation library with a plugin system
Project description
๐ Tukuy
A flexible data transformation library with a plugin system for Python.
๐ Overview
Tukuy (meaning "all" or "everything" in Quechua) is a powerful and extensible data transformation library that makes it easy to manipulate, validate, and extract data from various formats. With its plugin architecture, Tukuy provides a unified interface for working with text, HTML, JSON, dates, numbers, and more.
โจ Features
- ๐งฉ Plugin System: Easily extend functionality with custom plugins
- ๐ Chainable Transformers: Compose multiple transformations in sequence
- ๐งช Type-safe Transformations: With built-in validation
- ๐ Rich Set of Built-in Transformers:
- ๐ Text manipulation (case conversion, trimming, regex, etc.)
- ๐ HTML processing and extraction
- ๐ Date parsing and calculations
- ๐ข Numerical operations
- โ Data validation
- ๐ JSON parsing and extraction
- ๐ Pattern-based Data Extraction: Extract structured data from HTML and JSON
- ๐ก๏ธ Error Handling: Comprehensive error handling with detailed messages
๐ฆ Installation
pip install tukuy
๐ ๏ธ Basic Usage
from tukuy import ToolsTransformer
# Create transformer
tools = ToolsTransformer()
# Basic text transformation
text = " Hello World! "
result = tools.transform(text, [
"strip",
"lowercase",
{"function": "truncate", "length": 5}
])
print(result) # "hello..."
# HTML transformation
html = "<div>Hello <b>World</b>!</div>"
result = tools.transform(html, [
"strip_html_tags",
"lowercase"
])
print(result) # "hello world!"
# Date transformation
date_str = "2023-01-01"
age = tools.transform(date_str, [
{"function": "age_calc"}
])
print(age) # 1
# Validation
email = "test@example.com"
valid = tools.transform(email, ["email_validator"])
print(valid) # "test@example.com" or None if invalid
๐งฉ Plugin System
Tukuy uses a plugin system to organize transformers into logical groups and make it easy to extend functionality.
๐ Built-in Plugins
- ๐ text: Basic text transformations (strip, lowercase, regex, etc.)
- ๐ html: HTML manipulation and extraction
- ๐ date: Date parsing and calculations
- โ validation: Data validation and formatting
- ๐ข numerical: Number manipulation and calculations
- ๐ json: JSON parsing and extraction
๐ Creating Custom Plugins
You can create custom plugins by extending the TransformerPlugin class:
from tukuy.plugins import TransformerPlugin
from tukuy.base import ChainableTransformer
class ReverseTransformer(ChainableTransformer[str, str]):
def validate(self, value: str) -> bool:
return isinstance(value, str)
def _transform(self, value: str, context=None) -> str:
return value[::-1]
class MyPlugin(TransformerPlugin):
def __init__(self):
super().__init__("my_plugin")
@property
def transformers(self):
return {
'reverse': lambda _: ReverseTransformer('reverse')
}
# Usage
tools = ToolsTransformer()
tools.register_plugin(MyPlugin())
result = tools.transform("hello", ["reverse"]) # "olleh"
See the example plugin for a more detailed example.
๐ Plugin Lifecycle
Plugins can implement initialize() and cleanup() methods for setup and teardown:
class MyPlugin(TransformerPlugin):
def initialize(self) -> None:
super().initialize()
# Load resources, connect to databases, etc.
def cleanup(self) -> None:
super().cleanup()
# Close connections, free resources, etc.
๐ Pattern-based Extraction
Tukuy provides powerful pattern-based extraction capabilities for both HTML and JSON data.
๐ HTML Extraction
pattern = {
"properties": [
{
"name": "title",
"selector": "h1",
"transform": ["strip", "lowercase"]
},
{
"name": "links",
"selector": "a",
"attribute": "href",
"type": "array"
}
]
}
data = tools.extract_html_with_pattern(html, pattern)
๐ JSON Extraction
pattern = {
"properties": [
{
"name": "user",
"selector": "data.user",
"properties": [
{
"name": "name",
"selector": "fullName",
"transform": ["strip"]
}
]
}
]
}
data = tools.extract_json_with_pattern(json_str, pattern)
๐ Use Cases
Tukuy is designed to handle a wide range of data transformation scenarios:
- ๐ Web Scraping: Extract structured data from HTML pages
- ๐ Data Cleaning: Normalize and validate data from various sources
- ๐ Format Conversion: Transform data between different formats
- ๐ Text Processing: Apply complex text transformations
- ๐ Data Extraction: Extract specific information from complex structures
- โ Validation: Ensure data meets specific criteria
โก Performance Tips
- ๐ Chain Transformations: Use chained transformations to avoid intermediate objects
- ๐งฉ Use Built-in Transformers: Built-in transformers are optimized for performance
- ๐ Be Specific with Selectors: More specific selectors are faster to process
- ๐ ๏ธ Custom Transformers: For performance-critical operations, create custom transformers
- ๐ฆ Batch Processing: Process data in batches for better performance
๐ก๏ธ Error Handling
Tukuy provides comprehensive error handling with detailed error messages:
from tukuy.exceptions import ValidationError, TransformationError, ParseError
try:
result = tools.transform(data, transformations)
except ValidationError as e:
print(f"Validation failed: {e}")
except ParseError as e:
print(f"Parsing failed: {e}")
except TransformationError as e:
print(f"Transformation failed: {e}")
๐ค Contributing
Contributions are welcome! Here's how you can help:
- ๐ด Fork the repository
- ๐ฟ Create a feature branch (
git checkout -b feature/amazing-feature) - ๐ป Make your changes
- โ
Run tests with
pytest - ๐ Update documentation if needed
- ๐ Commit your changes (
git commit -m 'Add amazing feature') - ๐ Push to the branch (
git push origin feature/amazing-feature) - ๐ Open a Pull Request
๐ License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tukuy-0.0.1.tar.gz.
File metadata
- Download URL: tukuy-0.0.1.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcb5ac76378750c2e0d98d92b564800f23cbaf62caafe6e33a3f6f5927fd0b83
|
|
| MD5 |
d3bc3cfcf6c80dac2a074319cb724c4d
|
|
| BLAKE2b-256 |
ebf7a7bc7350059601867f0587b8c97ef377b905d8884e3504a95d491bbbe88f
|
File details
Details for the file tukuy-0.0.1-py3-none-any.whl.
File metadata
- Download URL: tukuy-0.0.1-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f161668356920cf9c1229305097db295bb22eb0175e1d357aa3facbb27c762c
|
|
| MD5 |
f61db8871389dd086fd1b34efb99a0ed
|
|
| BLAKE2b-256 |
93b803d6e12930a65e6d92af6e8c23a7fe03f214309e4c709835f4e54522f881
|