Skip to main content

A fast runtime type annotator for Python code.

Project description

Typerwriter

Typerwriter is a Python tool that generates types for your function arguments and return values. It produces much the same results as Instagram's monkeytype, while being both more flexible and vastly more efficient. Unlike monkeytype, which can slow down your code more than tenfold and cause it to consume huge amounts of memory, typerwriter lets your code run at nearly full speed with almost no memory overhead.

typerwriter: high performance

In the below example drawn from the pyperformance benchmark suite, monkeytype runs 30x slower than the original program or when running with typerwriter (which runs under 3% slower).

% python3 bm_mdp          
Time elapsed:  6.106977417017333
% typerwriter bm_mdp
Time elapsed:  6.299191833997611
% monkeytype run bm_mdp
Time elapsed:  184.57902495900635

typerwriter: low memory consumption

With monkeytype, this program also consumes 5GB of RAM; the original consumes just 21MB. That's an over 200x increase in memory consumption. monkeytype also leaves behind a 3GB SQLite file.

By contrast, typerwriter's memory consumption is just a small increment over the original program: it consumes about 24MB, just 15% more.

NOTE: this is an alpha release and is not production ready.

Requirements

  • Python 3.12 or higher

Installation

python3 -m pip install typerwriter

Usage

To use Typerwriter, simply run your script with typerwriter instead of python3:

typerwriter your_script.py [args...]

This will execute your_script.py with Typerwriter's monitoring enabled. The type signatures of all functions will be recorded and output to a file named typerwriter.out. Each line represents a function signature in the following format:

filename:def function_name(arg1: arg1_type, arg2: arg2_type, ...) -> return_type

Contributing

Contributions are welcome! Feel free to submit pull requests or report issues on the GitHub repository.

License

This project is licensed under the Apache License. See the LICENSE file for details.

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

typerwriter-0.0.2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typerwriter-0.0.2-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file typerwriter-0.0.2.tar.gz.

File metadata

  • Download URL: typerwriter-0.0.2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for typerwriter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 85719c68b7302b4886841c81240db50f1ff0933c3a45f4ad07f9dac8ff99006a
MD5 a797bb8c2e5a9e0b3a8ba5dceacec4d0
BLAKE2b-256 a43dc8a95e2ec5bdbdbf15643bc371114672fa17b969fc53c38d0e99ebb51145

See more details on using hashes here.

File details

Details for the file typerwriter-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: typerwriter-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for typerwriter-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1f4d7124d8a24024efa6630509a03fe1884e7bf601a15f84b36c9a208872fe2c
MD5 dea51aae8ac7bbb2f74eda9b34c108ad
BLAKE2b-256 700d35816fc4d9e3a1637269954ff625a7a7782a698f1d5a6716812ab08fcc89

See more details on using hashes here.

Supported by

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