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.0.0rc5.tar.gz (65.8 kB view details)

Uploaded Source

Built Distribution

typeguard-4.0.0rc5-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file typeguard-4.0.0rc5.tar.gz.

File metadata

  • Download URL: typeguard-4.0.0rc5.tar.gz
  • Upload date:
  • Size: 65.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for typeguard-4.0.0rc5.tar.gz
Algorithm Hash digest
SHA256 2f3f112c1744dc35022a9a90770683e6138c441c2e2f8d32f01f6f71a2b4f15f
MD5 2f5da4b2c128040c9ee8731a573e5726
BLAKE2b-256 9f85de8d213bdb834745f50558f9d9873d2e5445760380f53ef1c408911e20f3

See more details on using hashes here.

File details

Details for the file typeguard-4.0.0rc5-py3-none-any.whl.

File metadata

  • Download URL: typeguard-4.0.0rc5-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for typeguard-4.0.0rc5-py3-none-any.whl
Algorithm Hash digest
SHA256 5a253ea36b5d908465bd0cf40832b7dce4335844788737c63ad3deb891b15452
MD5 6f6517d8e268c389aedfd5ce19b636e5
BLAKE2b-256 ce36f1e441b35f699b970efb700d1dbc1ddd1aec311c83b7eb60caf5c92ec9f3

See more details on using hashes here.

Supported by

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