Skip to main content

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 "to transform" or "to become" 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
TUKUY = ToolsTransformer()

# Basic text transformation
text = " Hello World! "
result = TUKUY.transform(text, [
    "strip",
    "lowercase",
    {"function": "truncate", "length": 5}
])
print(result)  # "hello..."

# HTML transformation
html = "<div>Hello <b>World</b>!</div>"
result = TUKUY.transform(html, [
    "strip_html_tags",
    "lowercase"
])
print(result)  # "hello world!"

# Date transformation
date_str = "2023-01-01"
age = TUKUY.transform(date_str, [
    {"function": "age_calc"}
])
print(age)  # 1

# Validation
email = "test@example.com"
valid = TUKUY.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
TUKUY = ToolsTransformer()
TUKUY.register_plugin(MyPlugin())

result = TUKUY.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 = TUKUY.extract_html_with_pattern(html, pattern)

๐Ÿ“‹ JSON Extraction

pattern = {
    "properties": [
        {
            "name": "user",
            "selector": "data.user",
            "properties": [
                {
                    "name": "name",
                    "selector": "fullName",
                    "transform": ["strip"]
                }
            ]
        }
    ]
}

data = TUKUY.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 = TUKUY.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:

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch (git checkout -b feature/amazing-feature)
  3. ๐Ÿ’ป Make your changes
  4. โœ… Run tests with pytest
  5. ๐Ÿ“ Update documentation if needed
  6. ๐Ÿ”„ Commit your changes (git commit -m 'Add amazing feature')
  7. ๐Ÿš€ Push to the branch (git push origin feature/amazing-feature)
  8. ๐Ÿ” Open a Pull Request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tukuy-0.0.2.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tukuy-0.0.2-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file tukuy-0.0.2.tar.gz.

File metadata

  • Download URL: tukuy-0.0.2.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tukuy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ad25e93d2f2b31d947104d70ab78d345deb8718fa233081a00b9e133942bc4a3
MD5 7a87c3c4b2adc1a214ff4d255cb53321
BLAKE2b-256 7f5650bbd9c7674140cdcccc3c3c22ae47356911949b030209ab917f33f4bb2f

See more details on using hashes here.

File details

Details for the file tukuy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: tukuy-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tukuy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5664382069101f220a6bb259e065d60ffa3890f9579dc8cec536703b502799d
MD5 c5cf2b678ee591813daa3812424a22d1
BLAKE2b-256 42c5da9b8f65ded8c5627b56ea6e0c5ff8955d49e3455794fed9f2b1b6e74932

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page