Python SDK
The official Python SDK for LogVault. Supports Python 3.8+ with both sync and async clients.
Installation
Bash
1pip install logvault
Quick Start
Python
1import logvault23# Initialize the client4client = logvault.Client("lv_live_your_key_here")56# Log an event7client.log(8 action="user.login",9 user_id="user_123",10 resource="dashboard",11 metadata={12 "ip": "192.168.1.1",13 "browser": "Chrome"14 }15)
Async Support
For async applications (FastAPI, aiohttp, etc.), use the async client:
Python
1import logvault23# Initialize async client4client = logvault.AsyncClient("lv_live_your_key_here")56# Log an event (await required)7await client.log(8 action="user.login",9 user_id="user_123"10)
Configuration Options
Python
1client = logvault.Client(2 api_key="lv_live_...",3 base_url="https://api.logvault.eu", # Default4 timeout=30, # Request timeout in seconds5 max_retries=3 # Retry failed requests6)
Error Handling
Python
1from logvault.exceptions import (2 LogVaultError,3 AuthenticationError,4 ValidationError,5 RateLimitError6)78try:9 client.log(action="user.login", user_id="123")10except AuthenticationError:11 print("Invalid API key")12except ValidationError as e:13 print(f"Invalid data: {e}")14except RateLimitError:15 print("Rate limit exceeded, retry later")16except LogVaultError as e:17 print(f"LogVault error: {e}")
Django Integration
Python
1# settings.py2LOGVAULT_API_KEY = os.environ.get("LOGVAULT_API_KEY")34# views.py5import logvault6from django.conf import settings78client = logvault.Client(settings.LOGVAULT_API_KEY)910def login_view(request):11 # ... authentication logic ...12 client.log(13 action="user.login",14 user_id=str(user.id),15 metadata={"ip": request.META.get("REMOTE_ADDR")}16 )17 return redirect("dashboard")
FastAPI Integration
Python
1from fastapi import FastAPI, BackgroundTasks2import logvault34app = FastAPI()5client = logvault.AsyncClient(os.environ["LOGVAULT_API_KEY"])67@app.post("/login")8async def login(background_tasks: BackgroundTasks):9 # ... authentication logic ...1011 # Log in background (non-blocking)12 background_tasks.add_task(13 client.log,14 action="user.login",15 user_id=user_id16 )17 return {"status": "ok"}
Chain Integrity Verification
LogVault uses cryptographic hash chaining to ensure audit logs cannot be tampered with. Use these methods to verify chain integrity:
Python
1# Verify the entire audit log chain2result = client.verify_chain()3print(f"Chain valid: {result['is_valid']}")4print(f"Events verified: {result['events_checked']}")56# Get chain statistics7stats = client.get_chain_stats()8print(f"Chain coverage: {stats['chain_coverage']}%")910# Get cryptographic proof for a specific event11proof = client.get_event_proof("event_id_here")12print(f"Chain hash: {proof['proof']['chain_hash']}")1314# Verify event locally (offline, zero-trust)15local_result = client.verify_event_locally(proof['event'])16print(f"Local verification: {local_result['is_valid']}")
Semantic Search
Search your audit logs using natural language queries:
Python
1# Search for events2results = client.search_events("failed login attempts")3for event in results['results']:4 print(f"{event['action']} - {event['user_id']}")