Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Easy stream redirection in Python.

Project description

Package Documentation

Description

This project provides Python context managers to help redirect multiple forms of output into a buffer (capturing the output).

Installation

$ pip install redirect-streams

Basic Usage

The most common use of this project is to redirect stdout.

from io import BytesIO, SEEK_SET, TextIOWrapper
from os import system
from sys import stdout

from redirect_streams import redirect_stdout

with TextIOWrapper(BytesIO(), stdout.encoding) as buffer:
    with redirect_stdout(buffer):
        print('this will be saved in the buffer')
        # code below won't work with stdlib's redirect_stdout
        system('this will be saved in the buffer')
    buffer.seek(SEEK_SET)
    saved = buffer.read()
print(saved)

For other context managers and more detailed information, please refer to the documentation.

Project details


Download files

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

Files for redirect-streams, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size redirect_streams-0.1.0-py2.py3-none-any.whl (4.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size redirect-streams-0.1.0.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View hashes
Filename, size redirect-streams-0.1.0.zip (6.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page