Skip to main content

Maximum performance runtime type enforcement using CPython C API.

Reason this release was yanked:

Redundant speed and nature

Project description

Guardian 🛡️

Maximum performance runtime type enforcement for Python 3.10+

Guardian is a C-optimized runtime type checker that ensures your Python functions receive and return exactly the types they expect. It operates at two levels: blazing-fast function boundary enforcement, and strict local-variable execution tracing.

Built directly on the CPython C-API using the Vectorcall protocol, Guardian delivers microsecond-level overhead.

Features

  • @guard: Enforces parameter and return types at the function boundary (~0.67µs overhead).
  • @strictguard: Enforces boundaries and locks local variables to their annotated or initially assigned types dynamically (~13µs overhead).
  • Comprehensive Typing Support: Supports Union (|), Literal, Annotated, list[T], dict[K, V], set[T], tuple[T, ...], Custom Classes, and Forward References.
  • C-Level Performance: Pre-compiled type-check trees and zero Python-level lambda recursion.

Installation

pip install guardian
(Note: Guardian utilizes a C extension. If installing from source on Windows, you will need the Visual Studio C++ Build Tools installed.)

Usage1. Function Boundary Enforcement (@guard)
Use @guard for maximum-speed input/output validation.Python

from guardian import guard

@guard
def process_data(data: list[int], limit: int | None = None) -> int:
    if limit is None:
        return sum(data)
    return sum(data[:limit])

process_data([1, 2, 3], limit=2)  # OK
process_data([1, "2", 3])         # GuardianTypeError: Parameter 'data' expected list[int]
2. Strict Internal Execution Tracing (@strictguard)
Use @strictguard for mathematically complex or security-sensitive functions where local variable mutation bugs would be catastrophic.Python

from guardian import strictguard

@strictguard
def strict_math(x: int) -> int:
    y = 10        # 'y' is dynamically locked to 'int'
    y = 20        # OK
    y = "bad"     # GuardianTypeError: Variable 'y' expected int, got str
    return x + y

Performance BenchmarkMeasured on Python 3.13 (1,000,000 iterations)

TargetTotal Time (s) Overhead/call (µs)
Plain Function 0.1514
Guardian C (@guard) 0.8278 ~0.67 µs
StrictGuard C (@strictguard) 13.1459 ~13.0 µs

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

guardian_type_enforcer-2.0.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distributions

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

guardian_type_enforcer-2.0.0-cp313-cp313-win_amd64.whl (12.5 kB view details)

Uploaded CPython 3.13Windows x86-64

guardian_type_enforcer-2.0.0-cp312-cp312-win_amd64.whl (13.2 kB view details)

Uploaded CPython 3.12Windows x86-64

guardian_type_enforcer-2.0.0-cp312-cp312-win32.whl (12.6 kB view details)

Uploaded CPython 3.12Windows x86

