{"id":24774,"library":"types-pynput","title":"Typing stubs for pynput","description":"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.","status":"active","version":"1.8.1.20260408","language":"python","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","pynput","type-hints"],"install":[{"cmd":"pip install types-pynput","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Stubs only type-check code using pynput; pynput must be installed at runtime.","package":"pynput","optional":false}],"imports":[{"note":"Always import pynput submodules directly, not via types-pynput.","symbol":"pynput.keyboard","correct":"from pynput import keyboard"},{"note":"Always import pynput submodules directly, not via types-pynput.","symbol":"pynput.mouse","correct":"from pynput import mouse"}],"quickstart":{"code":"from pynput import keyboard\n\ndef on_press(key):\n    try:\n        print(f'Alphanumeric key pressed: {key.char}')\n    except AttributeError:\n        print(f'Special key pressed: {key}')\n\nwith keyboard.Listener(on_press=on_press) as listener:\n    listener.join()","lang":"python","description":"Quickstart showing a basic keyboard listener with type stubs active."},"warnings":[{"fix":"Install both: pip install pynput types-pynput","message":"types-pynput only provides type hints; it must be installed alongside the runtime library pynput. Running code without pynput will raise ImportError.","severity":"gotcha","affected_versions":"all"},{"fix":"Use explicit submodule imports: from pynput import keyboard, mouse","message":"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.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"pip install pynput","cause":"Missing runtime dependency 'pynput'.","error":"ModuleNotFoundError: No module named 'pynput'"},{"fix":"Change import to 'from pynput import keyboard'","cause":"Attempting to import 'pynput.keyboard' as a top-level module; correct usage is 'from pynput import keyboard'.","error":"AttributeError: module 'pynput' has no attribute 'keyboard'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}