Skip to main content

Python SDK for the Kavach Shield Engine ecosystem.

Project description

🛡️ rajeev02-kavach-sdk

Python Backend Client for Kavach Shield Engine


🔗 Source Code: Rajeev02/kavachid on GitHub

📖 Overview

The official Kavach Python SDK. While the frontend SDKs (React, iOS, Android) handle the user-facing biometrics, this SDK is designed strictly for Backend Microservices (FastAPI, Flask, Django, etc.). It acts as a high-level wrapper to communicate with your central Kavach Shield Engine (KSE) to evaluate user risk in real-time.

✨ Key Features

  • Risk Engine Integration: Instantly query the KSE /v1/kse/evaluate endpoint to determine if an action should be allowed, blocked, or stepped-up.
  • Async Support: Includes both synchronous (requests) and fully asynchronous (aiohttp/httpx) clients for high-concurrency FastAPI servers.
  • Webhook Verification: Cryptographically verifies incoming webhooks from the Kavach SaaS platform using HMAC-SHA256 signatures.
  • Telemetry Parsing: Helper methods to parse and validate x-device-fingerprint headers sent by frontend clients.

🏆 Why Use This Library?

  • Decoupled Security: Keeps complex security logic out of your main business applications. Let the Shield Engine handle the risk matrix.
  • Zero-Trust Enforcement: Easily wrap sensitive API routes with decorators that automatically enforce risk policies.
  • High Performance: Connection pooling ensures minimal latency overhead when evaluating risk.

🚀 Installation (PyPI)

pip install rajeev02-kavach-sdk

💻 Detailed Usage

1. Basic Risk Evaluation

from kavach.sdk import KavachShieldClient
from kavach.models import ActionType, SecurityLevel

client = KavachShieldClient("https://api.yourdomain.com", api_key="sk_live_123")

def perform_bank_transfer(user_id, amount, request):
    # Evaluate the risk BEFORE executing the business logic
    decision = client.evaluate(
        user_id=user_id,
        action_type=ActionType.FINANCIAL_TRANSFER,
        security_level=SecurityLevel.CRITICAL,
        ip_address=request.client.host,
        device_fingerprint=request.headers.get("x-device-fingerprint")
    )

    if decision.status == "DENY":
        raise Exception("Access Denied: High Risk Detected")
    elif decision.status == "STEP_UP_REQUIRED":
        raise Exception("401 MFA Required: Please provide biometric verification")

    # Proceed with transfer if status == "ALLOW"
    return "Transfer successful"

2. FastAPI Decorator Example

from fastapi import FastAPI, Depends
from kavach.sdk.fastapi import require_risk_level

app = FastAPI()

@app.post("/api/v1/delete-account")
@require_risk_level(SecurityLevel.CRITICAL)
async def delete_account():
    # If the user's current session doesn't meet the risk threshold,
    # the decorator automatically returns a 403 or 401 demanding biometrics.
    pass

🌐 The Kavach Ecosystem

Kavach provides native SDKs for all major platforms:

Platform Source Code (GitHub) Package Registry
🌍 Web Source Code NPM: @rajeev02/kavach-web
📱 React Native Source Code NPM: @rajeev02/kavach-react-native
🍎 iOS (Swift) Source Code CocoaPods: KavachSDK
🤖 Android (Kotlin) Source Code Maven: io.github.rajeev02.kavach
🐦 Flutter Source Code Pub.dev: kavach_flutter
🐍 Python Source Code PyPI: rajeev02-kavach-sdk
🐹 Go Source Code pkg.go.dev

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

rajeev02_kavach_sdk-1.0.4.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

rajeev02_kavach_sdk-1.0.4-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file rajeev02_kavach_sdk-1.0.4.tar.gz.

File metadata

  • Download URL: rajeev02_kavach_sdk-1.0.4.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for rajeev02_kavach_sdk-1.0.4.tar.gz
Algorithm Hash digest
SHA256 642185ac9bde708f81dd589970cc19b06f7b90572f76e1b6f956b3d7bdef75b9
MD5 da237bc1b02206a4a5fc740452f8d09a
BLAKE2b-256 12ced1ff9b8a1f5cc0dba6cc7902227e6c3945f01e8824adac54d5cf73340a28

See more details on using hashes here.

File details

Details for the file rajeev02_kavach_sdk-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for rajeev02_kavach_sdk-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cc04d24dbd15dc2c7596f23ff33f08ffdf29779dafc963dae6e71ab6977dd510
MD5 a1335b81af374766bb333454b876ceb3
BLAKE2b-256 dafb2850921a24abdd1396e72af36712d9779e618f5b180ded5c61076a222897

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