skillfed

pyvers

A Python library for managing multiple versions of dependencies

pyvers v0.2.3 2.5M downloads/30d#3,047 on PyPI
Permissive license MIT Active released

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 pyvers

uv

uv add pyvers

poetry

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 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

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9

Tags

version-based function dispatchhandle breaking changes between library versionsbackend switching cpu gpumulti-version dependency supportdynamic implementation selectionversion-specific code dispatchbackend abstraction layer
version-dispatchbackend-abstractioncompatibility-layer

More Software Development packages