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-2.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

timedinput-2.0.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for timedinput-2.0.0.tar.gz
Algorithm Hash digest
SHA256 d61eaf08d48266f32bf75645f9b0ce6ea30a76bbdb119aea602875100402b2cc
MD5 505e008f3f754fa0a3a956c6cc325be0
BLAKE2b-256 336ae770d376a87dbbf14ee02c2c771c55804a914aef9ebfe35223278fbb0916

See more details on using hashes here.

Provenance

The following attestation bundles were made for timedinput-2.0.0.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-2.0.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for timedinput-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82123979328243a36e0e9d077078d7ec7123ac71ec915ff423daebaac80cf99a
MD5 acadd173b9c55947215c0f7f40c62734
BLAKE2b-256 738f043c779d8b57fa5291306b757a89266c567394929c7a4c1ee899a55e4115

See more details on using hashes here.

Provenance

The following attestation bundles were made for timedinput-2.0.0-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