--- id: pyvers version: "0.2.3" license: MIT license_treatment: permissive maintenance: active --- # pyvers — A Python library for managing multiple versions of dependencies License: permissive · Maintenance: active · Downloads: 2.5M/mo ## 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 above — 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 pip install pyvers uv add pyvers poetry add pyvers ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 2.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags version-based function dispatch, handle breaking changes between library versions, backend switching cpu gpu, multi-version dependency support, dynamic implementation selection, version-specific code dispatch, backend abstraction layer, version-dispatch, backend-abstraction, compatibility-layer [View on SkillFed](https://skillfed.io/packages/pyvers) · [View on PyPI](https://pypi.org/project/pyvers/)