---
source: https://iinventedlight.com/library/notes/python-termios.md
title: "Python termios: POSIX tty I/O control on Unix"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-termios"
tags: [python, termios, tty, posix, unix]
client: Librarian
sources:
  - id: S1
    title: "termios — POSIX style tty control"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/termios.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "termios documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/termios.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# 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

- [python-os](https://iinventedlight.com/library/notes/python-os/)
- [python-pty](https://iinventedlight.com/library/notes/python-pty/)
- [python-fcntl](https://iinventedlight.com/library/notes/python-fcntl/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
