
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
pytimedinput
Advanced tools
A tiny, simplistic little alternative to the standard Python input()-function allowing you to specify an optional timeout for the function.
pytimedinput should work on both Windows and Linux, though no exceedingly extensive testing has been done and there might be bugs.
.. code:: bash
$ pip3 install pytimedinput
timedInput() ............
timedInput() works similar to Python's default input() - function, asking user for a string of text, but timedInput() allows you to define an amount of time the user has to enter any text or how many consecutive seconds to wait for input, if the user goes idle.
.. code:: python
def timedInput(prompt="", timeout=5, resetOnInput=True, maxLength=0, allowCharacters="", endCharacters="\x1b\n\r")
The function timedInput() from pytimedinput accepts the following parameters:
The function returns a tuple of:
Example:
.. code:: python
from pytimedinput import timedInput
userText, timedOut = timedInput("Please, do enter something: ")
if(timedOut):
print("Timed out when waiting for input.")
print(f"User-input so far: '{userText}'")
else:
print(f"User-input: '{userText}'")
timedKey() .......... timedKey() waits for the user to press one of a set of predefined keys, with a timeout, while ignoring any keys not on the list.
.. code:: python
def timedKey(prompt="", timeout=5, resetOnInput=True, allowCharacters="")
The function timedKey() from pytimedinput accepts the following parameters:
The function returns a tuple of:
Example:
.. code:: python
from pytimedinput import timedKey
userText, timedOut = timedKey("Please, press 'y' to accept or 'n' to decline: ", allowCharacters="yn")
if(timedOut):
print("Timed out when waiting for input. Pester the user later.")
else:
if(userText == "y"):
print("User consented to selling their first-born child!")
else:
print("User unfortunately declined to sell their first-born child!")
Tip: use timedKey() for the infamous "Press any key to continue."-prompt!
.. code:: python
from pytimedinput import timedKey
timedKey("Press any key to continue.", timeout=-1)
timedInteger() and timedFloat() ............................... timedInteger() and timedFloat work like timedInput(), except they only allow the user to enter numbers, and comma or period in case of timedFloat. Can be used to enter a negative number.
.. code:: python
def timedInteger(prompt="", timeout=5, resetOnInput=True, allowNegative=True)
The function timedInteger() and timedFloat() from pytimedinput accept the following parameters:
The function returns a tuple of:
Example:
.. code:: python
from pytimedinput import *
userNumber, timedOut = timedFloat("Enter a floating-point value: ")
if(not timedOut):
if(userNumber == None):
print("We wanted a number, but got none.")
else:
print(f"We should do some fancy maths with {userNumber}!")
All the functions require an interactive shell to function and will raise a Runtimerror-exception otherwise, which will need to be caught in any script that will be used both interactively and non-interactively.
MIT
FAQs
Query a user for input with a timeout.
We found that pytimedinput demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.