Skip to main content

Generating type annotations from sampled production types

Project description

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:

$ 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.

LICENSE

MonkeyType is BSD licensed. We also provide an additional patent grant.

Changelog

17.12.0

  • Initial public version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MonkeyType-17.12.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

MonkeyType-17.12.1-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file MonkeyType-17.12.1.tar.gz.

File metadata

File hashes

Hashes for MonkeyType-17.12.1.tar.gz
Algorithm Hash digest
SHA256 56453e2e3313cf914c9f1107699cb7e4e76b81478e554fdca22af31b96b505c8
MD5 1c8195d81fff901f74bec8f84fc088ca
BLAKE2b-256 825f751674de2c3a33162536fb2d67ce6dc11192a2985c540dfd9bdc7ca7c65c

See more details on using hashes here.

Provenance

File details

Details for the file MonkeyType-17.12.1-py3-none-any.whl.

File metadata

File hashes

Hashes for MonkeyType-17.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1643bd98d397d3b1824aa370f4981ca7d40a0d039e60793249c22b5850b4cb10
MD5 90ef029b299e48461cdac3831b42a66b
BLAKE2b-256 f160aa4a881f5b544524aa6ec85d2b412911b15989f8318b309e2343dbb8f34d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page