{"id":24227,"library":"pep562","title":"pep562","description":"Backport of PEP 562 (customizing module __getattr__ and __dir__) for Python 2.7, 3.5, and 3.6. Current version 1.1, last updated in 2019. Low release cadence.","status":"deprecated","version":"1.1","language":"python","source_language":"en","source_url":"https://github.com/facelessuser/pep562","tags":["pep562","backport","module","python2","deprecated"],"install":[{"cmd":"pip install pep562","lang":"bash","label":"pip install"}],"dependencies":[],"imports":[{"note":"PEP 562 is natively supported in Python 3.7+. This library is only needed for older versions.","symbol":"pep562","correct":"import pep562"}],"quickstart":{"code":"import sys\n\nif sys.version_info < (3, 7):\n    import pep562\n    pep562.patch_module(__name__)\n\n# Define module-level __getattr__ and __dir__\ndef __getattr__(name):\n    if name == 'missing':\n        return 'default'\n    raise AttributeError(f\"module {__name__!r} has no attribute {name!r}\")\n\ndef __dir__():\n    return ['existing']\n","lang":"python","description":"Patches the current module to support PEP 562 on Python < 3.7."},"warnings":[{"fix":"Remove dependency and conditional imports when targeting Python >= 3.7.","message":"PEP 562 is natively supported in Python 3.7+. This backport is only needed for Python <= 3.6.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure `import pep562; pep562.patch_module(__name__)` is executed early, preferably at the top of the module.","message":"The library must be imported and `patch_module` called before any other code that relies on __getattr__ or __dir__.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install pep562` and ensure the environment is activated.","cause":"The library is not installed.","error":"ImportError: No module named pep562"},{"fix":"Call `pep562.patch_module(__name__)` and define a top-level function named `__getattr__`.","cause":"`patch_module` was not called, or the function is not defined as a module-level __getattr__.","error":"AttributeError: module 'your_module' has no attribute '__getattr__'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}