Intelligent Meta-Dispatcher โ one import, best backend, always.
Project description
Shaaha ๐ง
One import. Best backend. Always.
Shaaha is a Python meta-dispatcher library. Instead of memorising which
library is fastest, whether your system has a GPU, or whether a colleague has
polars installed โ you write import shaaha.dataframe and Shaaha figures it
out for you, silently, at the moment you actually use it.
The Problem Shaaha Solves
| Problem | Without Shaaha | With Shaaha |
|---|---|---|
| Dependency hell | try: import cupy except: import numpy everywhere |
import shaaha.math |
| GPU/CPU branching | Manual torch.cuda.is_available() checks |
Automatic |
| Large vs small data | You pick polars or pandas | Shaaha picks for you |
| Team differences | Code breaks on colleagues' machines | Zero config |
| Library upgrades | Rewriting code when switching backends | Proxy API stays the same |
Install
pip install shaaha # zero dependencies
pip install "shaaha[default]" # numpy, pandas, pillow, sklearn, matplotlib
pip install "shaaha[science]" # full scientific stack
pip install "shaaha[gpu]" # CUDA / GPU stack
Quick Start
import shaaha
# โโ DataFrames โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import shaaha.dataframe as df
# Shaaha picks polars (large data) or pandas (small) automatically
data = df.read_csv("data.csv")
# โโ Math / Arrays โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import shaaha.math as sm
# On a GPU machine โ cupy / jax. On CPU โ numpy.
arr = sm.array([1, 2, 3, 4, 5])
result = sm.sqrt(arr)
# โโ Machine Learning โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import shaaha.ml as ml
# GPU available โ torch. Otherwise โ scikit-learn / xgboost.
model = ml.LinearRegression()
# โโ Image Processing โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import shaaha.image as img
# OpenCV if installed, else Pillow โ same API either way.
image = img.open("photo.jpg")
# โโ NLP โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import shaaha.nlp as nlp
# HuggingFace Transformers โ spaCy โ NLTK (whichever is installed)
# โโ Check what's running โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
print(shaaha.status())
# {'version': '1.0.0', 'cuda_available': False, 'selected_backends': {...}}
How It Works
Shaaha uses PEP 302 Import Hooks (sys.meta_path) to intercept Python's
import machinery before it looks for physical files.
import shaaha.math
โ
โผ
ShaahafFinder (sys.meta_path[0])
โ domain = "math"
โผ
Router.resolve("math")
โ checks: CUDA? โ No. numpy installed? โ Yes.
โผ
ProxyModule wrapping numpy
โ
โผ
shaaha.math.array โ numpy.array
The ProxyModule is lazy โ nothing is imported until you access an attribute.
Initial import shaaha adds ~0ms to your startup time.
Configuration
import shaaha
shaaha.configure(
prefer_gpu=True, # Use GPU backends when available (default: True)
auto_install=False, # Offer to pip-install missing best backends
log_level="WARNING", # 'DEBUG' to see routing decisions
force_backend={ # Override routing for specific domains
"math": "numpy", # Always use numpy even if cupy is installed
}
)
Supported Domains
shaaha.<domain> |
Best backend | Fallbacks |
|---|---|---|
shaaha.math |
cupy / jax | torch โ numpy |
shaaha.dataframe |
polars | modin โ pandas โ dask |
shaaha.ml |
torch | xgboost โ lightgbm โ sklearn |
shaaha.image |
cv2 | PIL / pillow |
shaaha.nlp |
transformers | spacy โ nltk |
shaaha.viz |
plotly | altair โ seaborn โ matplotlib |
shaaha.stats |
statsmodels | scipy โ sklearn |
shaaha.http |
httpx | requests โ urllib3 |
shaaha.json |
orjson | ujson โ json (stdlib) |
Adding a New Backend (Contributing)
- Open
src/shaaha/registry.py - Add your backend to the relevant domain list:
"dataframe": [
Backend("vaex", "vaex", weight=85, tags=["large_data", "out-of-core"]),
# ... existing entries
]
- Optionally add a wrapper in
src/shaaha/wrappers/if the API differs. - Open a Pull Request โ that's it.
Project Architecture
shaaha/
โโโ src/shaaha/
โ โโโ __init__.py # Registers sys.meta_path hook
โ โโโ importer.py # PEP 302 Finder + Loader
โ โโโ router.py # Decision engine (picks the winner)
โ โโโ registry.py # Library weights & domain mappings
โ โโโ environment.py # Hardware & dependency probe
โ โโโ proxy.py # Lazy proxy module system
โ โโโ installer.py # Optional auto-pip-install
โ โโโ wrappers/ # Unified API adapters per backend
โโโ tests/
โ โโโ test_shaaha.py # 24 tests, 100% passing
โโโ pyproject.toml # PEP 621 metadata
โโโ README.md
For MSc Thesis
Shaaha implements three advanced CS concepts worth discussing in your thesis:
- Python Import Protocol (PEP 302/451) โ
sys.meta_path,MetaPathFinder,Loader - Proxy Design Pattern โ transparent delegation via
__getattr__on aModuleTypesubclass - Context-Aware Dispatch โ weighted scoring with hardware-aware overrides
License
MIT ยฉ Shaaha
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shaaha-1.0.0.tar.gz.
File metadata
- Download URL: shaaha-1.0.0.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e605b4c4bc76e4adcd19fd0cbbcd6730a2c263b84903e30bd4811f9acc927d9f
|
|
| MD5 |
fa49c7024a7aa2bcefd747420176b9fe
|
|
| BLAKE2b-256 |
571ec5641f4d5d34618439ddf5c596aaf3693ac001fb212da672f476e3dca721
|
File details
Details for the file shaaha-1.0.0-py3-none-any.whl.
File metadata
- Download URL: shaaha-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c10d4213e9ed4ac278f0315b52fddcc1852949ebe0708e5f471fb19d3b2f4fd
|
|
| MD5 |
7192314f4c0a31b7ae962d268019703f
|
|
| BLAKE2b-256 |
2b0766bc10fa6147123655c63074a4858a37be4ae6f433813625e2b669efc052
|