Capture C-level stdout/stderr in Python
Switch branches/tags
Nothing to show
Clone or download
Latest commit 088bb99 Dec 12, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.bumpversion.cfg Bump version: 1.0.2 → May 20, 2018
.gitignore gitignore pytest cache May 9, 2018
.travis.yml macos needs language: generic Dec 12, 2018
Demo.ipynb Make it an IPython extension Mar 14, 2016
LICENSE Initial commit Mar 8, 2016 packaging Mar 8, 2016 Link blogpost about redirecting stdout/stderr Jun 30, 2018
setup.cfg init package Mar 8, 2016 improvements Jul 13, 2018 sleep after flushing stdout Dec 12, 2018 poll timeout is in milliseconds Dec 12, 2018


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

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


pip install wurlitzer


Capture stdout/stderr in pipes:

from wurlitzer import pipes

with pipes() as (out, err):

stdout =

Capture stdout/stderr in StringIO:

from io import StringIO
from wurlitzer import pipes, STDOUT

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

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():

Or even simpler, enable it as an IPython extension:

%load_ext wurlitzer

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


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


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