Skip to main content

Runtime NumPy version router with lazy bootstrap and per-version caching.

Project description

# numpy-router

A lightweight runtime NumPy version router.

It allows Python applications to use different NumPy versions without reinstalling or modifying the environment.

The router intercepts the first real use of numpy and loads the appropriate version from a local cache.

It works with embedded Python distributions, machine‑learning frameworks, and environments where NumPy cannot be freely installed or upgraded.

---

## Features

- Lazy bootstrap: NumPy loads only when actually used.

- Version selection:

- requirements.txt next to the main script

- package dist-info metadata

- user‑forced version via environment variable

- fallback heuristic

- Router bypass switch.

- Cache inspection API.

- Compatible with native NumPy installations.

---

## Installation

pip install numpy-router

Then place the provided numpy\_router.pth file into your Python site-packages directory.

---

## Environment Variables

### NUMPY\_ROUTER\_VERSION=X.Y.Z

Force a specific NumPy version.

### NUMPY\_ROUTER\_OFF=1

Disable the router entirely and use native NumPy.

### NUMPY\_ROUTER\_CACHE=PATH

Override the cache directory.

---

## Cache Inspection

---


python

import numpy\_router

print(numpy\_router.cache())

---

## How It Works

---

┌──────────────────────────┐

│ Python starts │

│ site-packages loads .pth │

└───────────────┬──────────┘

shim module installed

as sys.modules["numpy"]

numpy_router wraps shim

with a lightweight proxy

first attribute access on numpy

(e.g., np.ndarray, np.array)

bootstrap runs

- resolve version

- download if needed

- extract to cache

- load real NumPy

- replace shim with real module

all further imports use

real NumPy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numpy_router-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numpy_router-0.1.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file numpy_router-0.1.1.tar.gz.

File metadata

  • Download URL: numpy_router-0.1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for numpy_router-0.1.1.tar.gz
Algorithm Hash digest
SHA256 491010d86f87a03521c5a42fdb981952bc3f97f99a2faf70086a8aed72a29b3c
MD5 e6331e05bc32362d0d70ea8b8d6660b8
BLAKE2b-256 b69c7bc3e89887b0e6a9147bc1ca0caf1cdcb58718b4d0064fb9ccef73a9e971

See more details on using hashes here.

File details

Details for the file numpy_router-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: numpy_router-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for numpy_router-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab83917ebf995112d6e5b564e0163da831841574eb3a44a26f6155eb98f3f465
MD5 80854be12cc3b4cfd1c71072b9cb7a87
BLAKE2b-256 8bb33df121946f9f1427c85767cdd87cbc5a75eb54bee80790ac91201e486424

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page