MonkeyType
Generating type annotations from sampled production types
What it is and what it does
MonkeyType is a runtime type collection and annotation tool that hooks into Python's function call mechanism to observe the actual types flowing through your code, then uses that data to generate type annotations. It works by running your code under sys.setprofile instrumentation, recording argument and return types into a SQLite database, and then either outputting stub files or modifying your source code directly to add the inferred annotations.
The tool is designed as a first-pass annotation generator: it produces concrete type hints based on what it observes at runtime, which may be narrower than the full capability of your functions. For example, a function that works with any numeric type will be annotated with the specific type it saw during execution. The generated annotations are meant to be reviewed and refined by a developer, not used blindly.
Use it for:
- Quickly add type annotations to an existing untyped codebase by running your test suite or representative workload under MonkeyType
- Generate stub files for modules to enable static type checking without modifying the original source
- Bootstrap type safety in legacy Python code where manual annotation would be time-consuming
- Identify type inconsistencies by comparing inferred types across different execution paths or test cases
- Support Python 3.7+ codebases that need gradual typing adoption with minimal upfront effort
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
MonkeyType collects runtime types of function arguments and return values, then automatically generates type stub files or applies draft type annotations directly to your Python code.
Yes, if you need to add type annotations to existing untyped Python code and are willing to review and refine the generated hints. The tool is stable (Production/Stable status) and has low install friction, but the aging maintenance status means you should verify it works with your Python version and check for any open issues matching your use case before committing to it in a critical workflow.
Install
monkeytype on PyPI
pip
pip install monkeytypeuv
uv add monkeytypepoetry
poetry add monkeytypeInstalling MonkeyType
Before you install
Low install friction with only two runtime dependencies (mypy-extensions and libcst). Maintenance status is aging—last release was in March 2023—but the repository remains active and unarchived with 5000 stars.
License in practice
BSD license is permissive, allowing commercial and private use with minimal restrictions beyond attribution and liability disclaimers.
Quickstart
pip install MonkeyType
# Run your script under MonkeyType to collect types
monkeytype run myscript.py
# Generate stub file or apply annotations
monkeytype stub some.module
monkeytype apply some.module
Requires Python 3.7 or later. The tool modifies your source code in-place when using 'apply', so version control or backups are recommended before running it.
Verify before relying
- Whether the tool handles all Python language features equally well or has known gaps in type inference accuracy
- Performance impact when running production code under sys.setprofile instrumentation
- How well generated annotations handle polymorphic functions or complex generic types beyond the documented examples
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — mypy-extensions, libcst |
| Maintenance | aging — 1,243 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 356,424/month — #7,282 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: MonkeyType-23.3.0-py3-none-any.whl
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
autotypingAutomatically infers and adds type annotations…
permissive · top 15,000 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
typing-inspectProvides runtime inspection utilities for…
permissive · top 1,000 on PyPI
pytest-beartype-testsA pytest plugin that automatically applies…
permissive · top 15,000 on PyPI
sqlalchemy-stubsProvides type stubs and a mypy plugin to enable…
permissive · top 5,000 on PyPI
targGenerates a command-line interface from…
permissive · top 15,000 on PyPI
types-smorestProvides type stubs for flask-smorest, enabling…
copyleft · top 5,000 on PyPI
types-antlr4-python3-runtimeProvides type stubs for antlr4-python3-runtime,…
permissive · top 15,000 on PyPI
mozcrashExtracts and formats stack traces from minidump…
copyleft · top 15,000 on PyPI
homeassistant-stubsProvides PEP 484 type stubs for Home Assistant…
permissive · top 15,000 on PyPI