Skip to main content

Intelligent Meta-Dispatcher โ€” AI-powered backend selection, agent execution, and code optimization.

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-2.0.0.tar.gz (43.2 kB view details)

Uploaded Source

Built Distribution

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

shaaha-2.0.0-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file shaaha-2.0.0.tar.gz.

File metadata

  • Download URL: shaaha-2.0.0.tar.gz
  • Upload date:
  • Size: 43.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for shaaha-2.0.0.tar.gz
Algorithm Hash digest
SHA256 291a20ac9891ce10eb031a794cc04bf6b397f8a722f4b5f7ee0228cf0a288f1c
MD5 b514fbbc84a9b2e5820d434eb9b0c238
BLAKE2b-256 7e8bd7e1a928fec2631abfd458a636e39726a92d50b02f642b7dda3403021e76

See more details on using hashes here.

File details

Details for the file shaaha-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: shaaha-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 42.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for shaaha-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3b4ba280b5132671ca539393939258706532831031c1bb98dbbb35b3de357fe
MD5 b2a0d880c09659f17e4d30b70291d6a3
BLAKE2b-256 c7f444bf4534fd36ef5d5cef5da8697cfdb3d53a7161fb8ab67c8b8c5bb04446

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