Skip to main content

Refinery components for the Sayou Data Platform

Project description

sayou-refinery

PyPI version License Docs

The Universal Data Cleaning & Normalization Engine for Sayou Fabric.

sayou-refinery acts as the "Cleaning Plant" in your data pipeline.

It transforms heterogeneous raw data (JSON Documents, HTML, DB Records) into a standardized stream of SayouBlocks, ensuring that downstream components (like Chunkers or LLMs) receive clean, uniform data regardless of the original source format.

💡 Core Philosophy

"Flatten Structure, Polish Content."

Refinery operates in two distinct stages to guarantee data quality:

  1. Normalization (Shape Shifting): Converts complex structures (nested JSON, HTML trees, DB Rows) into a linear list of SayouBlocks.
  2. Processing (Cleaning): Applies a chain of cleaning agents (Regex, Masking, Deduplication) to improve data hygiene.

📦 Installation

pip install sayou-refinery

⚡ Quick Start

The RefineryPipeline orchestrates the normalization and processing chain.

from sayou.refinery.pipeline import RefineryPipeline

def run_demo():
    # 1. Initialize with specific cleaning rules
    pipeline = RefineryPipeline()
    pipeline.initialize(
        mask_email=True,
        outlier_rules={"price": {"min": 0, "max": 1000, "action": "clamp"}}
    )

    # 2. Raw Data (e.g., from sayou-document)
    raw_doc = {
        "metadata": {"title": "Test Doc"},
        "pages": [{
            "elements": [
                {"type": "text", "text": "Contact: admin@sayou.ai"},
                {"type": "text", "text": "   Dirty   Whitespace   "}
            ]
        }]
    }

    # 3. Run Pipeline
    # source_type: 'standard_doc', 'html', 'json', etc.
    blocks = pipeline.run(raw_doc, source_type="standard_doc")

    # 4. Result
    for block in blocks:
        print(f"[{block.type}] {block.content}")
        
        # Output:
        # [md_meta] --- title: Test Doc ...
        # [md] Contact: [EMAIL]
        # [md] Dirty Whitespace

if __name__ == "__main__":
    run_demo()

🔑 Key Components

Normalizers

  • DocMarkdownNormalizer: Converts Sayou Document Dicts into Markdown blocks.
  • HtmlTextNormalizer: Strips HTML tags and scripts, extracting clean text.
  • RecordNormalizer: Converts DB rows or JSON objects into 'record' blocks.

Processors

  • TextCleaner: Normalizes whitespace and removes noise via regex.
  • PiiMasker: Masks sensitive info like emails and phone numbers.
  • Deduplicator: Removes duplicate content blocks.
  • Imputer: Fills missing values in record blocks.
  • OutlierHandler: Filters or clamps numerical outliers in records.

🤝 Contributing

We welcome contributions for new Normalizers (e.g., CsvNormalizer, LogNormalizer) or Processors (e.g., LangChainFilter).

📜 License

Apache 2.0 License © 2025 Sayouzone

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

sayou_refinery-0.2.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

sayou_refinery-0.2.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file sayou_refinery-0.2.0.tar.gz.

File metadata

  • Download URL: sayou_refinery-0.2.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sayou_refinery-0.2.0.tar.gz
Algorithm Hash digest
SHA256 47dade55859282a2c7037af1f208f5893fa181b57c18f40f31cabe34219a4b62
MD5 1f19e55b93f3071ca06a47de2b5d81c4
BLAKE2b-256 47f4ea41b3c3b3902dedbe9b7428b130de5af3ab9facbdee71b37469def9f111

See more details on using hashes here.

File details

Details for the file sayou_refinery-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sayou_refinery-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sayou_refinery-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fb06fde16215f88cb5330d7e79dbcdeac45f89f10638fb1c082abf5ae3b39c5
MD5 a201e31d32fefb557375d8636d9b589f
BLAKE2b-256 bfbdd085f90e9930d593a13f60329acd7423f8040a67bf6a1916eb47372e67ca

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