Skip to main content

Proprietary SDK for Revgate services

Project description

Revgate SDK

The Revgate SDK provides a simple interface for tracing, billing, and observing your AI applications. It supports both manual event tracking and automatic instrumentation for popular AI libraries.

1. SDK Structure

The SDK is organized into the following modules:

  • revgate: Top-level package exposing the main Revgate client and key functions.
  • revgate.client: Contains the Revgate class for managing the connection and accessing sub-clients (e.g., billing).
  • revgate.tracing: The core tracing module.
    • revgate.tracing.core: Handles OpenTelemetry (OTEL) integration and span management.
    • revgate.tracing.events: Defines custom event tracking (e.g., billing events).
    • revgate.tracing.autoinstrumentation: Provides automatic instrumentation for AI libraries.
  • revgate.logger: Centralized logging configuration.

2. Usage

Installation

Basic Installation (Core) Lightweight install with just the core dependencies.

pip install revgate-python

With Specific Integrations Install support for specific AI libraries to enable auto-instrumentation.

# For specific providers
pip install "revgate-python[openai]"
pip install "revgate-python[anthropic,langchain]"
pip install "revgate-python[google-genai]"

# For all supported integrations
pip install "revgate-python[all]"

Development Setup For contributors or local development, install in editable mode with all features.

# From the root of the repository
pip install -e ".[all]"

Auto-Instrumentation

Revgate can automatically trace calls to supported AI libraries like Google GenAI, OpenAI, Anthropic, and LangChain. This captures spans, prompts, completions, and token usage without manual instrumentation.

Example with Google GenAI:

import os
from revgate import auto_instrument, Revgate

# 1. Initialize Auto-Instrumentation
# This must be called before using the AI library.
# Supported libraries: "google-genai", "openai", "anthropic", "langchain"
auto_instrument(["google-genai"])

# 2. Use the AI library as usual
from google import genai

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
response = client.chats.create(model='gemini-1.5-flash').send_message("Hello!")

print(response.text)
# A trace is automatically generated and sent to the configured OTEL collector.

Manual Event Tracking (Billing)

For custom business logic or billing events that are not captured by auto-instrumentation, you can use track_event.

Example:

from revgate import Revgate

client = Revgate()

# Track a billable event
client.billing.track_event(
    name="llm_call",
    metadata={
        "model": "gemini-1.5-flash",
        "tokens": 150,
        "cost": 0.00015,
        "currency": "USD",
        "user_id": "user_123"
    }
)

# Track a signal (non-billable)
client.billing.track_event(
    name="tool_execution",
    metadata={
        "tool": "search_db",
        "status": "success"
    }
)

Configuration

The SDK uses environment variables for configuration:

  • REVGATE_ENABLED: Enable/disable tracing and event tracking (default: true).
  • REVGATE_BASE_URL: Revgate base URL (default: http://dev.revgate.com).
  • REVGATE_API_KEY: Your Revgate API key.
  • REVGATE_OTEL_EXPORTER_TYPE: OTLP exporter type - proto or json (default: proto).
  • REVGATE_OTEL_EXPORT_MODE: Span export mode - batch or simple (default: batch).
  • REVGATE_ENABLE_CONSOLE_LOGGING: Enable console span exporter for debugging (default: false).
  • REVGATE_LOG_LEVEL: Logging level (default: INFO).

3. Development & Release

Local Development

To set up the environment for development:

# Install in editable mode with all dependencies
pip install -e ".[all]"

Building the Package

To build the distribution files (wheel and source archive) locally:

  1. Install build tools:

    pip install build
    
  2. Run the build:

    python -m build
    

    This creates a dist/ directory containing the .whl and .tar.gz files.

  3. Install the built wheel:

    pip install dist/*.whl
    # Note: Validates that the package installs correctly.
    

Publishing (Manual)

To verify the upload or publish manually:

  1. Install Twine:

    pip install twine
    
  2. Upload:

    twine upload dist/*
    

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

revgate_python-0.1.0b2.tar.gz (42.8 kB view details)

Uploaded Source

Built Distribution

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

revgate_python-0.1.0b2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file revgate_python-0.1.0b2.tar.gz.

File metadata

  • Download URL: revgate_python-0.1.0b2.tar.gz
  • Upload date:
  • Size: 42.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for revgate_python-0.1.0b2.tar.gz
Algorithm Hash digest
SHA256 af3e32bac37dbfe4576ef328bb8d6d992d6cee7e1d109c94c0ce9dd74a8d346f
MD5 ea023fa4282cefbf1b54381451639b8a
BLAKE2b-256 45decbce26f0e722c5855f58b6493566bf3885c9d195c71725a1c6b726674413

See more details on using hashes here.

Provenance

The following attestation bundles were made for revgate_python-0.1.0b2.tar.gz:

Publisher: publish.yml on Revgate/revgate-python-sdk

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

File details

Details for the file revgate_python-0.1.0b2-py3-none-any.whl.

File metadata

File hashes

Hashes for revgate_python-0.1.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 454fa72543de5828d8d09c77c62da26e65a7e97bfe70a1bc2745e972a0500edd
MD5 ee04781c8da4d8ea35d15efe03e087b0
BLAKE2b-256 0ee1a73ba57c28f5e88979e85ca75e5ff24397573369b4a04cab747847e13153

See more details on using hashes here.

Provenance

The following attestation bundles were made for revgate_python-0.1.0b2-py3-none-any.whl:

Publisher: publish.yml on Revgate/revgate-python-sdk

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