Install & Compatibility
Where this runs
tested against v6.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.120s · 18.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.102s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ExceptionTrap
✓ from jaraco.context import ExceptionTrap
pushd
✓ from jaraco.context import pushd
temp_dir
✓ from jaraco.context import temp_dir
tarball
✓ from jaraco.context import tarball
on_interrupt
✓ from jaraco.context import on_interrupt
suppress
✓ from jaraco.context import suppress
A decorator version of contextlib.suppress.
null
✓ from jaraco.context import null
✗ import jaraco.context.null
While directly importable, it's generally preferred to import specific symbols. The `null` context manager is also deprecated.
This quickstart demonstrates the `temp_dir` context manager to create and automatically clean up a temporary directory, and the `pushd` context manager to temporarily change and restore the current working directory.
import os
from jaraco.context import temp_dir, pushd
with temp_dir() as tmp_dir_path:
print(f"Temporary directory created at: {tmp_dir_path}")
assert os.path.isdir(tmp_dir_path)
# The temporary directory is automatically removed here
assert not os.path.exists(tmp_dir_path)
# Example with pushd
current_cwd = os.getcwd()
with temp_dir() as tmp_path_for_pushd:
with pushd(tmp_path_for_pushd):
print(f"Current working directory changed to: {os.getcwd()}")
assert os.getcwd() == os.fspath(tmp_path_for_pushd)
print(f"Current working directory restored to: {os.getcwd()}")
assert os.getcwd() == current_cwd
Debug
Known issues
deprecatedThe `null` context manager, which provides a no-op context, has been deprecated. While still available, users should consider refactoring to avoid its use or using `contextlib.nullcontext` for newer Python versions (3.7+) as an alternative if truly needed for symmetry.fixMigrate to `contextlib.nullcontext` (Python 3.7+) or refactor code to remove the need for a no-op context.
affects: >=6.0.0 (deprecation noted in documentation)
gotchaWhen using the `tarball` context manager, a conditional dependency on `backports.tarfile` exists for Python versions prior to 3.12. If you target Python 3.10 or 3.11 and use `tarball`, ensure `backports-tarfile` is installed.fixFor Python 3.10-3.11, explicitly install `pip install backports-tarfile`. For Python 3.12+, it's part of the standard library.
affects: <3.12
gotchaOlder versions of `jaraco.context` (prior to unspecified fixes) had a vulnerability related to handling certain archive file paths in `tarball`, which could lead to directory traversal and overwriting files outside the intended extraction directory.fixAlways use the latest stable version of `jaraco.context` to ensure security patches are applied. As of 6.1.2, this issue should be addressed.
affects: <6.x (exact versions unspecified, but fixed in later releases)
breakingA temporary directory created and managed by a context manager (likely `tempdir` from `jaraco.context`) failed to be cleaned up upon exiting its context, resulting in an `AssertionError` when checking for its non-existence. This indicates a resource leak where temporary files or directories persist beyond their intended scope.fixEnsure the library version is up-to-date. If the issue persists, verify that the temporary directory context manager's implementation correctly removes the directory and its contents upon context exit. This may require checking for platform-specific cleanup issues or examining the library's bug tracker for known regressions related to resource management.
affects: >=6.0.0 (versions relying on `tempdir` for cleanup)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jaraco.context'
The `jaraco.context` package is not installed in the current Python environment or is not accessible on the Python path.
fixEnsure the package is correctly installed using pip: `pip install jaraco.context`
AttributeError: 'ExceptionTrap' object has no attribute 'passes'
This usually indicates an attempt to use an `ExceptionTrap` instance with a method (`.passes()` or `.raises()`) that is only available as a decorator on a function, or an older version of `jaraco.context` is installed that lacks this specific API.
fixUpdate `jaraco.context` to the latest version (`pip install --upgrade jaraco.context`) and ensure `ExceptionTrap` is used as a decorator (e.g., `@ExceptionTrap(ValueError).passes`) or as a context manager (e.g., `with ExceptionTrap(ValueError) as trap:`).
TypeError: 'function' object is not a context manager
A function that is intended to be a context manager (e.g., created with `@contextlib.contextmanager` or similar internal mechanisms in `jaraco.context`) is being called directly without a `with` statement, or the `@contextmanager` decorator was omitted.
fixEnsure that functions designed as context managers are always used within a `with` statement: `with some_context_manager():` or, if using a decorator, that the decorator itself is correctly applied to the function.
ImportError: The 'jaraco' package is required
This error typically occurs in bundled applications (e.g., created with PyInstaller) where `setuptools`'s `pkg_resources` module struggles to correctly locate the `jaraco` namespace package, even if `jaraco.context` is present.
fixWhen bundling with tools like PyInstaller, ensure the `jaraco` namespace is correctly included. This might involve adding `--hidden-import=jaraco` or `--collect-all jaraco` to your PyInstaller command, or explicitly including the `jaraco` parent directory in your build process.
Upgrade
Version history
6.1.2latest on PyPI · released Mar 20, 2026
Audit
Dependencies
backports.tarfileoptionalRequired for `tarball` context manager on Python versions < 3.12.