Skip to main content

pipeit

fury licence pyversions Publish Build

This is a super simple wrapper , let's use python functional programming like Unix pipe!

Inspired by abersheeran/only-pipe , czheo/syntax_sugar_python , pipetools

Install

pip install pipeit

Usage

  • Statements start with PIPE and end with END OR you can even ellipsis them.
  • There're only two objects(PIPE & END) and three types(Filter ,Map & Reduce) in namespace, so feel free to use from pipeit import *.
  • Convert filter into tuple or capital the first letter, e.g. map(lambda x:x + 1) => (map , lambda x:x + 1) or Map(lambda x:x + 1) , however DO NOT MIX USE THEM.
  • It'll be 10% ~ 20% faster using the original python functional way than using these wrappers.

v0.2.0 Update:

  • Simple code timing means

v0.3.0 Update:

  • Easier reading and writing operations

Example

Basic useage:

>>> from pipit import PIPE , END , Map , Filter , Reduce

>>> data = PIPE | range(10) | (map , lambda x:x + 1) | (map , str) | list | END
>>> data
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

# (map , lambda x:x + 1) equals to Map(lambda x:x + 1)
>>> func = lambda x: PIPE | range(x) | Map(lambda x:x + 1) | Map(str) | list | END
>>> func(10)
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

Or you may want a more easy use.

>>> range(10) | Filter(lambda x:x<5) | list
[0, 1, 2, 3, 4]

>>> for _ in range(3) | Map(str):
        print(repr(_))


'0'
'1'
'2'

Code timer updated in version 0.2.0, you can easily detect the execution time of code blocks or statements.

from pipeit import *
from functools import reduce

foo = list(range(100))
for _ in timeit(1e6): # which means loop for 1m times
    bar = foo | Filter(lambda x: x%3) | Map(lambda x: 10*x) | Reduce(lambda x, y: x+y) | int

with timeit(): # a handwritten for loop is required under context manager mode
    for _ in range(int(1e6)):
        bar = reduce(lambda x, y: x+y, map(lambda x: 10*x, filter(lambda x: x%3, foo)))

# output: 
# [line 5][approximate] time cost / loop: 9.8967234μs
# [line 8][exact] time cost: 7.0519098s 

Better IO functions are updated in version 0.3.0. If you hate typing encoding="utf-8" over and over again, believe me, you'll love them.

Use simple Read()/Write()/ReadB()/WriteB() functions instead of the default practice of with open(). You can specify the encoding format, but they are specified as utf-8 by default. Another advantage of doing this is that you no longer need to worry about accidentally emptying the file by not changing 'w' to 'r'.

from pipeit import *
import json

# 
Write("a.txt", "Hello World!")
WriteB("b.json", "[1, 2, 3]".encode("utf-8"))
assert Read("a.txt") == "Hello World!"
assert ReadB("b.txt") == b"[1, 2, 3]"

Similarly, you can use pipes to send data to them, or pipes to receive data from them.

# OR
"[1, 2, 3]".encode("utf-8") | WriteB("b.json")

# another typical scenario is to cache data to hard disk and read it back again
html_a = "abc" # requests.get("https://a.example.com").text
html_b = "123" # ...
htmls = {"html_a": html_a, "html_b": html_b}
json.dumps(htmls) | Write("htmls.json")
# 
htmls = Read("htmls.json") | json.loads
html_a, html_b = htmls.values()

>> and | operands are functionally identical while doing IO.

"Hello World!" >> Write("a.txt")
text = Read("a.txt") >> str
assert text == "Hello World!"

Metadata

Release files for pipeit 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pipeit 0.3.4
File Size Uploaded Provenance Actions
pipeit-0.3.4.tar.gz 14.8 kB Without provenance Details for pipeit-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pipeit 0.3.4
File Interpreter ABI Platform Actions
pipeit-0.3.4-py3-none-any.whl Python 3 none any Details for pipeit-0.3.4-py3-none-any.whl

Total release size: 29.9 kB

Release files / pipeit-0.3.4.tar.gz

Download URL pipeit-0.3.4.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
28b1008f935788c1ad2e773450b0f3258cc7bac0caeda8926dd7538caba88437
BLAKE2b-256 checksum
How to use checksums
720ecdeec986a4228e3ae27fb42e46b333d98f1d987bf22fdef4d8e623597c38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18

Release files / pipeit-0.3.4-py3-none-any.whl

Download URL pipeit-0.3.4-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06be195c02f9abbe71e08a6ccba013cf275c74e739d09f4e9279257262535f55
BLAKE2b-256 checksum
How to use checksums
dcbe7139cb3f8f17a4587ed8b701c2ab6ebb89d24599aa7aa5f6052012592293
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18

Security for pipeit 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page