Registry / type-stubs / pyannotate

pyannotate

JSON →
library1.2.0pypypi✓ verified 85d ago

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.

pip install pyannotate
INSTALL
IMPORT
SIG · PYANNOTATE
P
pyannotate
type-stubspythonv1.2.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

collect_types
from pyannotate_runtime import collect_types
from pyannotate_tools.annotations import collect_types

This quickstart demonstrates collecting type data via pytest and then applying annotations to a Python file using pyannotate's tools.

# 1. Collect type information during tests with pytest # Add to conftest.py: # from pyannotate_tools.pytest_hooks import pytest_collect_types # def pytest_configure(config): # config.pluginmanager.register(pytest_collect_types()) # 2. Run tests: pytest --annotations-output annotate.json # 3. Generate annotations in your source files: import json from pyannotate_tools.annotations import render_annotations with open('annotate.json') as f: annotations = json.load(f) # 'code' is the path to your Python file code = '/path/to/your/module.py' with open(code) as f: source = f.read() try: annotated = render_annotations(source, annotations, path=code) if annotated != source: with open(code, 'w') as f: f.write(annotated) print("Annotations applied to", code) else: print("No annotations to apply") except Exception as e: print("Error:", e)
Debug
Known issues
gotchaThe correct import path is 'pyannotate_tools.annotations', not 'pyannotate'. Many outdated tutorials use the wrong module.
fix
Use 'from pyannotate_tools.annotations import collect_types' instead of 'from pyannotate import collect_types'.
affects: all
gotchaPyAnnotate 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.
fix
Use Python 3.8 or lower for collection. For analysis, you can run it on older Python and apply annotations to newer code.
affects: >=1.0.0
breakingThe annotation output format changed between versions. JSON files from older versions may not parse correctly with newer render_annotations.
fix
Ensure you regenerate annotation files with the same version of pyannotate used to apply them.
affects: <1.2.0 -> 1.2.0
Upgrade
Version history
1.2.0latest on PyPI · released Sep 16, 2019
Audit
Dependencies
pytestrequiredRequired for the pytest plugin to collect type info during test runs.
sixrequiredRequired for Python 2/3 compatibility.
Agent activity
37 hits · last 30 days
node
34
OpenAI (training)
1
Resources
pyannotate — pip install pyannotate · libregistry