A subprocess replacement with tee support for both synchronous and asynchronous contexts.
Project description
tee-subprocess
A subprocess replacement with tee support for both synchronous and asynchronous contexts.
Usage
Just import the run
function and use it as you would use subprocess.run
.
from subprocess_tee import run
process = run(["python", "--version"], tee=True, text=True, capture_output=True)
# ==> Python 3.11.2
print(process.stdout)
# ==> Python 3.11.2
Changing stdout
and stderr
changes the location to which the tee
occurs. You can supply any of the defined options in subprocess
or asyncio.subprocess
(STDOUT
, DEVNULL
, etc), as well as a writable text or binary file object.
Async
Internally, subprocess_tee
utilizes asyncio
to concurrently output and capture the subprocess logs. If an event loop is already running, run
will return an awaitable coroutine. Otherwise, it will call asyncio.run
for you. Practically, this means you can just treat run
as a coroutine if you're in an async content; if you're not, just call it synchronously.
async def main():
process = await run(["python", "--version"], tee=True, text=True, capture_output=True)
# ==> Python 3.11.2
print(process.stdout)
# ==> Python 3.11.2
asyncio.run(main())
License
MIT License Copyright (c) 2023 Elias Gabriel
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tee_subprocess-1.0.0.tar.gz
.
File metadata
- Download URL: tee_subprocess-1.0.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.3 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f8c1fa13c50501c22255d4a1aa81340f5a0ec00ae4c60585e0a67e214dc7664 |
|
MD5 | 2d4d69a5942980f674f580416e140eb0 |
|
BLAKE2b-256 | d8ef7a730daa04ff38f691cb38cbb6e73e000c93748bb6a2041d63ce2d13a631 |
File details
Details for the file tee_subprocess-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: tee_subprocess-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.3 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 663a43e235bf0df6435f3f73aa5e47ec057b23fda14235c2607c33c599080b0c |
|
MD5 | 36b958be3607d1f033feb316aed51660 |
|
BLAKE2b-256 | adeedab34261ff555ed93d04d6c23fb9aed536cef36f6a7e79115ea856d25c61 |