WithPipe is a simple utility for functional piping in Python.

Overview

WithPipe

Introduction

WithPipe is a simple utility for functional piping in Python. The package exposes a context manager (used with with) called PipeContext, that allows you to access any function in any scope as a partial, meaning that it's naturally pipeable. Here's a contrived example from the test suite:

import numpy as np
from with_pipe import PipeContext
from pipetools import pipe

with PipeContext() as _:
    ret = (
        10 > pipe |
        _.np.ones() |
        _.np.reshape(newshape=(5, 2)) |
        _.np.mean() |
        _.int()
    )
    assert ret == 1

As you can see, we were able to call both numpy and built-in functions on the _ object, and it executed the pipeline similarly to say R's magrittr package.

Installation

pip install git+https://github.com/multimeric/WithPipe.git

Usage

Actually WithPipe doesn't provide an actual piping mechanism, but it does add a useful syntax for use with pipes. For the actual piping mechanism, I suggest that you try pipetools, which this package is actually tested against.

WithPipe provides a single class: PipeContext. The way you use PipeContext is by first using it as a context manager:

with PipeContext() as _:

Then, using the return value of the context manager, which we have named _ (but you could call it anything), you access attributes and items (using .attr or ["key"] or [0]) to locate the function you want and then you finally call it (), which will create the partial. You can use positional and keyword arguments at this point if you need

For more usage information, refer to the test suite.

Tests

Note: you will need poetry installed.

git clone https://github.com/multimeric/WithPipe.git
cd WithPipe
poetry install --extras pipetools
poetry run pytest test/
You might also like...
My first Python project is a simple Mad Libs program.
My first Python project is a simple Mad Libs program.

Python CLI Mad Libs Game My first Python project is a simple Mad Libs program. Mad Libs is a phrasal template word game created by Leonard Stern and R

simple way to build the declarative and destributed data pipelines with python

unipipeline simple way to build the declarative and distributed data pipelines. Why you should use it Declarative strict config Scaffolding Fully type

Flenser is a simple, minimal, automated exploratory data analysis tool.

Flenser Have you ever been handed a dataset you've never seen before? Flenser is a simple, minimal, automated exploratory data analysis tool. It runs

AptaMat is a simple script which aims to measure differences between DNA or RNA secondary structures.

AptaMAT Purpose AptaMat is a simple script which aims to measure differences between DNA or RNA secondary structures. The method is based on the compa

Data Scientist in Simple Stock Analysis of PT Bukalapak.com Tbk for Long Term Investment
Data Scientist in Simple Stock Analysis of PT Bukalapak.com Tbk for Long Term Investment

Data Scientist in Simple Stock Analysis of PT Bukalapak.com Tbk for Long Term Investment Brief explanation of PT Bukalapak.com Tbk Bukalapak was found

Generates a simple report about the current Covid-19 cases and deaths in Malaysia

Generates a simple report about the current Covid-19 cases and deaths in Malaysia. Results are delay one day, data provided by the Ministry of Health Malaysia Covid-19 public data.

Example Of Splunk Search Query With Python And Splunk Python SDK
Example Of Splunk Search Query With Python And Splunk Python SDK

SSQAuto (Splunk Search Query Automation) Example Of Splunk Search Query With Python And Splunk Python SDK installation: ➜ ~ git clone https://github.c

Business Intelligence (BI) in Python, OLAP
Business Intelligence (BI) in Python, OLAP

Open Mining Business Intelligence (BI) Application Server written in Python Requirements Python 2.7 (Backend) Lua 5.2 or LuaJIT 5.1 (OML backend) Mong

Owner
Michael Milton
Michael Milton
PipeChain is a utility library for creating functional pipelines.

PipeChain Motivation PipeChain is a utility library for creating functional pipelines. Let's start with a motivating example. We have a list of Austra

Michael Milton 2 Aug 7, 2022
Very basic but functional Kakuro solver written in Python.

kakuro.py Very basic but functional Kakuro solver written in Python. It uses a reduction to exact set cover and Ali Assaf's elegant implementation of

Louis Abraham 4 Jan 15, 2022
Python library for creating data pipelines with chain functional programming

PyFunctional Features PyFunctional makes creating data pipelines easy by using chained functional operators. Here are a few examples of what it can do

Pedro Rodriguez 2.1k Jan 5, 2023
TE-dependent analysis (tedana) is a Python library for denoising multi-echo functional magnetic resonance imaging (fMRI) data

tedana: TE Dependent ANAlysis TE-dependent analysis (tedana) is a Python library for denoising multi-echo functional magnetic resonance imaging (fMRI)

null 136 Dec 22, 2022
Functional tensors for probabilistic programming

Funsor Funsor is a tensor-like library for functions and distributions. See Functional tensors for probabilistic programming for a system description.

null 208 Dec 29, 2022
Python utility to extract differences between two pandas dataframes.

Python utility to extract differences between two pandas dataframes.

Jaime Valero 8 Jan 7, 2023
Pandas-based utility to calculate weighted means, medians, distributions, standard deviations, and more.

weightedcalcs weightedcalcs is a pandas-based Python library for calculating weighted means, medians, standard deviations, and more. Features Plays we

Jeremy Singer-Vine 98 Dec 31, 2022
small package with utility functions for analyzing (fly) calcium imaging data

fly2p Tools for analyzing two-photon (2p) imaging data collected with Vidrio Scanimage software and micromanger. Loading scanimage data relies on scan

Hannah Haberkern 3 Dec 14, 2022
Datashredder is a simple data corruption engine written in python. You can corrupt anything text, images and video.

Datashredder is a simple data corruption engine written in python. You can corrupt anything text, images and video. You can chose the cha

null 2 Jul 22, 2022