readchar
Library to easily read single chars and key strokes
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 readcharuv
uv add readcharpoetry
poetry add readcharInstalling 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
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
python-yakhCaptures individual keypresses from terminal…
permissive · top 15,000 on PyPI
urwid-readlineAdds readline-style keyboard shortcuts to urwid…
permissive · top 15,000 on PyPI
pwinputDisplays mask characters (like asterisks) as…
permissive · top 15,000 on PyPI
pinyinConverts Chinese characters to pinyin…
permissive · top 15,000 on PyPI
UnidecodeConverts Unicode text to ASCII-safe…
copyleft · top 1,000 on PyPI
anyasciiConverts Unicode text to ASCII-only equivalents…
permissive · top 5,000 on PyPI
keyboardHook global keyboard events, register hotkeys,…
permissive · top 5,000 on PyPI
chardetDetects character encoding and language in byte…
permissive · top 1,000 on PyPI
streamlit-keyupAdds real-time text input to Streamlit apps…
unclear · top 15,000 on PyPI
graphemeProvides string manipulation functions that…
permissive · top 5,000 on PyPI