readkeys
Python library to read from stdin a single char, keypress (with escape sequences) or line.
Originally a fork of magmax/python-readchar, it was rewritten to fix some bugs and better support UNIX and Windows systems.
Usage
import readkeys
ch = readkeys.getch() # get a single character
key = readkeys.getkey() # get a single keypress
line = readkeys.getline() # get a line of text
line2 = readkeys.getline(raw=False) # Get a line of text and print out characters as they are typed, similar to built-in input.
flush = readkeys.flush() # flush stdin
Functions
getch
The getch function reads a single character byte from stdin. The buffer is not flushed after read.
The function has the following type signature:
getch(NONBLOCK: bool = False, encoding: str = None, raw: bool = True) -> str
NONBLOCK: booluse non-blocking mode when reading from stdin, defaults to False. The library may encounter unforeseen errors if set toTrue.encoding: strspecify an encoding (e.g. utf-8) to be used to decode bytes from the stdin buffer. If unspecified it assumes characters can be directly extracted from stdin.raw: boolput tty terminal in raw mode before reading, see tty.setraw. If set toFalsethe characters will still appear in the terminal as they are typed. Settings before changing to raw mode are saved and restored when the read operation is complete.
The option is ignored on Windows systems as they use a completely different terminal environment and a different library is necessary to read character from stdin:msvcrt.
getkey
The getkey function reads a single keypress from stdin, including escape sequences of function keys. For example arrow keys are returned with their full escape sequence, without leaving anything in the buffer (0x1b5b41, 0x1b5b42, 0x1b5b43 or 0x1b5b44).
The function has the following type signature:
getch(getch_fn: Callable[[], str] = None, encoding: str = "", raw: bool = True) -> str
getch_fn: Callable[[], str]if passed, use the this function instead of the built-ingetchto read the single bytes from stdin. The library may encounter unforeseen errors if this option is used.encoding: strspecify an encoding (e.g. utf-8) to be used to decode bytes from the stdin buffer. Seegetch.raw: boolput tty terminal in raw mode before reading. Seegetch.
getline
The getline function reads a full line of characters from stdin, including non-standard keys (e.g. arrow keys). It defaults to raw mode, leaving characters unprinted on screen.
The function has the following type signature:
(getch_fn: Optional[Callable[[], str]] = None, encoding: str = None, raw: bool = True) -> str
getch_fn: Callable[[], str]if passed, use the this function instead of the built-ingetchto read the single bytes from stdin. The library may encounter unforeseen errors if this option is used.encoding: strspecify an encoding (e.g. utf-8) to be used to decode bytes from the stdin buffer. Seegetch.raw: boolput tty terminal in raw mode before reading. Seegetch.
flush
The flush function removes any leftover byte from stdin and returns them as a string. It is useful to clear the buffer from any remaining bytes after doing a single read with getch.
The function has the following type signature:
flush() -> str
Metadata
Release files for readkeys 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| readkeys-1.0.2.tar.gz | 8.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| readkeys-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / readkeys-1.0.2.tar.gz
| Download URL | readkeys-1.0.2.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ea2a6a7e2993a454d53c90fbdcd7d526d12ade30c23049c1dc7398d1d7b32de
|
|
BLAKE2b-256 checksum How to use checksums |
38bfd16f025af693b48848004a3bd582c912d6937b481204cbaccbeda54ba47c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.5 Darwin/19.5.0
|
Release files / readkeys-1.0.2-py3-none-any.whl
| Download URL | readkeys-1.0.2-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b113c4f0726df495ace2b031f174c17b77c576f014c347bb6d92d87d4f6a298
|
|
BLAKE2b-256 checksum How to use checksums |
22420be0768148dbc7d3f36d19e419edc3abd93ea05037b1debed50dfb880a4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.5 Darwin/19.5.0
|
Security for readkeys 1.0.2
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.