{"id":15981303,"url":"https://github.com/greg-hellings/stream-redirect","last_synced_at":"2026-06-28T22:31:34.109Z","repository":{"id":137514083,"uuid":"239952574","full_name":"greg-hellings/stream-redirect","owner":"greg-hellings","description":null,"archived":false,"fork":false,"pushed_at":"2020-02-14T07:12:24.000Z","size":52,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-07T20:43:18.179Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greg-hellings.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-12T07:34:09.000Z","updated_at":"2023-04-26T15:25:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"f3b94031-cb27-439e-96c0-c61d67f59c55","html_url":"https://github.com/greg-hellings/stream-redirect","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/greg-hellings/stream-redirect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-hellings%2Fstream-redirect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-hellings%2Fstream-redirect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-hellings%2Fstream-redirect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-hellings%2Fstream-redirect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greg-hellings","download_url":"https://codeload.github.com/greg-hellings/stream-redirect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-hellings%2Fstream-redirect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34906700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T00:43:19.312Z","updated_at":"2026-06-28T22:31:34.097Z","avatar_url":"https://github.com/greg-hellings.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI Status](https://github.com/greg-hellings/stream-redirect/workflows/Check%20Push/PR/badge.svg)](https://github.com/greg-hellings/stream-redirect/actions)\n[![codecov](https://codecov.io/gh/greg-hellings/stream-redirect/branch/master/graph/badge.svg)](https://codecov.io/gh/greg-hellings/stream-redirect)\n[![PyPI version](https://badge.fury.io/py/stream-redirect.svg)](https://badge.fury.io/py/stream-redirect)\n\nstdout\\_redirect\n----------------\n\nWhat?\n-----\n\nA Python library to collect and redirect code from stdout (and/or stderr) and\ncollect it into program-accessible locations.\n\nTested and working on Linux, Mac OS, and Windows!\n\nHow?\n----\n\n`pip install -U stream-redirect`\n\n```python\nfrom stream_redirect import Redirect\n\nr = Redirect(stdout=True, stderr=True)\nwith r:\n    print(\"This will be captured\")\n    os.system(\"echo This will also be captured\")\n    some_c_module.method_that_writes(\"This willl be, too\")\n\nprint(\"Captured stdout: \", r.stdout)\nprint(\"Captured stderr: \", r.stderr)\n```\n\nConstruction\n============\n\nRedirect accepts three arguments:\n\n* `stdout` - Default **True**. Capture stdout to the \"stdout\" property\n* `stderr` - Default **False**. Capture stderr to the \"stderr\" property\n* `python_only` - Default **False**. Only capture the output of Python code and\n  not the output of system calls and C libraries. This behavior mimics the built\n  in context manager (discussed below) and is useful when you just want to drop\n  in this to replace that one in versions of Python where it doesn't exist\n\nUsage\n=====\n\nIf you only want to silence output you can do\n```python\nwith Redirect():\n   pass\n```\n\nHowever, if you wish to inspect the results of the run, you need to create and read\nthe context manager outside of the `with` invocation, as the object created during\nthe call is only accessible within the body of the `with` block.\n\nWhy?\n----\n\n# Isn't there already a standard module for this?\n\nIt's true that the standard library includes a context decorator that\n[already redirects stdout](https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout)\nfor most normal uses. But this is not sufficient. It fails on at least a few\nscenarios.\n\n### It is new\n\nThe built-in module won't help you on Python 2.7 or Python 3.0-3.3 (where it does\nnot exist).\n\nThis module will do so\n\n### It doesn't capture system calls\n\nThe above module doesn't capture system calls\n\n```\nIn [1]: import io, os, contextlib\n\nIn [2]: s = io.StringIO()\n\nIn [3]: with contextlib.redirect_stdout(s):\n   ...:     os.system(\"echo Hello world\")\n   ...:\nHello world\n\nIn [4]: print(\"Captured output: \", s.getvalue())\nCaptured output:\n```\n\nThis module will do so\n\n### It doesn't capture output from the C library\n\nIf an extension module written in C writes output, the built-in context wrapper\nwill not capture it.\n\nThis module will do so\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-hellings%2Fstream-redirect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreg-hellings%2Fstream-redirect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-hellings%2Fstream-redirect/lists"}