MonkeyType
MonkeyType collects runtime types of function arguments and return values, and can automatically generate stub files or even add draft type annotations directly to your Python code based on the types collected at runtime.
Examples
Run a script under call-trace logging of functions and methods in all imported modules:
$ monkeytype run myscript.py
Or enable call-trace logging for a block of code:
import monkeytype
with monkeytype.trace():
...
By default this will dump call traces into a sqlite database in the file monkeytype.sqlite3 in the current working directory. You can then use the monkeytype command to generate a stub file for a module, or apply the type annotations directly to your code:
$ monkeytype stub some.module $ monkeytype apply some.module
Requirements
MonkeyType requires Python 3.6+ and the retype library (for applying type stubs to code files). It generates only Python 3 type annotations (no type comments).
Installing
Install MonkeyType with pip:
pip install MonkeyType
How MonkeyType works
MonkeyType uses the sys.setprofile hook provided by Python to interpose on function calls, function returns, and generator yields, and record the types of arguments / return values / yield values.
It generates stub files based on that data, and can use retype to apply those stub files directly to your code.
See the full documentation for details.
Troubleshooting
Check if your issue is mentioned in the frequently asked questions list.
LICENSE
MonkeyType is BSD licensed.
Changelog
17.12.3
Rewrite imports from _io module to io. (#1, merge of #32). Thanks Radhans Jadhao.
Add Config.cli_context() as a hook for custom CLI initialization and cleanup logic (#28; merge of #29). Thanks Rodney Folz.
17.12.2
Exclude “frozen importlib” functions in default code filter.
Fix passing args to script run with monkeytype run (#18; merge of #21). Thanks Rodney Folz.
Fix generated annotations for NewType types (#22; merge of #23). Thanks Rodney Folz.
17.12.1
Fix using MonkeyType outside a virtualenv (#16). Thanks Guido van Rossum for the report.
17.12.0
Initial public version.
Metadata
Release files for MonkeyType 17.12.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| MonkeyType-17.12.3.tar.gz | 20.7 kB | Without provenance | Details for MonkeyType-17.12.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| MonkeyType-17.12.3-py3-none-any.whl | Python 3 | none | any | Details for MonkeyType-17.12.3-py3-none-any.whl |
Total release size: 48.5 kB
Release files / MonkeyType-17.12.3.tar.gz
| Download URL | MonkeyType-17.12.3.tar.gz |
|---|---|
| Size | 20.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19d2061267c694ff6722ee28842f7b66c0dd1c0109b297167b750dc9e846a649
|
|
BLAKE2b-256 checksum How to use checksums |
8a3469e43d5e6c93e9b24d2819b747a8da60896f9d8cea95c3a34b0bd7545d0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / MonkeyType-17.12.3-py3-none-any.whl
| Download URL | MonkeyType-17.12.3-py3-none-any.whl |
|---|---|
| Size | 27.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0e13947eb10cb0c228439a5a0553a0726ce22e330d8b4e1ccd992a62291ea2c
|
|
BLAKE2b-256 checksum How to use checksums |
e1675cae22d2ef2f23fdab687ad99a6925c157c81f4fc2974227a8bb9f23f0ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for MonkeyType 17.12.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.