Skip to main content

lapipe

A tiny, zero-dependency “value-first” pipe helper for Python  —  inspired by Unix pipes and F#’s |>, but with an optional _ placeholder so you can drop the value exactly where you need it.

PyPI Python


Why?

  • Chain data-transform steps without intermediate variables
  • Keep left-to-right reading order (like functional pipes)
  • Explicitly mark the slot with _ only when you need to
  • Works with any callables — Pandas, NumPy, matplotlib, your own functions — no monkey-patching or heavy frameworks

Installation

pip install lapipe

Quick start

from lapipe import pipe, _

def add(a, b):      return a + b
def mul(a, b):      return a * b

result = (
    pipe(2)               # wrap the value
    | (add, 3)            # 2 -> first arg: add(2, 3)
    | (mul, 4, _)         # 5 -> second arg: mul(4, 5)
)
print(result.value)        # 20

Rules in one table

syntax how the value is passed
` func` first positional arg
` (func, *args)` first positional arg
` (func, …, _)` replaces that _
` (func, {..., k=_})` replaces that kwarg _
returns new Pipe each step

Examples

1. NumPy vector math

import numpy as np
from lapipe import pipe, _

vec = np.arange(5)                # [0 1 2 3 4]

out = (
    pipe(vec)
    | (np.add, 10)                # [10 11 12 13 14]
    | (np.multiply, 2, _)         # [20 22 24 26 28]
    | (np.power, _, 2)            # square each
)
print(out.value)
# [400 484 576 676 784]

2. Pandas transformation + plot

import pandas as pd, matplotlib.pyplot as plt
from lapipe import pipe, _

df = pd.DataFrame({
    "year": range(2010, 2025),
    "sales": [42, 45, 47, 44, 50, 54, 57, 60, 64, 66, 70, 74, 78, 81, 85]
})

(
    pipe(df)
    | (pd.DataFrame.copy, _)              # keep original intact
    | (pd.DataFrame.set_index, _, "year")
    | (pd.DataFrame.assign, growth=lambda d: d.sales.pct_change())
    | (pd.DataFrame.rolling, 3)           # 3-year moving mean
    | (pd.core.window.Rolling.mean, _)    # computes .mean()
    | (pd.DataFrame.plot, _, y="sales")   # `_` is DataFrame here
)
plt.title("3-year moving average sales")
plt.show()

3. Keyword placeholder

def greet(who, *, punct="!"):
    return f"Hello {who}{punct}"

pipe("?") | (greet, "world", {'punct': _})
# Pipe('Hello world?')

API

pipe(value)        # wrap any value → returns Pipe
Pipe | func        # call func(value, …)
Pipe | (func, ...) # tuple form with args / kwargs
_                  # sentinel placeholder
Pipe.value         # access the wrapped result

That’s it! No other symbols, no hidden globals.


Design notes

  • No string → AST tricks. Just normal Python calls.
  • No runtime import hacks. You decide which libraries to use.
  • Stateless. Each step returns a new Pipe; the original stays unchanged.
  • Pure Python 3.8+. One file, ~80 lines.

Contributing

Issues and PRs are super welcome! If you find an edge-case that breaks the placeholder logic (looking at you, Pandas & NumPy dtypes), open an issue or send a failing test.

git clone https://github.com/yourname/lapipe
pytest

License

MIT — do what you want, just keep the copyright and don’t blame us.


Designed so your data can flow like water, not spaghetti. Enjoy piping! 🚰

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lapipe-1.0.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

lapipe-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file lapipe-1.0.0.tar.gz.

File metadata

  • Download URL: lapipe-1.0.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for lapipe-1.0.0.tar.gz
Algorithm Hash digest
SHA256 329f408b30a9ffcd1fbde9a9570b3561f690f126fb98131974fc0f4ea991a5c1
MD5 97ac1d60932bd3bbb6687487554653c2
BLAKE2b-256 a966661359546ea165a741549fa53235176aefc247755467d4f8f0a7b7e42e75

See more details on using hashes here.

File details

Details for the file lapipe-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lapipe-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for lapipe-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d73543c30389893b2c416b8bf0db934eeeb38a96e6d253df8cf70bdeac32e27c
MD5 d58a63f1f6d18af9d87fa662d9a323c1
BLAKE2b-256 e7e4683d56b13e0d7983bf843fa4a2a0fdf5e004e5966336cf35576d212b52a0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page