Spaces:
Runtime error
Download README.md from CleanflowAI/cleanflowai: direct link, hf CLI and curl.
- Browser
- Download file 12.7 kB
-
https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/README.md
- Command line
-
hf download hf://spaces/CleanflowAI/cleanflowai/README.md
-
curl -L -o README.md https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/README.md
title: CleanflowAI
emoji: π³
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 8000
pinned: false
ERP to CDF Transformation System v2.0
A high-performance Python system for converting ERP data exports into a standardized Common Data Frame (CDF) format using Polars and DuckDB.
π Features
- β‘ High-Performance Processing with Polars and DuckDB
- π Template-driven mapping with intelligent ERP auto-detection
- π€ AI-assisted mapping for unknown ERP schemas
- π Multiple file formats: CSV, Excel, JSON, SQL, Parquet
- π FastAPI REST API with comprehensive endpoints
- π’ 11 Enterprise ERP Systems with 883+ field mappings
- π Enhanced data models with full address support (16 fields)
- π― 5 Entity Types: Sales Orders, Customers, Invoices, Purchase Orders, Inventory Items
- π§ Production-ready with data format consistency and error handling
π Quick Start
Installation
# Clone the repository
git clone <repository-url>
cd cleanflowai
# Install dependencies
pip install -r requirements.txt
# Install high-performance dependencies
pip install polars duckdb
# Optional: Set up OpenAI API key for LLM fallback
export OPENAI_API_KEY="your-api-key-here"
Option 1: API Server (Recommended)
# Start the API server
python app.py
# API will be available at http://localhost:8000
# Interactive docs at http://localhost:8000/docs
Option 2: Python Package
from mapper import TransformationEngine, TransformationRequest
# Create transformation engine
engine = TransformationEngine()
# Transform data with auto-detection
request = TransformationRequest(
auto_select_erp=True,
auto_select_entity=True,
file_data="sample.csv"
)
result = engine.transform(request)
print(f"Transformed {len(result.data)} records")
Option 3: Quick Transform
from mapper import quick_transform
# One-liner transformation
result = quick_transform(
file_data="sample.csv",
auto_detect=True
)
if result.success:
print(f"β
Converted {len(result.data)} records")
print(f"π Detected ERP: {result.detected_erp}")
π API Endpoints
Core Transformation
POST /transform- Transform JSON data to CDF formatPOST /transform/file- Transform uploaded filesPOST /transform/file/download- Transform and download results
Analysis & Validation
POST /analyze- Analyze data structure and suggest ERP/entity combinationsPOST /validate- Validate file format and structure
Information
GET /health- Health checkGET /entities- List supported entity typesGET /erps- List supported ERP systemsGET /formats- List supported file formats
Template Inspection
GET /template/erp/{erp}/entity/{entity}- Get specific mappingGET /template/entity/{entity}/schema- Get CDF schema
Example API Usage
# Transform JSON data
curl -X POST "http://localhost:8000/transform" \
-H "Content-Type: application/json" \
-d '{
"auto_select_erp": true,
"auto_select_entity": true,
"data": [{"tranId": "SO1001", "total": 1249.0}]
}'
# Upload and transform file
curl -X POST "http://localhost:8000/transform/file" \
-F "file=@sample.csv" \
-F "auto_select_erp=true"
# Download transformed file
curl -X POST "http://localhost:8000/transform/file/download" \
-F "file=@sample.csv" \
-F "output_format=csv" \
-o transformed_data.csv
ποΈ Architecture
Clean Project Structure
cleanflowai/
βββ app.py # Main FastAPI application
βββ template.json # ERP mapping templates (883+ mappings)
βββ requirements.txt # Dependencies
βββ docs/ # Documentation
β βββ API_DOCUMENTATION.md # Complete API docs
β βββ PROJECT_STRUCTURE.md # Architecture details
βββ mapper/ # Core transformation package
βββ __init__.py # Package exports
βββ transformation_engine.py # Main orchestrator (Polars/DuckDB)
βββ data_processor.py # High-performance data processing
βββ template_loader.py # Template management
βββ erp_resolver.py # ERP auto-detection
βββ llm_handler.py # AI integration
βββ models.py # Pydantic models & CDF schemas
Data Flow
Input Data β DataProcessor (Polars/DuckDB) β ERP Detection β
Template Mapping β Transformation β CDF Output
π’ Supported ERP Systems
Enterprise Coverage (11 Systems)
| ERP System | Status | Description |
|---|---|---|
| Oracle Fusion | β Complete | Oracle's cloud ERP platform |
| SAP ERP | β Complete | SAP's enterprise resource planning |
| Microsoft Dynamics | β Complete | Microsoft business applications |
| NetSuite | β Complete | Oracle NetSuite cloud ERP |
| Workday | β Complete | Cloud HR and financial management |
| Infor M3 | β Complete | Manufacturing and distribution ERP |
| Infor LN | β Complete | Enterprise manufacturing ERP |
| Epicor Kinetic | β Complete | Manufacturing ERP solution |
| QAD ERP | β Complete | Manufacturing ERP |
| IFS Cloud | β Complete | ERP and asset management |
| Sage Intacct | β Complete | Cloud financial management |
π Entity Types & CDF Schemas
Sales Orders (13 fields)
order_id, order_date, customer_id, status, currency, total_amount, notes, item_id, description, quantity, unit_price, line_total, tax_code
Customers (16 fields with full address)
Core: customer_id, customer_name, contact_email, phone_number, alt_phone
Business: is_company, status, currency, created_date, last_modified
Address: address_type, address_line1, city, state, postal_code, country
Invoices (14 fields)
invoice_id, invoice_date, customer_id, status, currency, total_amount, due_date, notes, item_id, description, quantity, unit_price, line_total, tax_code
Purchase Orders (14 fields)
po_id, po_date, vendor_id, status, currency, total_amount, expected_receipt_date, notes, item_id, description, quantity, unit_price, line_total, tax_code
Inventory Items (12 fields)
item_id, item_name, description, purchase_description, sales_description, base_price, cost_price, unit_type, is_active, quantity_on_hand, reorder_point, preferred_vendor_id
π File Format Support
| Format | Extension | Description |
|---|---|---|
| CSV | .csv |
Comma-separated values |
| Excel | .xlsx, .xls |
Microsoft Excel files |
| JSON | .json |
JavaScript Object Notation |
| SQL | .sql |
SQL query results |
| Parquet | .parquet |
Columnar storage format |
π§ Data Format Consistency
Date Fields
- APIs/Database: ISO
yyyy-MM-ddformat - Human-readable:
dd-MMMM-yyyyformat (e.g.,04-August-2025)
Decimal Fields
- Precision: DECIMAL(18,2) for all currency and pricing
- Format: Always 2 decimal places (e.g.,
1249.00)
Boolean Fields
- JSON/API:
true/false - Database:
1/0
Text Fields
- Encoding: UTF-8 with proper escaping
- Processing: Trimmed and normalized
β‘ Performance
Benchmarks
- Small files (< 1MB): < 100ms processing time
- Medium files (1-10MB): < 500ms processing time
- Large files (10-100MB): < 2s processing time
High-Performance Features
- Polars: Lightning-fast DataFrame operations
- DuckDB: Optimized SQL query execution
- Memory efficiency: Streaming for large files
- Concurrent processing: FastAPI async support
π Advanced Usage
Custom Configuration
from mapper import TransformationEngine
# Custom engine with specific settings
engine = TransformationEngine(
template_path="custom-template.json",
use_mock_llm=False,
similarity_threshold=0.6
)
Batch Processing
from pathlib import Path
from mapper import create_transformation_engine
engine = create_transformation_engine()
# Process multiple files
for file_path in Path("data").glob("*.csv"):
request = TransformationRequest(
auto_select_erp=True,
auto_select_entity=True,
file_data=str(file_path)
)
result = engine.transform(request)
if result.success:
print(f"β
{file_path.name}: {len(result.data)} records")
Custom LLM Integration
from mapper import TransformationEngine, LLMHandler
# Custom LLM configuration
llm_handler = LLMHandler(
model_name="gpt-4o",
temperature=0.0,
max_retries=3
)
engine = TransformationEngine(llm_handler=llm_handler)
π§ͺ Testing
System Validation
# Test core components
python -c "
from mapper import TransformationEngine, DataProcessor, FileFormat
engine = TransformationEngine(use_mock_llm=True)
processor = DataProcessor()
print('β
All components operational')
"
# Test API
python -c "
from app import app, transformation_engine
print(f'β
API ready: {app.title} v{app.version}')
"
API Testing
# Start server
python app.py
# Test endpoints
curl http://localhost:8000/health
curl http://localhost:8000/entities
curl http://localhost:8000/erps
π Deployment
Local Development
python app.py
# API available at http://localhost:8000
Docker Deployment
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "app.py"]
Production Considerations
- Use production ASGI server (Gunicorn + Uvicorn)
- Configure logging and monitoring
- Implement authentication and rate limiting
- Set up health checks and metrics
π§ Configuration
Environment Variables
# Optional: OpenAI API key for LLM fallback
OPENAI_API_KEY=your-api-key-here
# Optional: Custom template file path
TEMPLATE_PATH=./custom-template.json
Template Structure
The template.json file defines ERP-to-CDF mappings:
{
"NetSuite": {
"sales_orders": {
"tranId": "order_id",
"trandate": "order_date",
"entity": "customer_id",
"total": "total_amount"
}
},
"CDF_META": {
"sales_orders": [
"order_id", "order_date", "customer_id", "status",
"currency", "total_amount", "notes", "item_id",
"description", "quantity", "unit_price", "line_total", "tax_code"
]
}
}
π Documentation
- API Documentation - Complete API reference
- Project Structure - Architecture details
- ERP System Coverage - Mapping statistics
- Data Format Guidelines - Consistency rules
- Changelog - Version history
π οΈ Development
Adding New ERP Systems
- Update
template.jsonwith new mappings - Test with sample data
- Update documentation
Adding New Entity Types
- Define new CDF model in
models.py - Add to
EntityTypeenum - Update template structure
- Add validation logic
Code Quality
# Format code
black mapper/ app.py
# Sort imports
isort mapper/ app.py
# Type checking
mypy mapper/
π Troubleshooting
Common Issues
Missing Dependencies
pip install polars duckdb
LLM API Key Missing
export OPENAI_API_KEY="your-key-here"
# or use mock LLM for testing
Template File Not Found
Ensure template.json exists in working directory
Debug Mode
import logging
logging.basicConfig(level=logging.DEBUG)
# Use mock LLM for testing
engine = TransformationEngine(use_mock_llm=True)
π€ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
π License
This project is licensed under the MIT License.
π Support
For questions, issues, or feature requests:
- Check the API Documentation
- Review the Project Structure
- Search existing issues
- Create a new issue with detailed information
- For API questions, check interactive docs at
/docs
π Built for Enterprise-Grade ERP Data Integration
β‘ Powered by Polars + DuckDB for Maximum Performance
π― Version 2.0.0 - Clean, Fast, Production-Ready