Typing stubs for pynput

raw JSON →
1.8.1.20260408 verified Fri May 01 auth: no python

This package provides type annotations (stubs) for the `pynput` library, allowing type checkers like mypy and pyright to validate code that uses pynput. Current version is 1.8.1.20260408, compatible with Python >=3.10. It is part of the typeshed project and is updated regularly to match upstream pynput releases.

pip install types-pynput
error ModuleNotFoundError: No module named 'pynput'
cause Missing runtime dependency 'pynput'.
fix
pip install pynput
error AttributeError: module 'pynput' has no attribute 'keyboard'
cause Attempting to import 'pynput.keyboard' as a top-level module; correct usage is 'from pynput import keyboard'.
fix
Change import to 'from pynput import keyboard'
gotcha types-pynput only provides type hints; it must be installed alongside the runtime library pynput. Running code without pynput will raise ImportError.
fix Install both: pip install pynput types-pynput
deprecated In some older stubs, importing directly from 'pynput' may not include submodule types. Always import from the specific submodule (e.g., 'from pynput import keyboard') to get correct type inference.
fix Use explicit submodule imports: from pynput import keyboard, mouse

Quickstart showing a basic keyboard listener with type stubs active.

from pynput import keyboard

def on_press(key):
    try:
        print(f'Alphanumeric key pressed: {key.char}')
    except AttributeError:
        print(f'Special key pressed: {key}')

with keyboard.Listener(on_press=on_press) as listener:
    listener.join()