skillfed

MonkeyType

Generating type annotations from sampled production types

monkeytype v23.3.0 356.4K downloads/30d#7,282 on PyPI5,000
Permissive license BSD AGING released

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 monkeytype

uv

uv add monkeytype

poetry

poetry add monkeytype

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

runtime type inferenceautomatic type annotationstype stub generationpython type annotation toolinfer types from executiongenerate type stubsadd type hints automatically
type-checkingcode-generationstatic-analysis

More Quality Assurance packages