Skip to main content

Build and expose flexible calculation pipelines that give the end user total control over dynamic variables and data logic.

Project description

🔗 filter_pipe

A powerful and flexible Python library for building data processing pipelines with filters and mathematical operations. Chain multiple filters together to process numerical data in a clean, intuitive way.

PyPI Version Python 3.8+


✨ Features

  • ⛓️ Chainable Pipelines - Combine filters seamlessly using pipe syntax
  • 📊 Signal Processing Filters - Moving average, low-pass, high-pass, band-pass, notch filters
  • 🧮 Mathematical Operations - Add, subtract, multiply, divide operations
  • 🎯 Flexible Configuration - Easy-to-read pipeline syntax with customizable parameters
  • 🔍 Regex-based Validation - Robust pattern matching for pipeline chunks

🚀 Quick Start

Installation

pip install -r requirements.txt

Basic Usage

from src.pipeline.pipeline import Pipeline

# Create a pipeline with multiple filters
pipeline = Pipeline('mavg(n=10) | lpass(alpha=0.2) | str(ndigits=2)')

# Process a value through the pipeline
result = pipeline.calc(2134.1231231)
print(result)  # Output: '2064.17'

Mathematical Operations

from src.pipeline.math_ops import Divide, Multiply, Add

# Use mathematical operations
divider = Divide(' / 2')
result = divider.calc(10)
print(result)  # Output: 5.0

# Combine in a pipeline
pipeline = Pipeline('*2 | +5 | /3')
result = pipeline.calc(10)  # (10 * 2 + 5) / 3 = 25/3 ≈ 8.33

Advanced Pipeline Example

# Signal smoothing pipeline: moving average → low-pass filter → round to 2 decimals
pipeline = Pipeline('mavg(n=5) | lpass(alpha=0.3) | str(ndigits=2)')
values = [100.2, 101.5, 99.8, 102.1, 100.9]

for value in values:
    smoothed = pipeline.calc(value)
    print(f"Input: {value:6.1f} → Output: {smoothed}")

📦 Available Pipeline Chunks

🎯 Filters

Chunk Syntax Description Parameters
Moving Average mavg(n=N) Calculates the average of the last N values n - window size (integer)
Low-Pass Filter lpass(alpha=A) Smooths data by attenuating high frequencies alpha - smoothing factor (0-1)
High-Pass Filter hpass(alpha=A) Attenuates low frequencies, preserves high frequencies alpha - smoothing factor (0-1)
Band-Pass Filter bpass(low_alpha=A,high_alpha=B) Passes frequencies within a band low_alpha, high_alpha - bounds (0-1)
Notch Filter notch(low_alpha=A,high_alpha=B) Removes frequencies within a band low_alpha, high_alpha - bounds (0-1)
High Cut hcut(cut=C) Caps maximum value cut - maximum threshold
Low Cut lcut(cut=C) Caps minimum value cut - minimum threshold
To String str(ndigits=N) Converts to formatted string ndigits - decimal places (optional, default=0)

🧮 Math Operations

Chunk Syntax Description Parameters
Divide / D Divides value by D D - divisor (number)
Multiply * M Multiplies value by M M - multiplier (number)
Add + V Adds V to value V - value to add (number)
Subtract - S Subtracts S from value S - value to subtract (number)

💡 Examples

Example 1: Temperature Smoothing

Smooth noisy temperature sensor readings:

from src.pipeline.pipeline import Pipeline

# Combine moving average with low-pass filter
pipeline = Pipeline('mavg(n=3) | lpass(alpha=0.5) | str(ndigits=1)')

temperatures = [20.1, 25.3, 19.8, 21.2, 20.9]
for temp in temperatures:
    smoothed = pipeline.calc(temp)
    print(f"Temperature: {temp}°C → Smoothed: {smoothed}°C")

Example 2: Financial Data Processing

Process stock price data:

# 10-period moving average → normalize → round to 2 decimals
pipeline = Pipeline('mavg(n=10) | str(ndigits=2)')

stock_prices = [150.25, 149.80, 151.10, 150.95, 149.50]
for price in stock_prices:
    avg = pipeline.calc(price)
    print(f"${price} → MA: ${avg}")

Example 3: Signal Processing

Apply advanced filtering:

# Remove noise with band-pass → apply notch → convert to string
pipeline = Pipeline('bpass(low_alpha=0.2,high_alpha=0.8) | notch(low_alpha=0.3,high_alpha=0.7) | str(ndigits=3)')

signal_data = [0.5, 0.6, 0.55, 0.58, 0.52]
for signal in signal_data:
    filtered = pipeline.calc(signal)
    print(f"Signal: {signal} → Filtered: {filtered}")

Example 4: Value Constraints

Bound values within a range:

# Scale value, then apply min/max constraints
pipeline = Pipeline('*10 | lcut(cut=0) | hcut(cut=100)')

raw_values = [-1.5, 5.3, 12.8, -0.2]
for val in raw_values:
    bounded = pipeline.calc(val)
    print(f"{val}{bounded} (0-100 range)")

🧪 Running Tests

Execute the test suite to verify functionality:

python3 -m pytest

Tests are located in the tests/ directory:

  • test_filters.py - Filter functionality tests
  • test_math.py - Math operations tests
  • test_pipeline.py - Pipeline chaining tests

🔗 Resources

  • 📦 PyPI Package: Find this project on PyPI
  • �💼 Regex Patterns: Learn and test regex patterns used in this project at regex101.com
  • 📚 Tools: See tools/index.html for playing around with the filters and learn how to calibrate the gains.

📝 License

This project is open-source and available for educational and commercial use.


Built with ❤️ for data processing pipelines

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

filter_pipe-1.0.1.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

filter_pipe-1.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file filter_pipe-1.0.1.tar.gz.

File metadata

  • Download URL: filter_pipe-1.0.1.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for filter_pipe-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7cbb19fcb03f50bff8c5fd585cedac9bb7c5b67975c781bc9862e2436a0d839b
MD5 861636fb60d94914ebf68c64e439b045
BLAKE2b-256 01321b32da51b9539bea4ad23e11a89b3d6d48fa346768c1756672787203af32

See more details on using hashes here.

Provenance

The following attestation bundles were made for filter_pipe-1.0.1.tar.gz:

Publisher: build.yaml on Jair-F/filter_pipe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file filter_pipe-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: filter_pipe-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for filter_pipe-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd088324d7e17726e84df4127b3f90d975b3ee4e5a3f5a5a6acd89f880da0085
MD5 c670be80823ef185cd9aa8c41116663c
BLAKE2b-256 12d2b9629e96e4c6b3e81fffb11bf09793e59f593d643c7d155cc37fd968724c

See more details on using hashes here.

Provenance

The following attestation bundles were made for filter_pipe-1.0.1-py3-none-any.whl:

Publisher: build.yaml on Jair-F/filter_pipe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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