Skip to main content

Tiny pipeline library for ordinary Python scripts.

Project description

pypelite

Pypelite is a tiny pipeline library for ordinary Python scripts.

Wrap the expensive steps with @pypelite.stage and run your script inside pypelite.pipeline(...). Stage outputs are saved to disk, so a failed run can resume from the completed steps, and a later run can refresh only the stages you want to rerun.

import pypelite

@pypelite.stage("load", fanout_arg="symbols", batch_size=50, workers=4)
def load_prices(symbols):
    return market_api.fetch_prices(symbols)

@pypelite.stage("features")
def build_features(prices_df):
    return make_model_features(prices_df)

@pypelite.stage("train")
def train_model(features_df):
    return fit_price_model(features_df)

with pypelite.pipeline("runs/price-model"):
    prices_df = load_prices(["AAPL", "MSFT", "NVDA"])
    features_df = build_features(prices_df)
    model = train_model(features_df)

No DSL, no DAG boilerplate, no Airflow deployment. The Python code is the pipeline.

Installation

pip install pypelite

Documentation

Refresh, Skip, Clean

Control a run from the pipeline context.

with pypelite.pipeline(
    path="runs/experiment",
    refresh=["features"],
    skip=["train"],
    clean=["predict"],
    until="features",
):
    run_price_model()
  • refresh recomputes named stages touched by the run.
  • skip returns a stage's skip_value without touching its cache.
  • clean removes old keyed artifacts not touched by a successful run.
  • until stops after the named stage completes.

Advanced Features

Item Caches

Use key when each item should have its own saved result. Use ignore to leave fields out of a composite key while still passing them to the function.

@pypelite.stage("predict", key=("symbol", "run_id"), ignore="run_id")
def predict_price(symbol, run_id, feature_row):
    return model.predict(feature_row)

with pypelite.pipeline("runs/predictions"):
    for symbol, feature_row in features_df.iterrows():
        predict_price(symbol, run_id="daily", feature_row=feature_row)

Fanout

Use workers when fanout should run in parallel.

@pypelite.stage("features", key="symbol", fanout_arg="symbols", workers=4)
def build_symbol_features(symbols):
    prices_df = market_api.fetch_prices(symbols)
    return make_model_features_by_symbol(prices_df)

with pypelite.pipeline("runs/features"):
    feature_rows = build_symbol_features(["AAPL", "MSFT", "NVDA"])

Batches

Use fanout_arg when work should run in chunks.

@pypelite.stage("predict", key="symbol", fanout_arg="rows", batch_size=200)
def predict_prices(rows):
    return model_api.batch_predict(rows)

with pypelite.pipeline("runs/predictions"):
    predictions = predict_prices(feature_rows)

Batch stages can run chunks in parallel with workers. Unkeyed batches use temporary chunk files while building one final artifact; keyed batches save one result file per key.

Shared Archives

Stages can choose named archives.

@pypelite.stage("prices", archive="market", key=("date", "symbol"))
def prices(date, symbol):
    return market_api.price(date, symbol)

with pypelite.pipeline(
    archives={"default": "runs/model", "market": "archive/market"},
):
    run_price_model()

Shared archives make it easy for many experiments to reuse the same market data while keeping model outputs in their own run directories.

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

pypelite-0.1.5.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

pypelite-0.1.5-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file pypelite-0.1.5.tar.gz.

File metadata

  • Download URL: pypelite-0.1.5.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pypelite-0.1.5.tar.gz
Algorithm Hash digest
SHA256 be15297aab2bd85c382db050d4efec22eb445ee9249a7d670c69e5b6e1ad59a9
MD5 74aeb472caf261e6b60e54633676829b
BLAKE2b-256 f2928f41097196436a3b43ad7f3964f9477d220040585c9635e9aae3f504fec6

See more details on using hashes here.

File details

Details for the file pypelite-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pypelite-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pypelite-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dc60b8a708b7b2bed52804f8307b889526313f5eb492c05912693721c13c4462
MD5 9a095b263d4e5e3a127939951b360083
BLAKE2b-256 4d863464bbe6dcef7dffb2d35af90ce79d539439fcce7a8c19d46f05e3f8c4bb

See more details on using hashes here.

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