Skip to main content

Python client for the Brookmimir API

Project description

odins-eye

PyPI version Python versions License: MIT

Python client library for the Brookmimir API.

Features

  • Synchronous and Asynchronous clients - Choose between sync (OdinsEyeClient) or async (AsyncOdinsEyeClient) based on your needs
  • Comprehensive API coverage - Access all Brookmimir API endpoints
  • Type-safe - Full type hints with Pydantic validation
  • Automatic retries - Built-in retry logic with exponential backoff
  • Rate limiting handling - Automatic detection and handling of rate limits
  • HTTP/2 support - Faster connections with HTTP/2
  • Context manager support - Automatic resource cleanup
  • Debug logging - Optional logging for troubleshooting
  • Comprehensive error handling - Detailed error messages and exception types

Installation

Install from PyPI:

pip install odins-eye

Install with development dependencies:

pip install odins-eye[dev]

Quick Start

Synchronous Usage

from odins_eye import OdinsEyeClient

# Initialize the client
client = OdinsEyeClient(api_key="your-api-key")

try:
    # Check API status
    status = client.index()
    print(f"API Status: {status}")

    # Get user profile
    profile = client.profile()
    print(f"User: {profile['user']['name']}")

    # Check credit balance
    credits = client.credits()
    print(f"Balance: {credits['current_balance']}")
finally:
    client.close()

Asynchronous Usage

import asyncio
from odins_eye import AsyncOdinsEyeClient

async def main():
    async with AsyncOdinsEyeClient(api_key="your-api-key") as client:
        # Make concurrent requests
        status, profile, credits = await asyncio.gather(
            client.index(),
            client.profile(),
            client.credits()
        )
        print(f"API Status: {status}")
        print(f"User: {profile['user']['name']}")
        print(f"Credits: {credits['current_balance']}")

asyncio.run(main())

Using Context Managers (Recommended)

with OdinsEyeClient(api_key="your-api-key") as client:
    status = client.index()
    print(status)

# Async version
async with AsyncOdinsEyeClient(api_key="your-api-key") as client:
    status = await client.index()
    print(status)

API Methods

Status and Version

# Get API status
status = client.index()

# Get API version
version = client.version()

# Run network test
result = client.nettest()

User Profile and Credits

# Get user profile
profile = client.profile()
print(f"Name: {profile['user']['name']}, Age: {profile['user']['age']}")

# Check credit balance
credits = client.credits()
print(f"Balance: {credits['current_balance']}")

Document Retrieval

# Fetch a document by ID
document = client.document("doc-123")

Query Submission

# Submit a media search
query_result = client.query({
    "limit": 2,
    "include_actors": True,
    "include_faces": True,
    "include_ocr_snippets": True,
    "filters": {
        "actor_name": "Alice",
        "environment": "prod",
        "keyword": "beach",
        "media_type": "image",
        "min_face_count": 1,
        "source_domain": "news.example",
        "tags": ["vip"],
    },
})
# Submit an image-based search
query_result = client.query({
    "image_base64": "...",
    "top_k": 10,
    "min_score": 0.1,
    "filters": {
        "source_domain": "goodsoil.church"
    },
})

Face Search

# Basic face search from a local image
results = client.face_search("path/to/image.jpg")

# Face search with canonical parameters
results = client.face_search(
    "path/to/image.jpg",
    top_k=10,
    min_score=0.8,
)

# Embedding-based face search
results = client.face_search(
    embedding=[0.5] * 512,
    top_k=5,
)

Legacy aliases such as max_k and image_base64 are still accepted for compatibility.

Error Handling

The client provides detailed error information through exception types:

from odins_eye import OdinsEyeClient, OdinsEyeAPIError, OdinsEyeError

with OdinsEyeClient(api_key="your-api-key") as client:
    try:
        result = client.profile()
    except OdinsEyeAPIError as e:
        # API returned an error (4xx or 5xx)
        print(f"API Error: {e.message}")
        print(f"Status Code: {e.status_code}")
        if e.error:
            print(f"Error: {e.error}")
        if e.error_details:
            print(f"Details: {e.error_details}")
    except OdinsEyeError as e:
        # Client-side error (validation, network, etc.)
        print(f"Client Error: {e.message}")

Handling Rate Limits

Rate limiting is automatically handled with retries:

from odins_eye import OdinsEyeAPIError

try:
    result = client.profile()
except OdinsEyeAPIError as e:
    if e.status_code == 429:
        print("Rate limit exceeded")
        if e.rate_limit_reset:
            print(f"Resets at: {e.rate_limit_reset}")

Configuration

Custom Timeout

import httpx
from odins_eye import OdinsEyeClient

timeout = httpx.Timeout(30.0, connect=10.0)
client = OdinsEyeClient(api_key="your-api-key", timeout=timeout)

Custom Retry Configuration

from odins_eye import OdinsEyeClient, RetryConfig

retry_config = RetryConfig(
    max_retries=5,
    initial_delay=2.0,
    max_delay=120.0,
    exponential_base=2.0,
    retry_on_rate_limit=True
)

client = OdinsEyeClient(
    api_key="your-api-key",
    retry_config=retry_config
)

Enable Debug Logging

import logging
from odins_eye import OdinsEyeClient

# Configure logging
logging.basicConfig(level=logging.DEBUG)

# Enable client logging
client = OdinsEyeClient(
    api_key="your-api-key",
    enable_logging=True
)

Custom Headers

client = OdinsEyeClient(
    api_key="your-api-key",
    headers={
        "X-Custom-Header": "value"
    }
)

Environment Variables

For security, consider using environment variables for your API key:

import os
from odins_eye import OdinsEyeClient

api_key = os.getenv("BROOK_MIMIR_API_KEY")
client = OdinsEyeClient(api_key=api_key)

Requirements

  • Python >= 3.9
  • httpx[http2] >= 0.27.0
  • pydantic >= 2.6.0

API Documentation

For detailed API documentation, visit the Brookmimir API docs.

Changelog

See CHANGELOG.md for release history and changes.

License

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

Links

Support

For support and questions:

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

odins_eye-1.5.4.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

odins_eye-1.5.4-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file odins_eye-1.5.4.tar.gz.

File metadata

  • Download URL: odins_eye-1.5.4.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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 odins_eye-1.5.4.tar.gz
Algorithm Hash digest
SHA256 9c2f61e11abd2ee238c8baae0b83a2acab4ea743498f50278bd8dc0ff9e129f5
MD5 f0794b6bb8327bc4e4ce02668af51689
BLAKE2b-256 924c6cad93f5521948449ddb56e08a18c5ee7cce4a996f626fedf490ee216a2d

See more details on using hashes here.

File details

Details for the file odins_eye-1.5.4-py3-none-any.whl.

File metadata

  • Download URL: odins_eye-1.5.4-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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 odins_eye-1.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2532559d0c74ada43662daa191003db289dd55f86766dde89e7c9af7ebee2f2f
MD5 ff0a5600c6d41f16ea66c7d63c66bb43
BLAKE2b-256 d5d439a29832ceb95ce65368748544834e34b5bc27205de32a8e0c910d6c4eb3

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