Python termios: POSIX tty I/O control on Unix
Answer: The termios module provides an interface to the POSIX calls for tty I/O control on Unix systems that support that style of control.
The interface
The module is available on Unix, and only on versions that support POSIX termios style tty I/O control configured during installation.
For a complete description of the calls, see the termios(3) Unix manual page.
Every function takes a file descriptor fd as its first argument.
That argument can be an integer file descriptor, such as the result of sys.stdin.fileno(), or a file object such as sys.stdin itself.
The module also defines the constants needed to work with those functions, using the same names as their counterparts in C.
Getting and setting attributes
tcgetattr returns a list of tty attributes for the file descriptor, including iflag, oflag, cflag, lflag, ispeed, and ospeed.
From a list like the one tcgetattr() returns, tcsetattr sets the tty attributes.
The when argument determines when the attributes are changed. TCSANOW changes attributes immediately.
See also
Claims
- id: C1 claim: The module provides POSIX tty I/O control. source: S1 evidence: "This module provides an interface to the POSIX calls for tty I/O control."
- id: C2 claim: Availability is Unix only. source: S1 evidence: "Availability : Unix."
- id: C3 claim: tcsetattr changes tty attributes on a file descriptor. source: S2 evidence: "Set the tty attributes for file descriptor"
Sources
- [S1] termios — POSIX style tty control. Python Software Foundation. https://docs.python.org/3/library/termios.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] termios documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/termios.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, termios — POSIX style tty control; CPython, termios 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, termios — POSIX style tty control; CPython, termios documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python termios: POSIX tty I/O control on Unix." iinventedlight Library, iil:note:q82ra9pe, version of 2026-11-26. https://iinventedlight.com/library/notes/python-termios/. License: CC-BY-4.0.
@misc{iil_note_q82ra9pe,
author = {{iinventedlight}},
title = {{Python termios: POSIX tty I/O control on Unix}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/python-termios/},
note = {Permanent ID iil:note:q82ra9pe. 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-termios.schema.json (schema; CC-BY-4.0)
- python-termios.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-termios.md.