Home
Author: Jiri Borovec · License: Apache 2.0 · Python: 3.9+ · Install: pip install pyDeprecate · Import: from deprecate import deprecated · PyPI: https://pypi.org/project/pyDeprecate/
Renaming a function or retiring an argument often means writing a wrapper and manual forwarding. You must also configure the warning category and stacklevel, then enforce the removal deadline. pyDeprecate replaces that boilerplate with a decorator and CI checks for overdue removals.
Usage and background
pyDeprecate has broad PyPI usage. For current download statistics, see pepy.tech.
Read Mastering API Deprecation in Python — the pain points and how pyDeprecate can help on CodeX / Medium.
from deprecate import deprecated
# NEW API — compute a sum with the current implementation.
def compute_sum(a: int, b: int) -> int:
return a + b
# DEPRECATED API — addition forwards to compute_sum.
@deprecated(target=compute_sum, deprecated_in="1.0", remove_in="2.0")
def addition(a: int, b: int) -> int:
return a + b
print(addition(1, 2)) # warns: FutureWarning
Calling addition(1, 2) now emits a FutureWarning and transparently forwards to compute_sum.
Features🔗
- Automatic call forwarding: The decorator routes positional and keyword arguments to the replacement. You need no manual
*args/**kwargsplumbing. - Generator and async support: Wrappers support generator functions (
def fn(): yield),async defcoroutines, and async generators (async def fn(): yield). They preserve the source'siscoroutinefunction,isgeneratorfunction, orisasyncgenfunctionintrospection. Functions warn at call time, coroutines onawait, and generators on their firstnext()orasync forstep. - Argument mapping:
args_mapping={"old": "new"}handles renames across the API boundary. Map toNoneto drop an argument entirely. - Argument deprecation:
TargetMode.ARGS_REMAPwarns only when callers pass the old argument name. Migrated callers see no noise. - Class and Enum support:
@deprecated_classwraps classes, Enums, and dataclasses in a transparent proxy. It supportsisinstanceandissubclass. - Instance / constant proxy:
deprecated_instance(obj, ...)wraps module-level dicts, lists, and custom objects. It provides transparent attribute/item access and optionalread_onlyenforcement. - Module deprecation:
deprecated_module(__name__, ...)retires a module, warning on every public attribute access. This includes names already in__dict__and star-imports, which PEP 562's__getattr__cannot reach. Warn in place, redirect to a replacement, or alias from the parent package. - Strict callable-only form:
@deprecated_callable()shares every@deprecatedparameter. It raisesTypeErrorat decoration time on a class source when implicit class dispatch should be an error. - Mode inference:
@deprecateddefaults toTargetMode.AUTO. Configuration resolves the mode at decoration time. Audit tools see the concrete mode, neverAUTO. - Public proxy protocol: Annotate against
DeprecationProxyinstead of private_DeprecatedProxy. Proxies carry__wrapped__/__signature__breadcrumbs. These letinspect, Sphinx, griffe, and IDEs resolve the source. - Configurable frequency:
num_warns=1defaults to one warning per function. Set-1for always orNfor exactly N times. - Docstring injection:
update_docstring=Trueautomatically inserts a Sphinx.. deprecated::or MkDocs admonition notice before the first docstring section. This keeps rendered API docs accurate. - Sphinx Plugin:
deprecate.docstring.sphinx_extrenders_DeprecatedProxyobjects with their injected deprecation notices in Sphinx autodoc. - MkDocs Plugin:
deprecate.docstring.griffe_extexposes runtime-injected!!! warningadmonitions in mkdocstrings-generated API docs. - Decorator stacking: Stack
@deprecateddecorators for multi-version migrations. Rename arguments across releases (ARGS_REMAP + ARGS_REMAP), then deprecate the function when a replacement arrives (ARGS_REMAP + NOTIFY). Unsupported combinations warn at decoration time. - Custom streams: The
streamparameter routes warnings tologging, standardwarnings, or any callable.stream=Nonesilences output while forwarding continues. - Custom message templates:
message_templateoverrides the default message with%-style placeholders. Available placeholders includesource_name,target_path,deprecated_in,remove_in, andargument_map. - Conditional skip:
skip_if=callablesuppresses deprecation machinery when a runtime condition holds, such as callers adopting a newer dependency. It works on decorators and proxies. - CI audit tools:
validate_deprecation_expiry()catches overdue removals.validate_deprecation_policy()checks your release policy.validate_deprecation_chains()detects double-deprecation chains. - Wrapper validation:
find_deprecation_wrappers()surfaces misconfiguredargs_mappingkeys before they silently do nothing. - Static type-checker signals: Native PEP 702 diagnostics come from
warnings.deprecated, which type checkers recognise by name. For static hints with runtime forwarding, stack@warnings.deprecated("literal message", category=None)directly above@deprecated(...). See Static type checkers. - CLI:
pydeprecate check src/scans for misconfigured wrappers and chains.pydeprecate all src/also checks expiry and policy, then appends a deprecation table. See CLI Reference. - CI integration: Ready-made pre-commit hooks and a GitHub Action run the checks in CI.
- Fatal mode:
as_exception=Trueordeprecate.as_exceptions()raisesDeprecatedErrorinstead of warning. Test runs can refuse deprecated calls. See Fatal deprecations. - Testing helpers: The
assert_no_warnings()context manager checks that no warnings of a given type escape a block.no_warning_callremains a legacy alias. - Zero runtime dependencies: Nothing is added to
install_requires. - Python compatibility: Python 3.9+ is supported.

Installation🔗
Choose the install that matches your workflow.
| Workflow | Command | Includes |
|---|---|---|
| Runtime deprecation wrappers | pip install pyDeprecate |
@deprecated, @deprecated_class, deprecated_instance, docstring helpers, and most audit metadata helpers |
| CI deadline checks | pip install 'pyDeprecate[audit]' |
Adds packaging for PEP 440 version comparison in validate_deprecation_expiry() and validate_deprecation_policy() |
| Command-line audit workflows | pip install 'pyDeprecate[audit]' |
Adds packaging version support for pydeprecate expiry, pydeprecate policy, and pydeprecate all; the CLI itself needs no dependency |
Install the audit extra for CI checks that compare version strings.
The [audit] extra is only needed for validate_deprecation_expiry and validate_deprecation_policy
The base install gives you @deprecated, @deprecated_class, deprecated_instance, and all other audit functions. Only validate_deprecation_expiry() and validate_deprecation_policy() need the extra. They use packaging for PEP 440 version comparison.
Use [audit] for command-line audit workflows
The pydeprecate command itself needs no extra. Before v0.15 it also needed the cli extra. pydeprecate expiry, pydeprecate policy, and the expiry/policy phases of pydeprecate all need [audit].
Start with pip install 'pyDeprecate[audit]' unless you only need Python API calls.
Comparison with other tools🔗
Choose pyDeprecate for call forwarding, argument mapping, proxies, and CI audits. Use PEP 702 with category=None for static checker visibility without per-call wrapper overhead. See the canonical tool comparison for alternatives, migration examples, and testing guidance.
Where to go next🔗
- Getting Started — install, write your first deprecation, see the full API at a glance.
- Use Cases — overview of all deprecation patterns with links to each topic page.
- Customization — custom message templates and output redirection to loggers.
- void() Helper — sentinel function for self-documenting deprecated stubs.
- Audit Tools — enforce removal deadlines and catch deprecation chains in CI.
- Compare Python Deprecation Tools — compare
warnings.warn,deprecation,Deprecated, andwarnings.deprecated. - Agent Recipes — copy-paste patterns for AI coding assistants.
- Troubleshooting — common errors and how to fix them.
- Brand — logos, colors, banners, and the "API migration by pyDeprecate" badge.
- Sphinx demo · MkDocs demo — live rendered output.
Show that you use pyDeprecate🔗
Show callers your project's deprecation path with a README badge. They receive a warning, a forwarded call, and a removal deadline instead of a sudden break.
[](https://github.com/Borda/pyDeprecate)
Compatibility and fit🔗
Recent PyPI download statistics show broad production use; see pepy.tech for current numbers.
| Topic | Status |
|---|---|
| Python versions | Project metadata currently supports Python 3.9+; Borda-maintained development policy targets Python 3.10+ because Python 3.9 reached end of life in October 2025. |
| Runtime dependencies | None. |
| Optional audit extra | packaging (plus tomli on Python < 3.11 for pyproject.toml version detection). |
| Optional CLI extra | None — the CLI uses only the standard library. Before v0.15 it needed the cli extra. |
| Docs engines | Sphinx and MkDocs compatible. |
| Type checker static warnings | Prefer warnings.deprecated for Python 3.13+ static-checker-only cases. |
When not to use pyDeprecate🔗
- Use
warnings.warnfor one-off internal warnings that do not need compatibility behavior. - Use
warnings.deprecatedfor static-checker-only visibility on Python 3.13+. - Use pyDeprecate when callers need forwarding, argument mapping, class or object aliases, warning frequency control, or CI audit checks.