
Product
Introducing Data Exports
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.
shivad
Advanced tools
Shiva is a modern, async Python framework for distributed systems and microservices. It provides a modular architecture for building scalable, event-driven applications, supporting protocols like RMQ, web APIs, metrics, and more. Shiva is built around the concept of dispatchers, protocols, workers, and drivers, enabling flexible orchestration of background tasks, message processing, and service integration.
To install Shiva, simply run:
pip install shivad
Flow Example:
A dispatcher (e.g., RMQ) receives a message, uses a protocol (e.g., JSON_Routed_BPM) to determine which worker should handle it, and the worker processes the message, possibly using a driver (e.g., Postgres) to interact with a database.
shiva/
common/ # Core abstractions (base classes, config, CLI, dispatcher logic)
commands/ # CLI commands (Typer-based)
dispatchers/ # Dispatcher implementations (RMQ, web, metrics, daemon)
drivers/ # Drivers for databases, ESB, APIs
proto/ # Protocols for message routing/handling
workers/ # Example and real workers (metrics, web, daemon, etc.)
examples/ # Example workers and usage
lib/ # Utilities (config loader, tools)
main.py # FastAPI app entrypoint
run.py # CLI entrypoint
shiva_cli.py # CLI loader
BaseDispatcherprepare, start, stop).name, coro, policy, connection, proto, etc.BaseWorker, BaseDaemon, BaseRmqWorker, BaseMetricprepare, start, stop methods.BaseDriverprepare, stop.BaseProtocolshiva/dispatchers/rmq.py): Handles RabbitMQ message consumption, manages exchanges/queues, and dispatches messages to workers via protocol.shiva/dispatchers/web.py): Integrates FastAPI routers from workers, mounts them to the main app.shiva/dispatchers/daemon.py): Manages daemon-style workers (background loops).shiva/dispatchers/metrics.py): Exposes Prometheus metrics endpoints and manages metric workers.shiva/proto/rmq_simple.py): Simple protocol that dispatches all messages to all workers.shiva/proto/bpm.py): Publishes messages with routing keys and metadata.shiva/drivers/databases/postgres.py): Asyncpg-based connection pool.shiva/drivers/databases/redis.py): Redis (async) connection pool.shiva/drivers/databases/mongodb.py): Motor-based async MongoDB client.shiva/drivers/api/s3_aiobotocore.py): Async S3 client using aiobotocore.shiva/examples/workers/benchmark/rmq_bench.py): Benchmarks RMQ message handling.shiva/examples/workers/mydaemon/daemon_1.py): Simple background loop.shiva/examples/workers/web/healthcheck.py): FastAPI endpoints for readiness/liveness.shiva/workers/metrics/some_metrics.py): Prometheus metrics example.from shiva.common.base import BaseRmqWorker
from shiva.common.rmq_routing import Router
router = Router()
class RmqBench(BaseRmqWorker):
name = 'shiva_benchmark'
dispatcher = 'shiva_bench'
async def prepare(self):
pass
@router.route('shiva.bench')
async def bench(self, message, raw=None):
# Process message
pass
from shiva.common.base import BaseDaemon
class MyDaemon(BaseDaemon):
name = 'first_shiva_daemon'
async def start(self):
self.running = True
while self.running:
# Do work
await asyncio.sleep(5)
from fastapi import APIRouter
from shiva.common.base import BaseWorker
from shiva.dispatchers.web import Web
router = APIRouter(prefix='')
class Healthcheck(BaseWorker):
name = 'healthcheck'
dispatcher = Web
@router.get("/readiness")
def read():
return {"status": "ok"}
from prometheus_client import Counter, Gauge
from shiva.common.base import BaseMetric
class MyMetric(BaseMetric):
name = 'my_metric'
dispatcher = 'metrics_main'
async def start(self):
g = Gauge('my_gauge_metric', 'Some metric')
c = Counter('my_counter', 'test_counter')
self.running = True
while self.running:
g.inc()
c.inc(1.2)
await asyncio.sleep(5)
app_name: shiva_test
common:
uvloop: True
coro_num: 1
modules_path: './modules'
logging:
level: DEBUG
sentry:
dsn: <sentry_dsn>
environment: 'LOCAL'
connections:
postgres:
driver: postgres
config:
dsn: postgresql://postgres:@127.0.0.1:5432/mydb
pool_min: 1
pool_max: 50
max_inactive_connection_lifetime: 300
max_queries: 20
redis:
driver: redis
config:
dsn: redis://127.0.0.1:6379/0
minsize: 1
maxsize: 1
rmq_default:
driver: rmq
config:
dsn: amqp://guest:guest@127.0.0.1:5672/myvenv
dispatchers:
web:
name: web
dispatcher: dispatcher_web
enabled: true
daemon_root_main:
name: daemon_root_main
dispatcher: daemon_root
enabled: true
policy: CONFIG
coro: 1
config:
echo: I'm alive!
shiva_bench:
name: shiva_bench
dispatcher: rmq
connection: rmq_default
proto: JSON_Routed_BPM
enabled: false
coro: 1
config:
exchanges:
ESB:
config:
type: topic
durable: true
queues:
shiva_benchmark:
coro: 5
config:
prefetch: 1
arguments:
auto_delete: false
durable: true
additional:
max-length: 1000
bindings:
- shiva.bench
workers:
waiter_daemon:
name: waiter1
coro: 1
enabled: true
worker: waiter_daemon
dispatcher: daemon_root_main
config:
echo: Hello!
depends:
databases:
- postgres
esb:
- rmq
You can extend Shiva by loading drivers, workers, dispatchers, and protocols from installed packages. This allows you to create reusable extensions.
Loading Order: shiva (built-in) → user (local) → packages (installed)
Example:
scopes:
packages:
- my_shiva_extension
- another_extension
For a package my_shiva_extension, Shiva will attempt to load:
my_shiva_extension.driversmy_shiva_extension.workersmy_shiva_extension.dispatchersmy_shiva_extension.protomy_shiva_extension.data_typesPackage Structure Example:
my_shiva_extension/
drivers/
databases/
my_custom_db.py
workers/
my_worker.py
dispatchers/
my_dispatcher.py
Modules are deduplicated by file path - first found wins. Missing scopes are silently skipped.
shiva_bench:
name: shiva_bench
dispatcher: rmq
connection: rmq_default
proto: JSON_Routed_BPM
enabled: false
coro: 1
config:
exchanges:
ESB:
config:
type: topic
durable: true
queues:
shiva_benchmark:
coro: 5
config:
prefetch: 1
arguments:
auto_delete: false
durable: true
additional:
max-length: 1000
bindings:
- shiva.bench
waiter_daemon:
name: waiter1
coro: 1
enabled: true
worker: waiter_daemon
dispatcher: daemon_root_main
config:
echo: Hello!
depends:
databases:
- postgres
esb:
- rmq
BaseProtocol and implement dispatch.BaseDriver and implement prepare and stop.shiva (see pyproject.toml and shiva_cli.py)shiva/commands/ modules.import typer
app = typer.Typer()
@app.command()
def hello(name: str):
"""Say hello."""
print(f"Hello, {name}!")
if __name__ == "__main__":
app()
shiva/commands/ and ensure it is loaded via CommandHelper.Run the main app:
python shiva/run.py
or via CLI:
shiva daemon run
Configuration:
Set SHIVA_CONFIG env variable or use ./config.yml.
Tests:
There are example test commands in shiva/commands/test.py.
To run:
python -m shiva.commands.test test
This project is licensed under the MIT License. See the LICENSE file for details.
End of Documentation
FAQs
A modern, async Python framework for distributed systems and microservices.
We found that shivad demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.

Research
/Security News
Bitwarden CLI 2026.4.0 was compromised in the Checkmarx supply chain campaign after attackers abused a GitHub Action in Bitwarden’s CI/CD pipeline.

Research
/Security News
Docker and Socket have uncovered malicious Checkmarx KICS images and suspicious code extension releases in a broader supply chain compromise.