Skip to main content

Run-time type checker for Python

Project description

Build Status Code Coverage Documentation

This library provides run-time type checking for functions defined with PEP 484 argument (and return) type annotations, and any arbitrary objects. It can be used together with static type checkers as an additional layer of type safety, to catch type violations that could only be detected at run time.

Two principal ways to do type checking are provided:

  1. The check_type function:

    • like isinstance(), but supports arbitrary type annotations (within limits)

    • can be used as a cast() replacement, but with actual checking of the value

  2. Code instrumentation:

    • entire modules, or individual functions (via @typechecked) are recompiled, with type checking code injected into them

    • automatically checks function arguments, return values and assignments to annotated local variables

    • for generator functions (regular and async), checks yield and send values

    • requires the original source code of the instrumented module(s) to be accessible

Two options are provided for code instrumentation:

  1. the @typechecked function:

    • can be applied to functions individually

  2. the import hook (typeguard.importhook.install_import_hook()):

    • automatically instruments targeted modules on import

    • no manual code changes required in the target modules

    • requires the import hook to be installed before the targeted modules are imported

    • may clash with other import hooks

See the documentation for further information.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

typeguard-3.0.0.tar.gz (55.3 kB view details)

Uploaded Source

Built Distribution

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

typeguard-3.0.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file typeguard-3.0.0.tar.gz.

File metadata

  • Download URL: typeguard-3.0.0.tar.gz
  • Upload date:
  • Size: 55.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for typeguard-3.0.0.tar.gz
Algorithm Hash digest
SHA256 91d86faa19b750515edab2d5fc9e4167dedd45b420e1696cd5d5e42f06d6bc02
MD5 7c9960e5fcf30fda70aa4f01a6292e87
BLAKE2b-256 f0c3f6e286339bda8015a116c1ee4d0319cefe59d1e9d7a00483b2fad3d6d4c9

See more details on using hashes here.

File details

Details for the file typeguard-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: typeguard-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for typeguard-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f595ad0c7dab4d7cb7158ddb46c392f17200a1f6f7ce340068ba2417661de31a
MD5 f1514f6ce7f37005cfef0022407bf1bc
BLAKE2b-256 67c6635a038d242026e7cd9efcd3f6cb3a6c3b6617aaa95d8e550a7c7284c371

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