Skip to main content

asyncpipe

This is a little module to help you chain together subprocess pipelines, a bit more nicely than python natively lets you. The key element here is the support for asyncio.

OS Compatibility

This will only work on versions of python that support async/await syntax I've only tested this on Linux. I don't see any reason why it wouldn't work on OSX/BSD, but it's possible. I doubt this works on Windows at all.

Python compatibility

This requires 'async' and 'await' keywords, so Python 3.5+ only.

Motivation

When you use a PIPE for stdout in the native asyncio.subprocess module, you don't get back a value that can be passed to another Popen like you do in the subprocess module. Instead you get a wrapper. Sometimes you can resolve that by just using the 'shell' execution model, but sometimes that's not a great fit.

The solution is to do an error-prone set of operations with os.pipe and linking up various subprocesses stdin/stdout. This gets especially ugly when you've got a chain of 3+ shell commands.

Use

Synchronous

The synchronous form is pretty straightforward:

import asyncpipe
pipe = asyncpipe.PipeBuilder('ls')
# you can chain it
pipe.chain('grep', '^S')
# or use the 'or' operator
pipe | 'wc -l'
results = pipe.call()
matches = int(results[-1].stdout.strip())

All of those return the underlying object, and the starting arguments are optional, so this is equivalent:

import asyncpipe
pipe = asyncpipe.PipeBuilder().chain('ls') | 'grep ^s' | ['wc' '-l']
results = pipe.call()
matches = int(results[-1].stdout.strip())

Asyncronous

Async code is similar, except you need to pass the event loop as the 'loop' value to the PipeBuilder, or set it any time before calling call_async():

import asyncpipe
import asyncio
loop = asyncio.new_event_loop()
# if you don't do this, you will get errors from asyncio 
asyncio.set_event_loop(loop)
pipe = asyncpipe.PipeBuilder(loop=loop)
pipe.chain('ls') | 'grep ^s' | ['wc' '-l']
results = loop.run_until_complete(pipe.call_async())
matches = int(results[-1].stdout.strip())

If you were doing more in your event loop, you would of course just await pipe.call_async()!

Metadata

Release files for asyncpipe 0.0.1

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

Built distribution (wheel)

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

Release files / asyncpipe-0.0.1-py3-none-any.whl

Download URL asyncpipe-0.0.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae5a3fd1b644cc05c84447d91a80687ff177cafece31de1749246927602a44c7
BLAKE2b-256 checksum
How to use checksums
55cfb4311680fe02eaf79caa02b58bc0254169e9761c146148bc1cbbe84f4eae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

Security for asyncpipe 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

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