contextlib2
Backports and enhancements for the contextlib module
Decision gist · record as of 2026-08-14
No, unless you are maintaining legacy code on Python 3.6–3.10 and need a specific backported feature not yet in your target Python version. For modern Python, use the standard library contextlib directly. The package is abandoned and receives no maintenance.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low install friction with no runtime dependencies.
- However, the package is abandoned—last release was 1874 days ago.
- For modern Python versions, the standard library contextlib is available natively; this backport is primarily useful for legacy codebases or edge-case compatibility scenarios.
License · maintenance · safety
PSF License (permissive) — Dual-licensed under the Python Software Foundation License (for the backported code) and Apache License 2.0 (for type hints from typeshed). Both are permissive; no restriction on commercial or proprietary use.
last release 2021-06-27 (1874 days)
0 known vulnerabilities (OSV.dev, 2026-08-14) · 12,264,081 downloads/mo, #1,330 on PyPI
Alternatives
Verify before relying
pip install contextlib2
import contextlib2
@contextlib2.contextmanager
def my_context():
print('enter')
yield
print('exit')
with my_context():
pass- Whether the backported APIs differ meaningfully from the current standard library contextlib.
- Whether Python 3.6, 3.7, 3.8, 3.9, or 3.10 versions targeted by this package remain in active use in your codebase.
What it is and what it does
contextlib2 is a backport of Python's standard library contextlib module, designed to make context manager utilities available on Python versions earlier than those in which they were added to the standard library. It includes both the core context manager decorators and utilities, plus type hints from the typeshed project.
Since the package requires Python 3.6 or later and the standard library has included contextlib since the earliest Python 3 releases, this package is most relevant for maintaining compatibility in legacy codebases. The package is no longer actively maintained, with its last release in 2021-06-27.
Use it for
- Maintaining legacy code that must run on Python 3.6–3.10 while using a unified contextlib interface.
- Providing type hints for contextlib usage in projects that need static type checking across multiple Python versions.
- Serving as a reference implementation or testing ground for proposed enhancements to the standard library contextlib.
- Supporting projects that pin to older Python versions and need backported context manager utilities.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
No, unless you are maintaining legacy code on Python 3.6–3.10 and need a specific backported feature not yet in your target Python version.
For modern Python, use the standard library contextlib directly. The package is abandoned and receives no maintenance.
Install
contextlib2 on PyPI
Before you install
Low install friction with no runtime dependencies. However, the package is abandoned—last release was 1874 days ago. For modern Python versions, the standard library contextlib is available natively; this backport is primarily useful for legacy codebases or edge-case compatibility scenarios.
License in practice
Dual-licensed under the Python Software Foundation License (for the backported code) and Apache License 2.0 (for type hints from typeshed). Both are permissive; no restriction on commercial or proprietary use.
Quickstart
pip install contextlib2
import contextlib2
@contextlib2.contextmanager
def my_context():
print('enter')
yield
print('exit')
with my_context():
pass
Verify before relying
- Whether the backported APIs differ meaningfully from the current standard library contextlib.
- Whether Python 3.6, 3.7, 3.8, 3.9, or 3.10 versions targeted by this package remain in active use in your codebase.
Package facts
| License | PSF License permissive |
| Python support | Supports the current Python release >=3.6 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Abandoned 1,874 days since the last release |
| First released | |
| Downloads | 12,264,081 / month, #1,330 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableLicense :: OSI Approved :: Apache Software LicenseLicense :: OSI Approved :: Python Software Foundation LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: contextlib2-21.6.0-py2.py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “context manager backport”
- contextlib2contextlib2 backports the Python standard library's contextlib module…
- async-exit-stackProvides AsyncExitStack, a backport of Python 3.7's asynchronous…
- backports.tempfileProvides the TemporaryDirectory context manager for Python 2.7 and…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also backports.tempfile · pickle5 · async_generator · asyncio · logutils · linecache2 · pyasyncore · traceback2 · textwrap3 · importlib-resources