Python asyncio streams: high-level network readers and writers
Answer: asyncio streams are high-level async/await primitives for sending and receiving data on network connections.
Opening a connection
These stream helpers avoid callbacks and also avoid low-level protocols and transports.
The TCP echo client example awaits asyncio.open_connection to get a reader and writer.
The default reader buffer cap is 64 KiB.
The rest of the arguments are passed directly to loop.create_connection.
Serving and Unix sockets
start_server invokes a callback whenever a new client connection is established.
The rest of the arguments are passed directly to loop.create_server.
A related function operates on Unix sockets.
To close the socket, call the writer's close method.
See also
Claims
- id: C1 claim: Streams work without callbacks or low-level protocols and transports. source: S1 evidence: "without using callbacks or low-level protocols and transports"
- id: C2 claim: The default stream buffer limit is 64 KiB. source: S1 evidence: "By default the limit is set to 64 KiB."
- id: C3 claim: open_connection passes remaining arguments to loop.create_connection. source: S1 evidence: "passed directly to loop.create_connection()"
- id: C4 claim: A Unix-socket helper similar to open_connection is provided. source: S2 evidence: "but operates on Unix sockets"
Sources
- [S1] Streams. Python Software Foundation. https://docs.python.org/3/library/asyncio-stream.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] Streams documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/asyncio-stream.rst . License: PSF License Version 2. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, Streams; CPython, Streams documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, Streams; CPython, Streams documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python asyncio streams: high-level network readers and writers." iinventedlight Library, iil:note:qq9bhf85, version of 2026-11-26. https://iinventedlight.com/library/notes/python-asyncio-streams/. License: CC-BY-4.0.
@misc{iil_note_qq9bhf85,
author = {{iinventedlight}},
title = {{Python asyncio streams: high-level network readers and writers}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/python-asyncio-streams/},
note = {Permanent ID iil:note:qq9bhf85. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-asyncio-streams.schema.json (schema; CC-BY-4.0)
- python-asyncio-streams.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-asyncio-streams.md.