Skip to main content

A Python library for secret management and API proxy calls

Project description

Double-O

A Python library for secret management and API proxy calls.

Installation

pip install double-o

Quick Start

Fetching Secrets

import oo

# Simple one-liner to fetch a secret
secret = oo.get_secret("YOUR_TOKEN_HERE")
print(f"Secret: {secret}")

Making Proxy API Calls

import oo

# Make an API call through the proxy
result = oo.proxy(
    "v1/chat/completions",
    token="YOUR_PROXY_TOKEN",
    payload={
        "model": "gpt-4o-mini",
        "messages": [{"role": "user", "content": "Hello!"}]
    }
)
print(result)

Chat Completions (Convenience Method)

import oo

# Even simpler for chat completions
result = oo.chat(
    token="YOUR_PROXY_TOKEN",
    messages=[{"role": "user", "content": "Hello!"}],
    model="gpt-4o-mini"
)
print(result)

Advanced Usage

Using the Client Class

For more control, use the Client class directly:

from oo import Client

# Create a client with custom settings
client = Client(
    base_url="http://localhost:3001",
    timeout=60
)

# Fetch a secret
secret = client.get_secret("YOUR_TOKEN")

# Make proxy calls
result = client.proxy(
    "v1/chat/completions",
    token="YOUR_PROXY_TOKEN",
    payload={"model": "gpt-4o-mini", "messages": []}
)

# Don't forget to close when done
client.close()

Context Manager

The client supports context managers for automatic cleanup:

from oo import Client

with Client(base_url="http://localhost:3001") as client:
    secret = client.get_secret("YOUR_TOKEN")
    # Client is automatically closed when exiting the block

Custom Base URL

All functions accept a base_url parameter:

import oo

# Use a different server
secret = oo.get_secret(
    "YOUR_TOKEN",
    base_url="http://your-server:8080"
)

Error Handling

The library provides custom exceptions for different error scenarios:

import oo
from oo import SecretError, ProxyError, AuthenticationError

try:
    secret = oo.get_secret("invalid_token")
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except SecretError as e:
    print(f"Failed to fetch secret: {e}")

try:
    result = oo.proxy("v1/endpoint", "invalid_token", payload={})
except AuthenticationError as e:
    print(f"Proxy authentication failed: {e}")
except ProxyError as e:
    print(f"Proxy request failed: {e}")

Exception Hierarchy

  • DoubleOError - Base exception for all Double-O errors
    • SecretError - Raised when fetching a secret fails
    • ProxyError - Raised when a proxy request fails
    • AuthenticationError - Raised when authentication fails

API Reference

Functions

oo.get_secret(token, base_url="http://localhost:3001")

Fetch a secret value using a token.

  • token (str): The authentication token
  • base_url (str): API server URL (default: http://localhost:3001)
  • Returns: The secret value as a string
  • Raises: SecretError, AuthenticationError

oo.proxy(path, token, method="POST", payload=None, headers=None, base_url="http://localhost:3001")

Make an API call through the proxy.

  • path (str): API path (e.g., 'v1/chat/completions')
  • token (str): Proxy authentication token
  • method (str): HTTP method (default: POST)
  • payload (dict): Request payload (optional)
  • headers (dict): Additional headers (optional)
  • base_url (str): API server URL (default: http://localhost:3001)
  • Returns: JSON response as a dictionary
  • Raises: ProxyError, AuthenticationError

oo.chat(token, messages, model="gpt-4o-mini", base_url="http://localhost:3001", **kwargs)

Convenience function for OpenAI chat completions.

  • token (str): Proxy authentication token
  • messages (list): List of message dicts with 'role' and 'content'
  • model (str): Model to use (default: gpt-4o-mini)
  • base_url (str): API server URL (default: http://localhost:3001)
  • kwargs: Additional parameters for the API
  • Returns: Chat completion response

Client Class

Client(base_url="http://localhost:3001", timeout=30)

Create a new Double-O client.

  • base_url (str): API server URL
  • timeout (int): Request timeout in seconds

Methods:

  • get_secret(token) - Fetch a secret
  • proxy(path, token, method="POST", payload=None, headers=None) - Make proxy call
  • chat_completion(token, messages, model="gpt-4o-mini", **kwargs) - Chat completion
  • close() - Close the client session

Development

Setup

# Clone the repository
git clone https://github.com/yourusername/double-o.git
cd double-o

# Install development dependencies
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black oo tests
isort oo tests

Type Checking

mypy oo

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

double_o-0.1.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

double_o-0.1.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file double_o-0.1.3.tar.gz.

File metadata

  • Download URL: double_o-0.1.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for double_o-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8a0e3088797ec7c30b531587787a45b5ad691f60e1a8e03ee088fc5051b8fb6b
MD5 aaa5d858a1555ee2a1d16f78ca9953b1
BLAKE2b-256 65a8d7b94ca2710341692402a7c72b4985eee190fc2cbe0ea02b0501bc84b414

See more details on using hashes here.

File details

Details for the file double_o-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: double_o-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for double_o-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8f5b2b57edfb751931b6287f0f819fb1f1e70e1f30775d716b84c9dfebcabe2c
MD5 3f1fedf59d43671cbc2fd7c169904f52
BLAKE2b-256 303b6fcdecb91e86bd4c622111b8d17bc27d659202ffdf3861ff82a27d273401

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