Pipeline framework for task-based data processing workflows.
Project description
Purple Titanium
A Python pipeline framework that provides a structured way to define and execute task-based data processing workflows.
Example
Here's a comprehensive example demonstrating the pipeline framework's features:
import purple_titanium as pt
from typing import List, Dict, Optional
# Define tasks with type hints for better clarity
@pt.task()
def fetch_data() -> List[int]:
"""Simulates fetching data from a source."""
return [1, 2, 3, 4, 5]
@pt.task()
def validate_data(data: List[int]) -> List[int]:
"""Validates the input data."""
if not data:
raise ValueError("Data cannot be empty")
if not all(isinstance(x, int) for x in data):
raise TypeError("All elements must be integers")
return data
@pt.task()
def process_data(data: List[int]) -> List[int]:
"""Processes the data by applying transformations."""
return [x * 2 for x in data]
@pt.task()
def analyze_data(data: List[int]) -> Dict[str, float]:
"""Analyzes the processed data and returns statistics."""
return {
"sum": sum(data),
"average": sum(data) / len(data),
"count": len(data)
}
# Event listeners for monitoring pipeline execution
@pt.listen(pt.TASK_STARTED)
def on_task_started(event):
print(f"Task {event.task.name} started")
@pt.listen(pt.TASK_FINISHED)
def on_task_finished(event):
print(f"Task {event.task.name} finished successfully")
@pt.listen(pt.TASK_FAILED)
def on_task_failed(event):
print(f"Task {event.task.name} failed: {event.task.exception}")
# Create the pipeline with error handling
try:
# Define the pipeline
raw_data = fetch_data()
validated_data = validate_data(raw_data)
processed_data = process_data(validated_data)
analysis = analyze_data(processed_data)
# Execute the pipeline
result = analysis.resolve()
print("Pipeline completed successfully!")
print(f"Analysis results: {result}")
# Expected output:
# Analysis results: {'sum': 30, 'average': 6.0, 'count': 5}
except ValueError as e:
print(f"Validation error: {e}")
except TypeError as e:
print(f"Type error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
# Example of checking task existence
print(f"Raw data task exists: {raw_data.exists()}") # True
print(f"Analysis task exists: {analysis.exists()}") # True
This example demonstrates several key features of the framework:
-
Task Definition
- Tasks are created using the
@pt.task()decorator - Type hints provide clear interface definitions
- Each task has a single responsibility
- Tasks are created using the
-
Dependency Management
- Tasks can depend on other tasks through their parameters
- Dependencies are automatically resolved
- The framework ensures correct execution order
-
Error Handling
- Tasks can raise exceptions that propagate through the pipeline
- Exceptions can be caught at any level
- Failed tasks maintain their error state
-
Event System
- Event listeners can monitor pipeline execution
- Events are emitted for task start, completion, and failure
- Custom event handling enables monitoring and logging
-
Task State
- The
exists()method checks if a task has been executed - Task state persists after execution
- Failed tasks maintain their error state
- The
-
Pipeline Execution
- The
resolve()method executes the pipeline - Only one
resolve()call is allowed in the call stack - Results are cached for efficiency
- The
Code Contribution
Prerequisites
- Python 3.8 or higher
- uv for dependency management
Development Setup
-
Clone the repository:
git clone https://github.com/yourusername/purple-titanium.git cd purple-titanium
-
Install uv if you don't have it already:
pip install uv
-
Set up the development environment:
uv venv uv pip install -e ".[dev]" # Installs package in editable mode with dev dependencies
Development Tools
-
Testing: Run the test suite
pytest
-
Code Quality:
# Run linting checks ruff check . # Format code ruff format .
Contributing Guidelines
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting
- 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 License
Copyright (c) 2024 Purple Titanium Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
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 purple_titanium-0.1.1.tar.gz.
File metadata
- Download URL: purple_titanium-0.1.1.tar.gz
- Upload date:
- Size: 597.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6809dad5713ab7a9cc08a243d1937bd070fecb9e1a43eba081f198be7bb7a164
|
|
| MD5 |
6e1776e5a9246c2e1a5e9e4431199d95
|
|
| BLAKE2b-256 |
1b9875b5f0cca757a3c501aca6123715a152df458570de3d0ccde85602f0d572
|
File details
Details for the file purple_titanium-0.1.1-py3-none-any.whl.
File metadata
- Download URL: purple_titanium-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
613dc67d13137cc14cd8810b6165bc807ec80cabcd9afadf63be4ed842f6f2ff
|
|
| MD5 |
8b37f779d5a4b9863732fa3a9ff6d50f
|
|
| BLAKE2b-256 |
72685fdb4ee7ae3f601f4061a2e09ac2cd18bc4e78040e2142604fd23c2792a5
|