← All notes

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

Sources

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

Permanent ID: iil:note:q82ra9pe

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.},
}

Markdown

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.

All artifact files (JSON index)

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.