Skip to main content

Revos

A Python library for custom LLM APIs authentication and LangChain-based LLM tools with support for multiple LLM models and robust configuration management. In this text and examples we use definition Revos API, which is a placeholder for any custom LLM API provider requiring customisation of authentication logic, auth token management.

Why Choose Revos? 🚀

🔐 Enterprise-Grade Authentication

  • Dual Authentication: OAuth 2.0 with automatic fallback mechanisms
  • Automatic Token Management: Background refresh with configurable intervals
  • Zero Downtime: Seamless token rotation without interrupting your application
  • Security First: Built-in token validation and secure credential handling

🤖 Advanced LLM Integration

  • Multiple Model Support: Use GPT-4, Claude, and other models simultaneously
  • Structured Data Extraction: Convert unstructured text into structured data with Pydantic models
  • LangChain Integration: Leverage the full power of LangChain ecosystem
  • OpenAI-Compatible: Works with any OpenAI-compatible API through Revos

⚡ Production-Ready Features

  • Observer Pattern: Automatic token updates across all components with zero duplicate requests
  • Background Services: Non-blocking token refresh with asyncio support
  • Efficient Token Management: Single TokenManager serves all extractors
  • Robust Error Handling: Comprehensive retry logic and fallback mechanisms
  • Flexible Configuration: Environment variables, YAML, JSON, and programmatic setup

🛠️ Developer Experience

  • Zero Configuration: Works out of the box with sensible defaults
  • Custom Prefixes: Avoid conflicts with multiple applications
  • FastAPI Ready: Built-in FastAPI integration patterns
  • Comprehensive Testing: 131+ tests ensuring reliability
  • Latest Version: v0.2.1 — model discovery CLI + clearer invalid-model errors
  • CLI: revos models lists gateway-accepted model ids

📈 Scalability & Performance

  • Zero Duplicate Requests: Observer Pattern eliminates redundant token API calls
  • Memory Optimized: Smart caching and resource management
  • Concurrent Safe: Thread-safe operations for high-traffic applications
  • Monitoring Ready: Built-in logging and observability features
  • Immediate Availability: Extractors get tokens instantly upon registration

Revos vs Alternatives

Feature Revos Direct OpenAI LangChain Only Custom Solution
Token Management ✅ Automatic ❌ Manual ❌ Manual ⚠️ Custom
Multiple Models ✅ Built-in ❌ Separate ⚠️ Complex ⚠️ Custom
Background Refresh ✅ Yes ❌ No ❌ No ⚠️ Custom
Observer Pattern ✅ Zero Duplicate Requests ❌ No ❌ No ⚠️ Custom
Configuration ✅ Flexible ❌ Basic ⚠️ Limited ⚠️ Custom
Error Handling ✅ Robust ⚠️ Basic ⚠️ Basic ⚠️ Custom
Testing ✅ 131+ Tests ❌ None ⚠️ Limited ⚠️ Custom
FastAPI Integration ✅ Ready ⚠️ Manual ⚠️ Manual ⚠️ Custom

Perfect For

🏢 Enterprise Applications

  • High Availability: Automatic token refresh ensures zero downtime
  • Multi-Tenant: Custom prefixes for different clients
  • Scalable: Background services handle token management
  • Monitoring: Built-in logging and observability

🤖 AI/ML Applications

  • Multiple Models: Use GPT-4, Claude, and others simultaneously
  • Structured Data: Extract structured data from unstructured text
  • LangChain Integration: Leverage the full LangChain ecosystem
  • Production Ready: Robust error handling and retry logic

🚀 FastAPI Applications

  • Async Support: Non-blocking token refresh with asyncio
  • Background Tasks: Automatic token management in background
  • Easy Integration: Built-in FastAPI patterns and examples
  • Zero Configuration: Works out of the box

📊 Data Processing Pipelines

  • Batch Processing: Efficient token management for large datasets
  • Concurrent Operations: Thread-safe operations for parallel processing
  • Error Recovery: Comprehensive retry logic and fallback mechanisms
  • Resource Optimization: Smart caching and memory management