guardian_type_enforcer-2.0.0-cp312-cp312-musllinux_1_1_x86_64.whl (34.6 kB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

guardian_type_enforcer-2.0.0-cp312-cp312-musllinux_1_1_i686.whl (33.8 kB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ i686

guardian_type_enforcer-2.0.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (30.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

guardian_type_enforcer-2.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (29.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

guardian_type_enforcer-2.0.0-cp312-cp312-macosx_11_0_arm64.whl (10.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

guardian_type_enforcer-2.0.0-cp312-cp312-macosx_10_9_x86_64.whl (10.4 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

guardian_type_enforcer-2.0.0-cp311-cp311-win_amd64.whl (13.1 kB view details)

Uploaded CPython 3.11Windows x86-64

guardian_type_enforcer-2.0.0-cp311-cp311-win32.whl (12.6 kB view details)

Uploaded CPython 3.11Windows x86

guardian_type_enforcer-2.0.0-cp311-cp311-musllinux_1_1_x86_64.whl (32.7 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

guardian_type_enforcer-2.0.0-cp311-cp311-musllinux_1_1_i686.whl (32.3 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ i686

guardian_type_enforcer-2.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

guardian_type_enforcer-2.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (27.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

guardian_type_enforcer-2.0.0-cp311-cp311-macosx_11_0_arm64.whl (10.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

guardian_type_enforcer-2.0.0-cp311-cp311-macosx_10_9_x86_64.whl (10.4 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

Details for the file guardian_type_enforcer-2.0.0.tar.gz.

File metadata

  • Download URL: guardian_type_enforcer-2.0.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for guardian_type_enforcer-2.0.0.tar.gz
Algorithm Hash digest
SHA256 c6592884c8e82fe4f8aaac2faf3fc4d74f519418587c2f57f16b32bf4f1820a2
MD5 4c413ecadaff55c44d7be49d8496dce5
BLAKE2b-256 64c3c3e250757347cc3248926948c5f28461279cbf93a6c4ef5a4cf6ddb5d12b

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 045753a2fc1e6eb503109d40c9bb7c70c3fd28f901408699131d4460d7c8379c
MD5 1abd1bb176d6907be388eb7ecdc9d033
BLAKE2b-256 debea61cfbec945baf7be74a1318bc7e24cee0cd5c8f8dc275676fa508e952eb

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fd7c57e06d80e09e6f061ed8763c72f65d74dc8a176c8669140f009aa1dac412
MD5 d8ceaa1f8181d923012744b3cba292df
BLAKE2b-256 9d581880f4efc5c718d8ac36be0daeb10ccab8351304e8cb1ab9e8f8344ec943

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 2c9e7ab55052591a43b9ff86ebfc2f6815e1256be5e98577b03738f4b2580ebc
MD5 a6ea37623d7e7c39f49e0823c5266d36
BLAKE2b-256 eb9f2a8a5f37371817983817eb35499566477670a8449fd945eedbdf98af58d5

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d2342fd2251c73654feb7a1f03f7342d3b85f6ef2e430c6713b528b790e69039
MD5 469f0015554085022d16d6c3fbef029d
BLAKE2b-256 0b8a12c383960057ff3bfc9cfd58ed815c679cb81352f4b49893dc5681c4b133

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 00dfb0fbbbe9fe6c8c12e0c155778caad6081d9fafc68f046ad13e13918e4866
MD5 2e2790687aced82cd427fab909a77814
BLAKE2b-256 af4b674b2e4995f7ad927c8693a0193311540da5d88e1fde870011733b818e15

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 53790c263cdebc62837a780ca2bc3c3c223da02b46681c679dfcb2bb4f1acab4
MD5 7df0dd6fc1ef49d91caf847d27909d0f
BLAKE2b-256 e1d289172ce469ce69d266f6432c2faeab4f283de0aa0570abf74ad9b1089a95

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 eb371060cf13154c2f9f1b38343b3d4159664da076bd982e7c386b636741e138
MD5 16d80ca3b1655309cf339f27e82bece5
BLAKE2b-256 1f51bb9ed886304a79e189d13eef40502ae86b315987d73512d52bae2bce2c90

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20c89471408800ae107b028ea3be9e6d37ad501a5081a4a9d13899f77832fb30
MD5 fbfdc680b8387c44f5725b0f70159540
BLAKE2b-256 70681d5952e424564a63e0b73ba7f12659312647dec1156019e484edeb7b0602

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3e4cc32827b494e8c237cfac10d841db3b590a1f4de4aa8fc6cdd0588c7c331f
MD5 fad06315cb2d2013af8b2e3fce8e706f
BLAKE2b-256 36baf03d2a98f2942b7db863262e25fa0cad7db671857414860914e8cc508726

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ef375fb253133cb92ac5dd5036130d6c32a03afc15489301e604c6b6457ab286
MD5 0e24047bddf0471e6dea985f64e5aa52
BLAKE2b-256 b59de377a221e0d458df3dc55bfa92391a027a03408847189dbb390be6144a32

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 c61e52aa673681dfdbe085fdc62596c183ebe3ed61136d3af38de97bdd964f3b
MD5 3ccfc365f10061a11a97a62e84eed259
BLAKE2b-256 278bb565aadf8f897de74326157e737197634b05861bf8fecc21d965f7a6fdf3

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8cb31b682a4b179f4588dcc1456c48b426808093ab4b97436a4d10af442de812
MD5 88876e992d5f4eb3f5553ad1a6d8150b
BLAKE2b-256 595f03908ac0c557766ecb489f98526c3bb030fb6a6303fa40d182abec409a13

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 f96f816a50434dfb18b7bbb260e4edf81da855f5c5759d78b54ffa4cc4762cba
MD5 9043924d7600204792e1ec55af4ad0f8
BLAKE2b-256 6a875a7a2b8be25308f765575c58fbc1b5b8997307d311edff0aee92ecbd5803

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a6b0ef701fda530f3c7573e61de8459f66a79638b9ba420066f4e2543948ffb5
MD5 f6b1009e7761466218e5700464d4f216
BLAKE2b-256 41ea82eedfbee7cb6cd61e9f215062886ef989605def1894d8cbad73498ea440

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2e25bc1f79f29483c7c8603b45d959605180724aa54b0f8b0a255627133e0c03
MD5 593e330c3bba7c22537f10c438a0a24a
BLAKE2b-256 eead02b331479f19865c31379ee3544c64afe619a5a5acad5c6809b51a5d0209

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ae6f0eb32514b89576553a397c88d497ae71b60956567eda80c132c252c3e88
MD5 23254dd741f9224ff72365808e956c56
BLAKE2b-256 599d8d2fe1267d5a18df756ec253446756479fe1bfd06d4b26c52342403c46ec

See more details on using hashes here.

File details

Details for the file guardian_type_enforcer-2.0.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for guardian_type_enforcer-2.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b866fa588778ef860e275ce2ebd39dd338ef07941a3b00393702f58fd6c0f85a
MD5 3cd3f484628b61db13eb58af4528ab36
BLAKE2b-256 4bb0fb15ee2c125db2efcc77670c7854eb7f6c1614b55a192999c7bf836582d3

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