PySpark Transform Registry
A simplified library for registering and loading PySpark transform functions using MLflow's model registry.
Installation
pip install pyspark-transform-registry
uv add pyspark-transform-registry
Quick Start
Register a Function
from pyspark_transform_registry import register_transform
from pyspark.sql import DataFrame
import pyspark.sql.functions as F
def clean_data(df: DataFrame) -> DataFrame:
"""Remove invalid records and standardize data."""
return df.filter(F.col("amount") > 0).withColumn("status", F.lit("clean"))
# Register the transform
logged_model = register_transform(
func=clean_data,
name="analytics.etl.clean_data",
description="Data cleaning transformation"
)
Load and Use a Transform
from pyspark_transform_registry import load_transform, load_transform_uri
# Load the registered transform
clean_data_func = load_transform("analytics.etl.clean_data", version=1)
# Or
clean_data_func = load_transform_uri("transforms:/analytics.etl.clean_data/1")
# Use it on your data
result = clean_data_func(your_dataframe)
Features
- Simple API: Just two main functions -
register_transform()andload_transform() - Direct Registration: Register transforms directly from Python code
- File-based Registration: Load and register transforms from Python files
- Automatic Versioning: Integer-based versioning with automatic incrementing
- MLflow Integration: Built on MLflow's model registry
Usage Examples
Direct Transform Registration
from pyspark_transform_registry import register_transform
from pyspark.sql import DataFrame
import pyspark.sql.functions as F
def risk_scorer(df: DataFrame, threshold: float = 100.0) -> DataFrame:
"""Calculate risk scores based on amount."""
return df.withColumn(
"risk_score",
F.when(F.col("amount") > threshold, "high").otherwise("low")
)
# Register with metadata
register_transform(
func=risk_scorer,
name="finance.scoring.risk_scorer",
description="Risk scoring transformation",
extra_pip_requirements=["numpy>=1.20.0"],
tags={"team": "finance", "category": "scoring"}
)
File-based Registration
# transforms/data_processors.py
from pyspark.sql import DataFrame
import pyspark.sql.functions as F
def feature_engineer(df: DataFrame) -> DataFrame:
"""Create engineered features."""
return df.withColumn("feature_1", F.col("amount") * 2)
# Register from file
register_transform(
file_path="transforms/data_processors.py",
function_name="feature_engineer",
name="ml.features.feature_engineer",
description="Feature engineering pipeline"
)
Source Code Inspection
# Load a transform
transform = load_transform("retail.processing.process_orders", version=1)
# Get the original source code
source_code = transform.get_source()
print(source_code) # Shows the original function definition
# Get the original function for inspection
original_func = transform.get_original_function()
print(f"Function name: {original_func.__name__}")
print(f"Docstring: {original_func.__doc__}")
Managing Transform Dependencies
Install dependencies for registered transforms automatically:
from pyspark_transform_registry import install_transform_requirements
# Install all dependencies for a transform
install_transform_requirements("transforms:/analytics.etl.clean_data/1")
# Then load the transform (dependencies are now available)
transform = load_transform("analytics.etl.clean_data", version=1)
You can also exclude certain packages (useful when running in environments like Databricks where some packages are pre-installed):
# Install dependencies but exclude packages already available in the environment
install_transform_requirements(
"transforms:/analytics.etl.clean_data/1",
exclude_packages=["pyspark", "mlflow", "pandas"]
)
Requirements
- Python 3.9+
- PySpark 3.0+
- MLflow 3.0+
Development
# Install development dependencies
make install
# Run tests
make test
# Run linting and formatting
make check
License
MIT License
Metadata
Release files for pyspark-transform-registry 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyspark_transform_registry-0.12.0.tar.gz | 15.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyspark_transform_registry-0.12.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.3 kB
Release files / pyspark_transform_registry-0.12.0.tar.gz
| Download URL | pyspark_transform_registry-0.12.0.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28959d95c2977d27a0abd1ab4e21e9ee987f5c1ea1b2baef55a793661b9ccff3
|
|
BLAKE2b-256 checksum How to use checksums |
97c08988dc7a7a50134768e627ca2efffc86ce2ef2564b0ca325893137c2a44f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|
Release files / pyspark_transform_registry-0.12.0-py3-none-any.whl
| Download URL | pyspark_transform_registry-0.12.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c106134aee4d88ace8e8f72e8caf681b282d964ced31f386ca8d6f2acd6f1e09
|
|
BLAKE2b-256 checksum How to use checksums |
ea743e541cb901733e2c6268f3eebde5778e090d0dd75ca2e3488237b63bd67f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|
Security for pyspark-transform-registry 0.12.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.