Skip to main content

term

An enhanced version of the tty module

Overview

The term package is an enhanced version of the standard library’s tty module. It provides context managers for opening a terminal stream, and for temporarily switching the terminal to raw or cbreak mode.

Package Contents

Terminal Control

setraw(fd, when=TCSAFLUSH, min=1, time=0)

Put the terminal in raw mode.

setcbreak(fd, when=TCSAFLUSH, min=1, time=0)

Put the terminal in cbreak mode.

rawmode(fd, when=TCSAFLUSH, min=1, time=0)

Context manager to put the terminal in raw mode.

cbreakmode(fd, when=TCSAFLUSH, min=1, time=0)

Context manager to put the terminal in cbreak mode.

Terminal I/O

opentty(bufsize=-1, mode=’r+b’)

Context manager returning a new rw stream connected to /dev/tty. The stream is None if the device cannot be opened.

readto(stream, endswith):

Read bytes or characters from stream until buffer.endswith(endswith) is true.

High-level Functions

getyx()

Return the cursor position as 1-based (line, col) tuple. Line and col are 0 if the device cannot be opened or the terminal does not support DSR 6.

getfgcolor()

Return the terminal foregound color as (r, g, b) tuple. All values are -1 if the device cannot be opened or does not supports OSC 10.

getbgcolor()

Return the terminal background color as (r, g, b) tuple. All values are -1 if the device cannot be opened or does not supports OSC 11.

islightmode()

Return true if the background color is lighter than the foreground color. May return None if the terminal does not support OSC color queries.

isdarkmode()

Return true if the background color is darker than the foreground color. May return None if the terminal does not support OSC color queries.

Documentation

Please see the API Documentation for more.

Changelog

3.0 - 2026-07-07

  • Remove deprecated license classifier. [stefan]

  • Upgrade .readthedocs.yaml. [stefan]

  • Upgrade sphinx and sphinx-rtd-theme in docs extra. [stefan]

  • Require Python >= 3.5. [stefan]

2.5 - 2023-09-14

  • Update tox.ini for latest tox. [stefan]

  • Add .readthedocs.yaml file. [stefan]

  • Pin sphinx and sphinx-rtd-theme versions in docs extra. [stefan]

  • Add pylint extra which installs pylint. [stefan]

  • Update .pylintrc for latest pylint. [stefan]

2.4 - 2022-03-07

  • Add Python 3.8-3.10 to tox.ini. Remove old Python versions. [stefan]

  • Replace deprecated python setup.py test in tox.ini. [stefan]

  • Remove deprecated test_suite from setup.py. [stefan]

  • Move metadata to setup.cfg and add a pyproject.toml file. [stefan]

  • Include tests in sdist but not in wheel. [stefan]

  • Fix escape sequence warning in byte string literal. [stefan]

  • Open /dev/tty in binary mode under both Python 2 and 3. [stefan]

  • Officially change opentty’s bufsize argument default from 1 to -1. Under Python 3, 1 has effectively meant -1 all along but Python 3.8 now issues a warning. [stefan]

  • Add readto, getfgcolor, getbgcolor, islightmode, and isdarkmode. [stefan]

2.3 - 2019-02-08

  • Add MANIFEST.in. [stefan]

  • Release as wheel. [stefan]

  • Drop explicit GPL because the PSF license is GPL-compatible anyway. [stefan]

2.2 - 2017-02-05

  • Support Python 2.6-3.6 without 2to3. [stefan]

2.1 - 2014-04-19

  • Remove setuptools from install_requires because it isn’t. [stefan]

2.0 - 2012-04-27

  • Open /dev/tty in binary mode under Python 3. [stefan]

  • Disable buffering if the device is not seekable. [stefan]

  • Remove getmaxyx since it cannot be implemented reliably. [stefan]

  • Support Python 2.5. [stefan]

  • Change license to GPL or PSF to avoid relicensing of PSF code. [stefan]

1.0 - 2012-04-11

  • Initial release. [stefan]

Metadata

Release files for term 3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for term 3.0
File Size Uploaded Provenance Actions
term-3.0.tar.gz 16.7 kB Without provenance Details for term-3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for term 3.0
File Interpreter ABI Platform Actions
term-3.0-py3-none-any.whl Python 3 none any Details for term-3.0-py3-none-any.whl

Total release size: 24.1 kB

Release files / term-3.0.tar.gz

Download URL term-3.0.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a6a81535e68fd98d25b1e2a1dff15400c5678e7f942e2d5bb5bde56784534d98
BLAKE2b-256 checksum
How to use checksums
dc778b246b695feaa9286049fb0d1567f8be73f77cec87f46d2031a512e790a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Release files / term-3.0-py3-none-any.whl

Download URL term-3.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0b8f8a9edba20f56c7c5b8cc87e43f0822fb7420efc5984fd7667617c22e037
BLAKE2b-256 checksum
How to use checksums
f4a1baa906ed243fb4a55d6992c8d53d0a42d7cd0f8780a9728803aedb6a13e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Security for term 3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page