pyvers
A Python library for managing multiple versions of dependencies
What it is and what it does
Pyvers is a dispatch library that lets you write version-aware code without littering your codebase with version checks and conditional logic. It works by registering version-specific implementations of a function, then automatically selecting the correct one based on the installed version of a dependency. You define a base function with the @implement_for decorator, then register variants for different version ranges using the .register() API (similar to functools.singledispatch). At runtime, pyvers inspects the actual installed version and calls the matching implementation.
The library also supports backend switching, letting you register multiple implementations (e.g., NumPy vs JAX, CPU vs GPU) and swap between them dynamically using context managers. Backends are imported only when needed, so you can register optional dependencies without requiring them to be installed upfront. This is useful for libraries that want to support multiple compute backends or handle breaking changes across major versions without forcing users to maintain separate code paths.
Use it for:
- Support multiple versions of a dependency (e.g., NumPy < 2.0 vs >= 2.0) without if/else chains in your code
- Switch between CPU (SciPy) and GPU (CuPy) implementations at runtime based on availability or user preference
- Handle breaking API changes in frameworks like PyTorch 2.0 or gymnasium vs gym without duplicating logic
- Write version-specific optimizations (e.g., torch.compile for PyTorch 2.0+) that degrade gracefully on older versions
- Maintain backward compatibility while adopting new library features as they become available
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pyvers provides dynamic dispatch for Python functions based on installed package versions and backend implementations, letting you write version-specific code that automatically selects the right implementation at runtime.
Yes. Pyvers solves a real problem—managing version-specific code paths—with a clean, low-friction API and zero runtime dependencies. It's actively maintained, supports modern Python versions, has no known vulnerabilities, and is permissively licensed. Install it if you maintain a library that needs to support multiple versions of a dependency or multiple backend implementations.
Install
pyvers on PyPI
pip
pip install pyversuv
uv add pyverspoetry
poetry add pyversInstalling pyvers
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance as of 36 days ago. Supports Python 3.9 through 3.14.
License in practice
MIT license (permissive): you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
from pyvers import implement_for, register_backend, get_backend
register_backend(group="numpy", backends={"numpy": "numpy"})
@implement_for("numpy")
def create_mask(arr):
raise NotImplementedError("No matching numpy version found")
@create_mask.register(from_version=None, to_version="2.0.0")
def _(arr):
np = get_backend("numpy")
return np.array([x > 0 for x in arr], dtype=np.bool8)
@create_mask.register(from_version="2.0.0")
def _(arr):
np = get_backend("numpy")
return np.array([x > 0 for x in arr], dtype=np.bool_)
Verify before relying
- Whether the package handles edge cases like missing or incompatible backend packages gracefully
- Performance overhead of the dispatch mechanism compared to direct function calls
- Whether version range matching supports pre-release or development versions
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 36 days since the last release |
| First released | |
| Downloads | 2,474,161/month — #3,047 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyvers-0.2.3-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
multimethodMultimethod provides a decorator for adding…
permissive · top 5,000 on PyPI
singledispatchProvides single-dispatch generic functions—a…
permissive · top 5,000 on PyPI
autorayAutoray provides automatic dispatch of array…
permissive · top 15,000 on PyPI
methoddispatchAdds single-dispatch method support to Python…
permissive · top 15,000 on PyPI
plum-dispatchPlum implements multiple dispatch in Python,…
permissive · top 5,000 on PyPI
multipledispatchEnables functions to dispatch on the types of…
permissive · top 5,000 on PyPI
array-api-compatProvides a unified wrapper around NumPy, CuPy,…
permissive · top 5,000 on PyPI
jax-jumpyJax-jumpy provides a unified interface that…
permissive · top 15,000 on PyPI
qpsolversProvides a unified Python interface to solve…
copyleft · top 5,000 on PyPI
pyro-apiProvides a generic dispatch API for…
permissive · top 5,000 on PyPI