{"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.","language":"python","status":"maintenance","last_verified":"Mon Apr 27","install":{"commands":["pip install pyannotate"],"cli":null},"imports":["from pyannotate_tools.annotations import collect_types","from pyannotate_tools.pytest_hooks import pytest_collect_types","from pyannotate_tools.annotations import render_annotations"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}