Python SDK for Velatir - AI function monitoring and approval
Project description
Velatir Python SDK
This is the official Python SDK for Velatir, a service that allows you to monitor and approve/reject AI function calls.
Installation
pip install velatir
Quick Start
import velatir
# Initialize the SDK with your API key
velatir.init(api_key="your-api-key")
# Decorate functions you want to monitor
@velatir.watch()
async def send_email(to: str, subject: str, body: str):
"""Send an email to the customer"""
print(f"Sending email to {to}: {subject}")
# Your email sending logic here
# Call the function as usual (or from LLM tool)
await send_email("customer@example.com", "Welcome!", "Hello from Velatir!")
How It Works
The @velatir.watch() decorator intercepts function calls and:
- Sends the function details and arguments to the Velatir API
- Processes the API response:
- If
approved: The function runs immediately - If
pending: The SDK polls the API every 5 seconds until the request is approved or denied - If
denied: An exception is raised and the function doesn't run
- If
Features
- Monitor function calls in real-time
- Approve or reject function execution
- Automatically handle pending approval states
- Works with both synchronous and asynchronous functions
- Customizable polling intervals and timeout settings
Advanced Usage
Custom Polling Configuration
@velatir.watch(polling_interval=2.0, max_attempts=30)
async def delete_user(user_id: str):
"""Delete a user from the system"""
# Deletion logic here
Adding Metadata
@velatir.watch(metadata={"priority": "high", "team": "billing"})
async def charge_credit_card(card_id: str, amount: float):
"""Charge a customer's credit card"""
# Charging logic here
Logging and Retries
The SDK supports configurable logging and automatic retries for network failures:
import velatir
import logging
from velatir import LogLevel
# Configure Python's logging (optional)
logging.basicConfig(level=logging.INFO)
# Configure with logging and retries
velatir.init(
api_key="your-api-key",
log_level=LogLevel.INFO, # Or use int: 0=NONE, 1=ERROR, 2=INFO, 3=DEBUG
max_retries=3, # Number of retries for failed requests
retry_backoff=0.5 # Base backoff time (exponential)
)
# Configure Velatir's logger specifically (optional)
velatir.configure_logging(level=logging.INFO)
Synchronous Client
While the decorator works with both async and sync functions, you can also use the synchronous client methods directly:
# Get the global client
client = velatir.get_client()
# Create a watch request synchronously
response = client.create_watch_request_sync(
function_name="charge_card",
args={"card_id": "card_123", "amount": 99.99},
metadata={"priority": "high"}
)
# Wait for approval synchronously
if response.is_pending:
approval = client.wait_for_approval_sync(
request_id=response.request_id,
polling_interval=2.0
)
Error Handling
When a function is denied:
try:
await risky_function()
except velatir.VelatirWatchDeniedError as e:
print(f"Function was denied: {e}")
Documentation
For detailed documentation, visit https://docs.velatir.com
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file velatir-0.1.0.tar.gz.
File metadata
- Download URL: velatir-0.1.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7857548426b6384cf18f853364f5a0b6a824021be5612f0768a57253614667a6
|
|
| MD5 |
219626c3163573b8f5aec4f94197550f
|
|
| BLAKE2b-256 |
d7ceb54ae8f8b219925f26da23ec224fc9d2a6b50950c54f840b8d73c05a8d78
|
Provenance
The following attestation bundles were made for velatir-0.1.0.tar.gz:
Publisher:
python-publish.yml on eliassorensen/velatir-demo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
velatir-0.1.0.tar.gz -
Subject digest:
7857548426b6384cf18f853364f5a0b6a824021be5612f0768a57253614667a6 - Sigstore transparency entry: 206413588
- Sigstore integration time:
-
Permalink:
eliassorensen/velatir-demo@34de840b289443ac4a6763e03d91c7d05263ea63 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/eliassorensen
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@34de840b289443ac4a6763e03d91c7d05263ea63 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file velatir-0.1.0-py3-none-any.whl.
File metadata
- Download URL: velatir-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c978c1bd95f7442586d51a29363d1a316b3e23cd56c2e0b3f91275c11fdb1dfa
|
|
| MD5 |
5d66bc1811f836f15b00ae2440448bf9
|
|
| BLAKE2b-256 |
69078c2825097f4ba880311d8dbd57cad1e3828a92e6cf109897556084eedc04
|
Provenance
The following attestation bundles were made for velatir-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on eliassorensen/velatir-demo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
velatir-0.1.0-py3-none-any.whl -
Subject digest:
c978c1bd95f7442586d51a29363d1a316b3e23cd56c2e0b3f91275c11fdb1dfa - Sigstore transparency entry: 206413589
- Sigstore integration time:
-
Permalink:
eliassorensen/velatir-demo@34de840b289443ac4a6763e03d91c7d05263ea63 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/eliassorensen
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@34de840b289443ac4a6763e03d91c7d05263ea63 -
Trigger Event:
workflow_dispatch
-
Statement type: