Skip to main content

Live Subprocess

Test CodeQL Code Coverage Maintainability Dependabot Python versions PyPI - Downloads X URL

Displays the stdout and stderr of the subprocess in real time.

Advantage

  • Displays subprocess stdout and stderr in real time as the process runs — not buffered until exit.
  • Uses a PTY (pseudo-terminal) on POSIX so the child process keeps line-buffering active, just as it would in a real terminal.
  • Cross-platform: PTY-based on POSIX, thread-backed pipe reader on Windows.
  • Zero runtime dependencies.
  • Async/await native; captures and returns the full output string for programmatic use.

Quickstart

Install:

pip install livesubprocess

Run a command with real-time output (POSIX):

import asyncio
from livesubprocess import LiveSubProcessFactory

async def main() -> None:
    pty = LiveSubProcessFactory.create_pty()
    stdout, returncode = await pty.run(["python", "-u", "script.py"])

asyncio.run(main())

Run a command with real-time output (POSIX and Windows):

import asyncio
import subprocess
from livesubprocess import LiveSubProcessFactory

async def main() -> None:
    proc = subprocess.Popen(
        ["python", "-u", "script.py"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    live = LiveSubProcessFactory.create_popen(proc)
    stdout, returncode = await live.wait()

asyncio.run(main())

PTY vs. Popen

PTY (create_pty) Popen (create_popen)
Platforms POSIX only POSIX and Windows
Process creation Managed by livesubprocess You create the Popen object
Line-buffering Yes — child sees a real TTY Depends on the child process
Use when Simplest API on POSIX Windows support needed, or you need to configure Popen directly (env, cwd, shell, etc.)

Both run() and wait() return (stdout_and_stderr: str, returncode: int).

How do I...

  • Wrap an existing subprocess.Popen? Use LiveSubProcessFactory.create_popen(). This works on both POSIX and Windows.

    import asyncio
    import subprocess
    from livesubprocess import LiveSubProcessFactory
    
    async def main() -> None:
        proc = subprocess.Popen(
            ["ffmpeg", "-i", "input.mp4", "output.mp4"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        live = LiveSubProcessFactory.create_popen(proc)
        stdout, returncode = await live.wait()
    
    asyncio.run(main())
    
  • Stop the reader early (before terminating the process)? Call live.stop() before popen.terminate() or popen.communicate() to deregister the fd readers cleanly.

Credits

This package was created with Cookiecutter and the yukihiko-shinoda/cookiecutter-pypackage project template.

Metadata

Release files for livesubprocess 0.2.0

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

Source distribution (sdist)

Source distribution for livesubprocess 0.2.0
File Size Uploaded Provenance Actions
livesubprocess-0.2.0.tar.gz 17.5 kB Without provenance Details for livesubprocess-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 32.2 kB

Release files / livesubprocess-0.2.0.tar.gz

Download URL livesubprocess-0.2.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
29b11446f0fe19e0e81831e276d2b9492d0f1ffe4a6a8862f88919dfd4be1396
BLAKE2b-256 checksum
How to use checksums
4a1de9c529a24af43250a9f4cd0cce48c39bf4b28d54c6c65a19d33d219adc0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / livesubprocess-0.2.0-py3-none-any.whl

Download URL livesubprocess-0.2.0-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a495e8961cf53d09565970e5da17d9a4bdfb248e010a2f0df6d44ba340b5f935
BLAKE2b-256 checksum
How to use checksums
4ee65e6049a96558457d983ca8843786880bbdc3d97752a3c1ee4e3e0eccb39b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for livesubprocess 0.2.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files 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