Jllobvemy's answer to this question might be what you're looking for if you're not looking to understand exactly how it works. It uses a simple, easy-to-understand module.
There are more complicated solutions as well, but those might help you understand the complexity of setting a timeout on an input in Python. For example, using threads to count how much time has passed can be tricky and easily done wrong.
I also found another simple module named pytimedinput that could be of use in your case. I didn't test it myself, but I thought I'd put it here anyway so you can choose what suits you best. Beware though, as pytimedinput only works in a console, not in IDEs apparently.
An example for pytimedinput:
from pytimedinput import timedInput
userText, timedOut = timedInput("Please, do enter something: ", resetOnInput=False)
#resetOnInput defaults to True, which resets the timer on each keypress. This is probably not what you're looking for.
if(timedOut):
print("Timed out when waiting for input.")
print(f"User-input so far: '{userText}'")
else: print(f"User-input: '{userText}'")
input()