Py-Pypr is a pure Python library for functional shift operators.
Project description
Py-Pypr
Py-Pypr is a pure Python library for functional shift operators, enabling readable and intuitive multi-step data transformation pipelines.
Features
-
Chainable pipelines for data transformation.
-
Functional programming style with decorators.
-
Lightweight and easy to use.
Installation
To install Py-Pypr, use pip or uv:
uv pip install py-pypr
pip install py-pypr
Usage
Basic Example
from py_pypr import PypObject, Pypline
# Create a PypObject
data = PypObject(" hello world ")
# pipelines
strip_pipeline = Pypline(str.strip)
uppercase_pipeline = Pypline(str.upper)
# Chain pipelines
data >> strip_pipeline >> uppercase_pipeline
# Get the result
print(data.result()) # Output: "HELLO WORLD"
Using the pypr Decorator
from py_pypr import PypObject, pypr
@pypr
def replace_spaces(data: str) -> str:
return data.replace(" ", "_")
# Create a PypObject
data = PypObject("hello world")
# Apply the decorated function
data >> replace_spaces
# Get the result
print(data.result()) # Output: "hello_world"
Advanced Example
import numpy as np
from py_pypr import PypObject, Pypline, pypr
stepwise = True
# Define object
arr = PypObject(np.ones((3, 120, 120)))
# Establish transforms
def add_to_upperleft(np_arr: np.ndarray, val: int | float) -> np.ndarray:
y, x = np.array(np_arr.shape[1:]) // 2
return np_arr[:, :y, :x] + val # return is required
@pypr(val=12)
def mul_righthalf(np_arr: np.ndarray, val: int | float) -> np.ndarray:
x = np.array(np_arr.shape[2:]) // 2
np_arr[:, :, x.item():] *= val
return np_arr
# Create Pypline
add_5_top_left = Pypline(add_to_upperleft, 5)
if stepwise:
# Transform iteratively
arr.data.mean() # start value (1.0)
for pyp in (add_5_top_left, mul_righthalf):
_ = arr >> pyp
arr.data.mean() # new value (6.0; 39.0)
else:
# Transform single line
arr >> add_5_top_left >> mul_righthalf
arr.data.mean() # new value (39.0)
Documentation
For detailed documentation, visit the GitHub repository.
License
Py-Pypr is licensed under the BSD 3-Clause License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 py_pypr-0.1.0.tar.gz.
File metadata
- Download URL: py_pypr-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0068444ca48842c90a93bbba57d9c53008d3c0a1dd0022f74815c2fbcc2829a8
|
|
| MD5 |
8c46c64a1e235f142fafff16f1667db2
|
|
| BLAKE2b-256 |
df1e93f522626b37f97465dd5405b96580b7845db4d5b482f0c2286aa5a0d682
|
File details
Details for the file py_pypr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_pypr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dfce7e07c7d355f80fd572543ad5173bfb3021146b642bc4c933f77027eba17
|
|
| MD5 |
253d2dd17aceb21932f8b9bdfa49c688
|
|
| BLAKE2b-256 |
2e5e2784067baf964c303fc3c5bb6e5bfe674237736e31e517fba817cdf2f8f8
|