wrapt

A Python module for building correct decorators, transparent object proxies, and safe monkey patching.

Library
PyPI
v2.3.0
2,293stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity96
Maintenance72
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture85
Code Quality88
Innovation80
Learning Curve62

wrapt provides a transparent object proxy for Python that serves as the foundation for writing decorators and wrapper functions that behave correctly in far more scenarios than functools.wraps() alone can guarantee. It goes beyond simply copying __name__/__doc__ attributes, preserving introspectability, call signatures, and type-checking behavior so that decorated functions, methods, classmethods, staticmethods, and classes all continue to behave like their undecorated originals.

The module ships a C extension for performance-critical proxy operations, with an automatic pure-Python fallback when no compiler is available, and includes dedicated utilities for monkey patching modules and classes safely at runtime. Because of its correctness-first design, wrapt is widely used as a dependency inside instrumentation, APM, and observability libraries (such as tracing agents) that need to wrap arbitrary third-party functions without breaking their callers’ assumptions.

What You Get

  • A @wrapt.decorator pattern for building ‘universal’ decorators that correctly detect whether they wrap a function, instance method, classmethod, or class
  • A transparent ObjectProxy base class for building advanced wrapper objects that behave identically to the wrapped object
  • Monkey-patching utilities (wrapt.wrap_function_wrapper, wrapt.patch_function_wrapper) for safely instrumenting third-party code at runtime
  • A C extension (_wrappers.c) for performance-critical proxy operations, with an automatic pure-Python fallback when no compiler is present
  • Thread-safe decorator implementations via a dedicated synchronization.py module
  • Full preservation of function signatures, annotations, and other introspection metadata through the decoration process

Common Use Cases

  • Writing decorators for a library’s public API that must preserve the wrapped function’s signature for tools like IDEs, inspect, and type checkers
  • Building an APM or tracing agent that monkey-patches third-party functions to add instrumentation without altering their observable behavior
  • Implementing lazy-loading, deprecation-warning, or retry decorators that need to work uniformly across functions, methods, and classes
  • Constructing object proxies (e.g. lazy objects, access-controlled wrappers) that must be indistinguishable from the object they wrap

Under The Hood

Architecture: The core is an ObjectProxy (src/wrapt/wrappers.py, src/wrapt/proxies.py) implemented primarily in C (src/wrapt/_wrappers.c) for speed, with a parallel pure-Python implementation used automatically when the C extension can’t be compiled — both expose the identical Python-level API so callers never need to know which backend is active. src/wrapt/decorators.py builds the @wrapt.decorator mechanism on top of this proxy, passing (wrapped, instance, args, kwargs) to the wrapper function so the decorator can introspect exactly what kind of callable it’s wrapping (plain function, bound method, classmethod, or class) via the instance parameter — this is the mechanism behind wrapt’s ‘universal decorator’ claim. src/wrapt/importer.py and patches.py implement the monkey-patching layer, hooking module import machinery so patches can be applied to functions/classes at the moment they’re first imported rather than requiring the patched module to already be loaded. src/wrapt/signature.py and arguments.py handle signature introspection and argument binding so decorated callables continue to report accurate inspect.signature() results. Tech Stack: Python 3.9+, CPython and PyPy supported, built with setuptools (PEP 639 license metadata) and uv for dependency locking (uv.lock); the C extension is optional and compiled via setup.py’s standard build_ext machinery. Code Quality: The tests/ directory contains 124 test files, an unusually large and thorough suite for a library of this size, reflecting the project’s explicit goal of focusing very much on correctness — tests cover decorator behavior across every callable type, proxy transparency, monkey-patching edge cases, and both the C and pure-Python backends to ensure behavioral parity. The repository also documents its own AI-assistant contribution guidelines (AGENTS.md, CLAUDE.md), suggesting active, disciplined maintenance practices. API Design: The (wrapped, instance, args, kwargs) decorator signature is the project’s signature ergonomic choice — it replaces the usual pattern of writing several near-duplicate decorator variants (one for functions, one for methods, etc.) with a single function that inspects instance to determine context, which the README’s ‘universal decorator’ example demonstrates directly; this does add one non-obvious concept (the meaning of instance) that newcomers must learn relative to a plain functools.wraps()-based decorator.

Used by 11 apps in this directory

Python
100%
Apache 2.0

Agno

Devops · AI Development · Automation

41,774

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
Python100%
Updated today
Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,081

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
63
Dependency
Built with
Python59%
Jupyter Notebook21%
Updated 2 days ago
C++
69%
Apache 2.0

ClickHouse

Databases · Analytics · Data Engineering

49,325

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
C++69%
Python13%
Updated today
C++
74%
Other

Dragonfly

Databases · Developer Tools · Devops

31,013

A modern Redis and Memcached replacement engineered for multi-core servers — delivering 25x more throughput, better cache hit rates, and up to 80% lower memory consumption with full API compatibility.

View details
90
Repo Health
9
Technical
71
Dependency
Built with
C++74%
Python16%
Updated today
Python
63%
Apache 2.0

GPT Researcher

Productivity · AI Assistants

29,039

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
88
Repo Health
91
Technical
64
Dependency
Built with
Python63%
TypeScript23%
Updated 1 months ago
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,469

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
68
Dependency
Built with
TypeScript83%
Python11%
Updated yesterday
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,083

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
62
Repo Health
81
Technical
66
Dependency
Built with
TypeScript91%
Updated 3 days ago
Python
83%
Apache 2.0

knowhere

AI Development · Developer Tools

2,515

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
70
Dependency
Built with
Python83%
HTML16%
Updated today
Python
47%
Other

Arize Phoenix

Devops · Analytics · Monitoring

11,105

Open-source AI observability platform for tracing, evaluating, and debugging LLM applications with built-in intelligence and MCP support.

View details
90
Repo Health
88
Technical
68
Dependency
Built with
Python47%
TypeScript41%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search