--- id: monkeytype version: "23.3.0" license: BSD license_treatment: permissive maintenance: aging --- # MonkeyType — Generating type annotations from sampled production types License: permissive · Maintenance: aging · Downloads: 356.4K/mo ## 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 above — 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 pip install monkeytype uv add monkeytype 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_current - Install friction: low - Maintenance: aging - Downloads: 356.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags runtime type inference, automatic type annotations, type stub generation, python type annotation tool, infer types from execution, generate type stubs, add type hints automatically, type-checking, code-generation, static-analysis [View on SkillFed](https://skillfed.io/packages/monkeytype) · [View on PyPI](https://pypi.org/project/monkeytype/)