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.1.tar.gz (67.7 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.1-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typeguard-4.1.1.tar.gz
  • Upload date:
  • Size: 67.7 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.1.tar.gz
Algorithm Hash digest
SHA256 278ad7a974c9e6325037751fdffc470b9b0212d282c1746ecc452235922e3602
MD5 eddd83ddcb65f44f8064ca01f7763932
BLAKE2b-256 84294c062df3e7bd7198a07960608f3d5b0b938a10018de2a12a4c52bf00c23e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typeguard-4.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8145b40eaac14d2cd9656a40a763e8928c3519a2d39c43b6478ca20e513fad83
MD5 8af6f3613aa99cc68684a81b23a68aa5
BLAKE2b-256 e9fece8f006cc033bc839d1bc8280ed31eb125fa17655c4b81b734f235136fa2

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