skillfed

tightwrap

A typed `functools.wraps`.

tightwrap v26.1.0 90.9K downloads/30d#13,554 on PyPI
Permissive license Apache2 Active released

What it is and what it does

tightwrap is a minimal library that solves a specific typing problem: when you use `functools.wraps` to decorate a function, static type checkers like mypy lose the original function's signature and see only `*args, **kwargs`. This breaks type safety—a caller can pass the wrong types and the checker won't catch it. tightwrap.wraps has the same runtime behavior as `functools.wraps` but preserves the wrapped function's type signature for static analysis, so type checkers correctly report signature mismatches.

The package is intentionally small and has only one runtime dependency (`typing-extensions`). It applies `functools.wraps` under the hood to maintain runtime introspection compatibility, and it handles cases where the wrapper has a different return type than the wrapped function. Recent versions add support for wrapping methods and modern Python versions (3.13, 3.14).

Use it for:

  • Wrapping functions in decorators while maintaining type safety for static analysis.
  • Building decorator libraries where callers should see the original function's signature in their IDE and type checker.
  • Ensuring runtime function metadata (name, docstring, annotations) stays accurate while preserving type hints.
  • Wrapping methods in classes with correct typing for both static checkers and runtime introspection.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A drop-in replacement for `functools.wraps` that preserves static type information when wrapping functions, so type checkers see the wrapped function's actual signature instead of `*args, **kwargs`.

Yes. If you write decorators or function wrappers and use a static type checker, this is a straightforward win: it fixes a real gap in `functools.wraps` with zero complexity, no security issues, active maintenance, and a permissive license. If you don't use type checking or don't write wrappers, you don't need it.

Install

tightwrap on PyPI

pip

pip install tightwrap

uv

uv add tightwrap

poetry

poetry add tightwrap

Installing tightwrap

Before you install

Low friction: pure Python wheel with only `typing-extensions` as a runtime dependency. Actively maintained with recent releases supporting Python 3.13 and 3.14.

License in practice

Apache 2.0 (permissive): you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.

Quickstart

pip install tightwrap

from tightwrap import wraps

def original(a: int) -> int:
    return a + 1

@wraps(original)
def wrapper(*args, **kwargs) -> int:
    return original(*args, **kwargs)

Verify before relying

  • Whether the package is suitable for all decorator patterns (e.g., class decorators, async functions, partial application).
  • Performance characteristics compared to `functools.wraps` for high-frequency wrapping scenarios.

Package facts

License Apache2 (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 1 — typing-extensions
Maintenance actively maintained — 163 days since the last release
First released
Downloads 90,943/month — #13,554 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: tightwrap-26.1.0-py3-none-any.whl

Intended Audience :: DevelopersProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonTyping :: Typed

Tags

typed function wrapperfunctools.wraps typingstatic type preservation wrappingdecorator type hintsmypy-compatible wrapsfunction wrapper static typestyped decorator helper
typingdecorators

More Software Development packages