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.1.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.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: velatir-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 5766fa6d5ef43f35c827b98f758f485bcd03b99186c84df435e57dde01ddb7ea
MD5 68f8edda7a217ead5ff8656b4691ffcd
BLAKE2b-256 e5e63ab83126dc6d46267b5fa2001420d34e8e1e2ac476bf8497505106ff16a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for velatir-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: velatir-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4919469e7888c876149097888f69985094fb7eb04317e03396d7602ca87a3cac
MD5 252d643d240ecb25060a3f447133685a
BLAKE2b-256 8e1bcf95ff87eefed03dbab340f9efa191dd90552dc33075f134f99a91c71cd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for velatir-0.1.1-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