--- id: contextlib2 version: "21.6.0" license: PSF License license_treatment: permissive maintenance: abandoned --- # contextlib2 — Backports and enhancements for the contextlib module License: permissive · Maintenance: abandoned · Downloads: 12.3M/mo ## 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 above — verify before relying. contextlib2 backports the Python standard library's contextlib module to earlier Python versions, providing context managers and related utilities for resource management across Python 3.6 and later. 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 pip install contextlib2 uv add contextlib2 poetry add contextlib2 ## Installing contextlib2 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_current - Install friction: low - Maintenance: abandoned - Downloads: 12.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags context manager backport, contextlib for older python, resource management utilities, python standard library backport, context manager enhancements, contextlib compatibility, async context manager support, backport, context-managers, legacy-support [View on SkillFed](https://skillfed.io/packages/contextlib2) · [View on PyPI](https://pypi.org/project/contextlib2/)