Skip to main content

Capture C-level output in context managers

Project description

Wurlitzer

Capture C-level stdout/stderr pipes in Python via os.dup2.

For more details on why this is needed, please read this blog post.

Install

pip install wurlitzer

Usage

Capture stdout/stderr in pipes:

from wurlitzer import pipes

with pipes() as (out, err):
    call_some_c_function()

stdout = out.read()

Capture stdout/stderr in StringIO:

from io import StringIO
from wurlitzer import pipes, STDOUT

out = StringIO()
with pipes(stdout=out, stderr=STDOUT):
    call_some_c_function()

stdout = out.getvalue()

Forward C-level stdout/stderr to Python sys.stdout/stderr, which may already be forwarded somewhere by the environment, e.g. IPython:

from wurlitzer import sys_pipes

with sys_pipes():
    call_some_c_function()

Or even simpler, enable it as an IPython extension:

%load_ext wurlitzer

To forward all C-level output to IPython during execution.

Acknowledgments

This package is based on stuff we learned with @takluyver and @karies while working on capturing output from the Cling Kernel for Jupyter.

Wurlitzer?!

Wurlitzer makes pipe organs. Get it? Pipes? Naming is hard.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wurlitzer-2.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

wurlitzer-2.1.1-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wurlitzer-2.1.1.tar.gz.

File metadata

  • Download URL: wurlitzer-2.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for wurlitzer-2.1.1.tar.gz
Algorithm Hash digest
SHA256 5a3ea5a13a8aac2d808864087fec87a0518bf7d9776173ab06a6bb4ade9f4d27
MD5 3f05b838bc5fe5ccb7f00b907a1841e3
BLAKE2b-256 9648a38a9d731c879ac04d6dac24dc802a9f0eb6a8de1c82b948eacee7c36bea

See more details on using hashes here.

File details

Details for the file wurlitzer-2.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: wurlitzer-2.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for wurlitzer-2.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dc778692e3017346f8c88a8f8d399fb3fee270a46d130c9a1a783641f271833d
MD5 4facb20c2bc8196612fad252fabfe76f
BLAKE2b-256 c09a846f5bdb7389815a04886a423df3277547b7117596c577346320c07257b6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page