skillfed

readchar

Library to easily read single chars and key strokes

readchar v4.2.2 15.8M downloads/30d#1,172 on PyPI180
Permissive license MIT Licence Copyright (c) 2022 Miguel Angel Garcia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),… (full text in the JSON record) Active released

What it is and what it does

readchar is a lightweight library for capturing keyboard input at the character and keystroke level in terminal applications. It abstracts away platform differences so you can read single keys, arrow keys, function keys, and modifier combinations (CTRL, ALT) in a portable way across Windows, Linux, and Unix. The library exposes two main functions: readchar() for single characters and readkey() for full keystrokes, plus a key module with named constants for special keys and a config class to customize interrupt behavior.

Typically used in interactive CLI tools, terminal UIs, and menu-driven applications where you need to respond to individual keypresses rather than waiting for a full line of input. It handles the low-level platform differences—Windows console APIs vs. Unix termios—so your code stays simple and portable.

Use it for:

  • Build interactive CLI menus that respond to arrow keys and Enter without waiting for line input
  • Implement terminal-based games or interactive tools that need real-time keystroke detection
  • Create command-line interfaces that handle function keys (F1–F12) for help or actions
  • Capture CTRL and ALT key combinations in terminal applications for custom shortcuts
  • Develop cross-platform terminal UIs that work identically on Windows and Linux

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Reads single characters and keystrokes from stdin, handling both ASCII characters and multi-character keys like arrows, function keys, and modifier combinations across Windows, Linux, and Unix systems.

Yes. readchar is stable, actively maintained, has zero dependencies, and solves a genuine problem for terminal applications. The MIT license is permissive, and the library's narrow scope and small footprint make it a low-risk addition. Install it if you need to handle raw keyboard input in a CLI or terminal UI.

Install

readchar on PyPI

pip

pip install readchar

uv

uv add readchar

poetry

poetry add readchar

Installing readchar

Before you install

Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-04-06 with a stable release cadence.

License in practice

MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.

Quickstart

pip install readchar

import readchar
from readchar import readkey, key

while True:
    k = readkey()
    if k == key.DOWN:
        print("Down arrow pressed")
    elif k == key.ENTER:
        break

Requires a terminal that supports raw input mode; behavior is undefined when stdin is piped or redirected from a non-interactive source.

Verify before relying

  • Whether readkey() correctly handles all modifier combinations (CTRL+ALT) on all supported platforms
  • Performance characteristics when reading from pipes or redirected input vs. interactive terminals
  • Behavior on Android and FreeBSD/OpenBSD (listed as enabled but not actively tested)

Package facts

License MIT Licence Copyright (c) 2022 Miguel Angel Garcia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 130 days since the last release
Last repo commit
First released
Downloads 15,794,533/month — #1,172 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: readchar-4.2.2-py3-none-any.whl

Keywords: characters, keystrokes, stdin, command line

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: Software DevelopmentTopic :: Software Development :: User Interfaces

Tags

read keyboard input from stdinsingle character keystroke readercross-platform terminal inputarrow key detectioncommand line key handlingraw stdin character capturefunction key recognition
terminal-inputcross-platformcli-tools

More Software Development packages