Features

  • 🔐 Revos API Authentication: Dual authentication methods with automatic fallback
  • 🤖 LangChain Integration: Structured data extraction using LLMs
  • ⚙️ Multiple LLM Models: Support for multiple models with different configurations
  • 🔄 Token Management: Automatic token refresh with configurable intervals
  • 🔄 Observer Pattern: Extractors automatically get updated tokens with zero duplicate requests
  • ⚡ Efficient Architecture: Single TokenManager serves all extractors
  • 🛡️ Robust Error Handling: Comprehensive retry logic and fallback mechanisms
  • 🔧 Flexible Configuration: Environment variables, YAML, JSON, and programmatic configuration
  • 📊 OpenAI-Compatible: Works with OpenAI-compatible APIs through Revos
  • 🌍 Custom Prefixes: Support for custom environment variable prefixes to avoid conflicts
  • 🧭 Model discovery: list_remote_models() and revos models CLI against GET /models

Installation

From PyPi

uv add revos
# or
pip install revos

# CLI (lists gateway model ids)
uv run revos models
# or after install:
revos models

From Source

git clone https://github.com/kavodsky/revos.git
cd revos
uv sync
# or: pip install -e .

Development Installation

git clone https://github.com/kavodsky/revos.git
cd revos
pip install -e ".[dev]"

Quick Start

1. Environment Configuration

Create a .env file with your Revos API credentials:

# Required Revos API credentials
REVOS_CLIENT_ID=your_client_id
REVOS_CLIENT_SECRET=your_client_secret
REVOS_TOKEN_URL=https://api.revos.com/token
REVOS_BASE_URL=https://api.revos.com

# Optional: Token management settings
REVOS_TOKEN_BUFFER_MINUTES=5
REVOS_TOKEN_REFRESH_INTERVAL_MINUTES=45

# LLM Models configuration
# IMPORTANT: set MODEL to an id from `revos models` / list_remote_models()
LLM_MODELS_GPT_4_MODEL=gpt-4
LLM_MODELS_GPT_4_TEMPERATURE=0.1
LLM_MODELS_GPT_4_MAX_TOKENS=2000

LLM_MODELS_CLAUDE_MODEL=<id-from-revos-models>
LLM_MODELS_CLAUDE_TEMPERATURE=0.3
LLM_MODELS_CLAUDE_MAX_TOKENS=4000

Discover valid gateway model identifiers before configuring:

revos models
# or
uv run revos models --env-file .env
from revos import list_remote_models

print(list_remote_models())

2. Basic Usage

from revos import get_langchain_extractor
from pydantic import BaseModel

# Define your data schema
class PersonInfo(BaseModel):
    name: str
    age: int
    occupation: str
    location: str

# Create an extractor (automatically handles token acquisition)
extractor = get_langchain_extractor("gpt-4")

# Extract structured data
result = extractor.extract(
    text="John Doe is 30 years old and works as a software engineer in San Francisco.",
    schema=PersonInfo
)

print(result)  # PersonInfo(name="John Doe", age=30, occupation="software engineer", location="San Francisco")

3. Token Management with Observer Pattern

from revos import TokenManager, get_langchain_extractor
import asyncio

# Create token manager with background refresh
token_manager = TokenManager(refresh_interval_minutes=45)

# Or with custom settings (refresh interval taken from config)
token_manager = TokenManager(settings_instance=config)

# Create extractors (they automatically register for token updates)
# Extractors get tokens immediately via Observer Pattern - no duplicate requests!
extractor1 = get_langchain_extractor("gpt-4")  # Gets token instantly
extractor2 = get_langchain_extractor("claude-4")  # Gets token instantly

# Start background token refresh service
# All extractors automatically get updated tokens via Observer Pattern!
async def main():
    await token_manager.start_background_service()
    # Your application code here
    # Extractors automatically use fresh tokens with zero duplicate requests
    await token_manager.stop_background_service()

