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 "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:

  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

๐Ÿ“„ License

MIT

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.1.tar.gz (30.1 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.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

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

Hashes for tukuy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bcb5ac76378750c2e0d98d92b564800f23cbaf62caafe6e33a3f6f5927fd0b83
MD5 d3bc3cfcf6c80dac2a074319cb724c4d
BLAKE2b-256 ebf7a7bc7350059601867f0587b8c97ef377b905d8884e3504a95d491bbbe88f

See more details on using hashes here.

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

Hashes for tukuy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f161668356920cf9c1229305097db295bb22eb0175e1d357aa3facbb27c762c
MD5 f61db8871389dd086fd1b34efb99a0ed
BLAKE2b-256 93b803d6e12930a65e6d92af6e8c23a7fe03f214309e4c709835f4e54522f881

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