Skip to main content

Python SDK for Velatir - AI function monitoring and approval

Project description

Velatir Python SDK

PyPI version License: MIT

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:

  1. Sends the function details and arguments to the Velatir API
  2. 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

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

velatir-0.1.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

velatir-0.1.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file velatir-0.1.2.tar.gz.

File metadata

  • Download URL: velatir-0.1.2.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

Hashes for velatir-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e43a5fbb48c92bef6626304ce4b590e400d812ac3f9f2144e72666a965197b63
MD5 2b50708c6a9bdce0e03224589f2fc96c
BLAKE2b-256 1549b6eec6740512930d21a28960f7a9e8593f7d7a5ecbaa627b7abceda4fb8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for velatir-0.1.2.tar.gz:

Publisher: python-publish.yml on eliassorensen/velatir-demo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file velatir-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: velatir-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for velatir-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6eb2af81c3a05c025d40f6724a949e06d62526a46bf4957bef40aa976cb83c2e
MD5 be2517764560f18f2acaa4fe1c1313eb
BLAKE2b-256 a5b2717c86ea692492e17c020fc2cc5b91a1956066b964dee69045f0af99d7e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for velatir-0.1.2-py3-none-any.whl:

Publisher: python-publish.yml on eliassorensen/velatir-demo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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