asyncio.run(main())

4. Observer Pattern Benefits

The Observer Pattern implementation provides several key advantages:

# ✅ EFFICIENT: Single TokenManager serves all extractors
token_manager = TokenManager(settings_instance=config)

# ✅ IMMEDIATE: Extractors get tokens instantly upon creation
extractor1 = get_langchain_extractor("gpt-4")  # Token provided immediately
extractor2 = get_langchain_extractor("claude-4")  # Token provided immediately

# ✅ AUTOMATIC: All extractors get updated tokens automatically
# No duplicate API calls, no manual token management needed!

Key Benefits:

  • Zero Duplicate Requests: Extractors don't make their own token requests
  • Immediate Availability: Extractors are ready to use instantly
  • Automatic Updates: All extractors get fresh tokens automatically
  • Resource Efficient: Single TokenManager handles all token operations
  • Thread Safe: Concurrent operations with proper synchronization

Configuration Options

Environment Variables

Variable Description Default
REVOS_CLIENT_ID Revos API client ID Required
REVOS_CLIENT_SECRET Revos API client secret Required
REVOS_TOKEN_URL OAuth token endpoint URL Required
REVOS_BASE_URL Revos API base URL Required
REVOS_TOKEN_BUFFER_MINUTES Token refresh buffer time 5
REVOS_TOKEN_REFRESH_INTERVAL_MINUTES Token refresh interval 45
LLM_MODELS_* LLM model configurations See LLM Models Guide

Custom Environment Variable Prefixes

If you need to use different prefixes (e.g., to avoid conflicts), you can use custom prefixes:

from revos import create_config_with_prefixes

# Create configuration with custom prefixes
config = create_config_with_prefixes(
    revo_prefix="MYAPP_",
    llm_prefix="MYAPP_LLM_",
    logging_prefix="MYAPP_LOG_",
    token_prefix="MYAPP_TOKEN_"
)

# Use with custom settings
token_manager = TokenManager(settings_instance=config)
extractor = get_langchain_extractor("gpt-4", settings_instance=config)

Documentation

Examples

Development

Latest Improvements (v0.2.0)

  • list_remote_models() / revos models: Discover ids the gateway actually accepts
  • Clearer invalid-model errors: include tried model + live /models list
  • Typer CLI: revos models, revos configured-models, revos version
  • Removed legacy LLMConfig: configure models only via llm_models / LLM_MODELS_*
  • Example defaults: marked EXAMPLE ONLY; dropped guessed claude-4-sonnet default

See CHANGELOG and RELEASE_NOTES_0.2.0.md.

Running Tests

# Run all tests
pytest

# Run specific test file
pytest tests/test_background_custom_settings.py -v

# Run with coverage
pytest --cov=revos

Building Documentation

# Build documentation
mkdocs build

# Serve documentation locally
mkdocs serve

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For questions, issues, or contributions, please visit our GitHub repository.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

revos-0.2.1.tar.gz (57.4 kB view details)

Uploaded Source

Built Distribution

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

revos-0.2.1-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file revos-0.2.1.tar.gz.

File metadata

  • Download URL: revos-0.2.1.tar.gz
  • Upload date:
  • Size: 57.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for revos-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5078a006bb32f71ca93af9142306b6db3aed50dee678d047407c4055ff7c95cb
MD5 c8d34fa968fb0e28a7409b21931d684e
BLAKE2b-256 7ceccaa0121bc8aa5abd3bcc9421986d209635ca4b797ea2af77dce909d25f82

See more details on using hashes here.

File details

Details for the file revos-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: revos-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 43.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for revos-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78f35137a39c0ae4835c8818c6c73ae51693be3e2abe9e42cece77f2c7a85d5b
MD5 a9c5d43c6cdb4122c126e37af877c36b
BLAKE2b-256 8490e58c238b5d51dc824834de0312cefd0960487f117994dad0c540c686f62f

See more details on using hashes here.

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