Metadata-Version: 2.4
Name: numpy-router
Version: 0.1.1
Summary: Runtime NumPy version router with lazy bootstrap and per-version caching.
Author: Leon
License: MIT
Project-URL: Homepage, https://github.com/leomaxwell972/numpy-router
Requires-Python: >=3.8
Description-Content-Type: text/markdown

\# 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:

&#x20; - `requirements.txt` next to the main script

&#x20; - package `dist-info` metadata

&#x20; - user‑forced version via environment variable

&#x20; - 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 │

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

&#x20;               │

&#x20;               ▼

&#x20;     shim module installed

&#x20;     as sys.modules\["numpy"]

&#x20;               │

&#x20;               ▼

&#x20;     numpy\_router wraps shim

&#x20;     with a lightweight proxy

&#x20;               │

&#x20;               ▼

&#x20;  first attribute access on numpy

&#x20;  (e.g., np.ndarray, np.array)

&#x20;               │

&#x20;               ▼

&#x20;        bootstrap runs

&#x20;  - resolve version

&#x20;  - download if needed

&#x20;  - extract to cache

&#x20;  - load real NumPy

&#x20;  - replace shim with real module

&#x20;               │

&#x20;               ▼

&#x20;     all further imports use

&#x20;         real NumPy







