Skip to main content

Intelligent Meta-Dispatcher โ€” one import, best backend, always.

Project description

Shaaha ๐Ÿง 

One import. Best backend. Always.

PyPI version Python 3.9+ License: MIT Tests

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)

  1. Open src/shaaha/registry.py
  2. Add your backend to the relevant domain list:
"dataframe": [
    Backend("vaex", "vaex", weight=85, tags=["large_data", "out-of-core"]),
    # ... existing entries
]
  1. Optionally add a wrapper in src/shaaha/wrappers/ if the API differs.
  2. 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:

  1. Python Import Protocol (PEP 302/451) โ€” sys.meta_path, MetaPathFinder, Loader
  2. Proxy Design Pattern โ€” transparent delegation via __getattr__ on a ModuleType subclass
  3. Context-Aware Dispatch โ€” weighted scoring with hardware-aware overrides

License

MIT ยฉ Shaaha

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

shaaha-1.0.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

shaaha-1.0.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

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

Hashes for shaaha-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e605b4c4bc76e4adcd19fd0cbbcd6730a2c263b84903e30bd4811f9acc927d9f
MD5 fa49c7024a7aa2bcefd747420176b9fe
BLAKE2b-256 571ec5641f4d5d34618439ddf5c596aaf3693ac001fb212da672f476e3dca721

See more details on using hashes here.

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

Hashes for shaaha-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c10d4213e9ed4ac278f0315b52fddcc1852949ebe0708e5f471fb19d3b2f4fd
MD5 7192314f4c0a31b7ae962d268019703f
BLAKE2b-256 2b0766bc10fa6147123655c63074a4858a37be4ae6f433813625e2b669efc052

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