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.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-4.1.2.tar.gz (67.8 kB view details)

Uploaded Source

Built Distribution

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

typeguard-4.1.2-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typeguard-4.1.2.tar.gz
  • Upload date:
  • Size: 67.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for typeguard-4.1.2.tar.gz
Algorithm Hash digest
SHA256 3be187945f9ef5a9f6d7a926dfe54babb7dfd807085ce05f9a5e8735f2487990
MD5 1331c3b2d1ae90c695bc5e9de824cb6d
BLAKE2b-256 853bbfac182aaf3d084832fbe5fb1bdbf52c3ec8b0d10838888521b697952900

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typeguard-4.1.2-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for typeguard-4.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e00775920d4c91e93a0db0ed473ecda9cfaca578aed3ce0ed3ba7f3cc38eab9c
MD5 5e040ec93db934b45174ccfd026ee31b
BLAKE2b-256 bbbddc7da80c95c920ee2b575e64901b5962ca4a1271b5f3cf6c27242aa0aafc

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