Skip to main content

Timeout for python inputs

Project description

timedinput

PyPI version Python versions Tests License

A Python module that waits for a specified amount of time for user input. If no input is received within the given timeout period, the module returns a default value or raises an exception.

Unlike standard timeout modules, timedinput actively monitors keystrokes and fully supports modern interactive environments like Jupyter Notebooks, Google Colab, and VS Code.

Installation

Standard installation for standard terminals (Windows/macOS/Linux):

pip install timedinput

For Jupyter/Colab Support: To enable timeout functionality inside Jupyter environments, install the optional UI dependencies:

pip install timedinput[jupyter]

(If you use timedinput in Jupyter without these dependencies, it will gracefully fall back to a standard, non-timing input() prompt to prevent crashes).

Usage

The timedinput function takes three optional arguments: prompt, timeout, and default.

from timedinput import timedinput

# Prompt the user for input with a timeout of 10 seconds
user_input = timedinput("Enter something: ", timeout=10)

# Prompt the user for input with a timeout of 5 seconds and a default value
user_input = timedinput("Enter something: ", timeout=5, default="default")

If the user enters input within the specified timeout, the function returns the user's input as a string. If the user does not enter input within the specified timeout, the function returns the default value (if one was provided) or raises a TimeoutOccurred exception.

Compatibility

  • Terminals: Works perfectly on all standard terminals across Windows and Unix-like operating systems.
  • Interactive: Fully compatible with JupyterLab, Classic Notebook, Google Colab, and VS Code Interactive windows.

License

Released under the MIT License. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timedinput-1.0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timedinput-1.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file timedinput-1.0.1.tar.gz.

File metadata

  • Download URL: timedinput-1.0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for timedinput-1.0.1.tar.gz
Algorithm Hash digest
SHA256 139075d0a78ed6d8d0a81c4f816051da81366626757a48b28e1ccdf3d0a34391
MD5 205b6ba853c76ac4db0e0d013b732a33
BLAKE2b-256 620238e0f6c7644ff01a0687135eff18a4c43e8a0751eaf026b06ab66fd49fe9

See more details on using hashes here.

Provenance

The following attestation bundles were made for timedinput-1.0.1.tar.gz:

Publisher: python-publish.yml on kerollosy/timedinput

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file timedinput-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: timedinput-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for timedinput-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8f23b866cc5166e45ab55b4a8b7bd53b09217d58a22779cfdd7c9183b4afd20
MD5 407fc11a59bf28ada53131377f7262d7
BLAKE2b-256 c97379fd3ab1015d9931e6e27f89a313447ce7ed587699ba8bf816a70005a089

See more details on using hashes here.

Provenance

The following attestation bundles were made for timedinput-1.0.1-py3-none-any.whl:

Publisher: python-publish.yml on kerollosy/timedinput

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page