{"id":21728,"library":"pyannotate","title":"PyAnnotate","description":"PyAnnotate is a tool by Dropbox that auto-generates PEP-484 type annotations for Python code based on runtime type information collected via a pytest plugin or direct calls. Version 1.2.0 is the latest. It has no active development releases since 2019, making it effectively in maintenance mode.","status":"maintenance","version":"1.2.0","language":"python","source_language":"en","source_url":"https://github.com/dropbox/pyannotate","tags":["type-annotations","pep-484","static-analysis","dropbox"],"install":[{"cmd":"pip install pyannotate","lang":"bash","label":"Latest from PyPI"}],"dependencies":[{"reason":"Required for the pytest plugin to collect type info during test runs.","package":"pytest","optional":false},{"reason":"Required for Python 2/3 compatibility.","package":"six","optional":false}],"imports":[{"note":"Most online examples use the wrong import; the correct module is pyannotate_tools.annotations.","wrong":"from pyannotate import collect_types","symbol":"collect_types","correct":"from pyannotate_tools.annotations import collect_types"},{"note":"This is the pytest plugin entry point. No common wrong import.","wrong":"","symbol":"pytest_collect_types","correct":"from pyannotate_tools.pytest_hooks import pytest_collect_types"},{"note":"Same as collect_types; the correct package is pyannotate_tools.","wrong":"from pyannotate import render_annotations","symbol":"render_annotations","correct":"from pyannotate_tools.annotations import render_annotations"}],"quickstart":{"code":"# 1. Collect type information during tests with pytest\n# Add to conftest.py:\n# from pyannotate_tools.pytest_hooks import pytest_collect_types\n# def pytest_configure(config):\n#     config.pluginmanager.register(pytest_collect_types())\n\n# 2. Run tests: pytest --annotations-output annotate.json\n# 3. Generate annotations in your source files:\nimport json\nfrom pyannotate_tools.annotations import render_annotations\n\nwith open('annotate.json') as f:\n    annotations = json.load(f)\n\n# 'code' is the path to your Python file\ncode = '/path/to/your/module.py'\nwith open(code) as f:\n    source = f.read()\n\ntry:\n    annotated = render_annotations(source, annotations, path=code)\n    if annotated != source:\n        with open(code, 'w') as f:\n            f.write(annotated)\n        print(\"Annotations applied to\", code)\n    else:\n        print(\"No annotations to apply\")\nexcept Exception as e:\n    print(\"Error:\", e)","lang":"python","description":"This quickstart demonstrates collecting type data via pytest and then applying annotations to a Python file using pyannotate's tools."},"warnings":[{"fix":"Use 'from pyannotate_tools.annotations import collect_types' instead of 'from pyannotate import collect_types'.","message":"The correct import path is 'pyannotate_tools.annotations', not 'pyannotate'. Many outdated tutorials use the wrong module.","severity":"gotcha","affected_versions":"all"},{"fix":"Use Python 3.8 or lower for collection. For analysis, you can run it on older Python and apply annotations to newer code.","message":"PyAnnotate only works with Python 2.7 and 3.6-3.8. It does not support Python 3.9+ or the latest Python versions due to reliance on removed APIs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure you regenerate annotation files with the same version of pyannotate used to apply them.","message":"The annotation output format changed between versions. JSON files from older versions may not parse correctly with newer render_annotations.","severity":"breaking","affected_versions":"<1.2.0 -> 1.2.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'pip install pyannotate' and use the correct import: 'from pyannotate_tools.annotations import collect_types'.","cause":"PyAnnotate is not installed, or you are importing the wrong module name.","error":"ModuleNotFoundError: No module named 'pyannotate_tools'"},{"fix":"Upgrade to pyannotate >=1.2.0: 'pip install --upgrade pyannotate'.","cause":"Older versions of pyannotate did not expose render_annotations publicly.","error":"AttributeError: module 'pyannotate_tools.annotations' has no attribute 'render_annotations'"},{"fix":"Use Python 3.8 or older, or run collection in a separate environment and apply annotations manually.","cause":"PyAnnotate does not support newer Python versions.","error":"RuntimeError: This package requires Python 3.6 - 3.8"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}