Skip to main content

Async Kafka and HTTP producer SDK for Raven AI logs

Project description

Raven SDK

Async Kafka and HTTP producer SDK for AI logs with support for both streaming and batch processing.

Features

  • Kafka Producer: Async Kafka producer for streaming AI logs
  • HTTP Producer: Simple HTTP producer for batch AI log submissions
  • Pydantic Models: Type-safe AI log models with automatic JSON serialization
  • UTC Timestamps: Automatic UTC timestamp formatting with ISO-8601 standard

Installation

pip install raven-sdk

Quick Start

Kafka Producer

import asyncio
from datetime import datetime
from raven import AiLog, AiLogKafkaProducer

async def main():
    # Create producer
    producer = AiLogKafkaProducer("localhost:9092", topic="ai-logs")
    
    # Start producer
    await producer.start()
    
    try:
        # Create AI log
        log = AiLog(
            modelId="gpt-4",
            confidenceScore=0.95,
            responseTimeMs=150,
            timestamp=datetime.utcnow(),
            numericFeatures={"temperature": 0.7},
            categoricalFeatures={"type": "completion"}
        )
        
        # Send logs
        await producer.produce_ai_logs([log])
        
    finally:
        await producer.stop()

asyncio.run(main())

HTTP Producer

import asyncio
from datetime import datetime
from raven import AiLog, AiLogHttpProducer

async def main():
    # Create producer
    producer = AiLogHttpProducer("https://api.example.com/logs")
    
    # Create AI log
    log = AiLog(
        modelId="gpt-4",
        confidenceScore=0.95,
        responseTimeMs=150,
        timestamp=datetime.utcnow(),
        numericFeatures={"temperature": 0.7},
        categoricalFeatures={"type": "completion"}
    )
    
    # Send logs (no start/stop needed)
    await producer.produce_ai_logs([log])

asyncio.run(main())

API Reference

AiLog

Pydantic model representing an AI log entry.

Fields:

  • modelId: str - Identifier for the AI model
  • confidenceScore: float - Confidence score of the prediction
  • responseTimeMs: int - Response time in milliseconds
  • timestamp: datetime - UTC timestamp of the log
  • numericFeatures: Dict[str, float] - Numeric features
  • categoricalFeatures: Dict[str, str] - Categorical features

AiLogKafkaProducer

Async Kafka producer for AI logs.

Methods:

  • __init__(kafka_bootstrap_servers: str, topic: str = "ai-logs")
  • async start() - Start the producer
  • async stop() - Stop the producer
  • async produce_ai_logs(logs: List[AiLog]) - Send batch of logs
  • async produce_stream_logs(logs: AsyncIterable[AiLog]) - Send streaming logs

AiLogHttpProducer

Simple HTTP producer for AI logs.

Methods:

  • __init__(endpoint_url: str, timeout: int = 30)
  • async produce_ai_logs(logs: List[AiLog]) - Send batch of logs via POST

Requirements

  • Python 3.8+
  • aiokafka>=0.8
  • pydantic>=2.0
  • aiohttp>=3.8

License

MIT License

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

raven_sdk-0.1.3.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

raven_sdk-0.1.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: raven_sdk-0.1.3.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for raven_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7109d0ec13e4559cc2e576b691348cb828178edfa793b231eb92db1e7fb68ffb
MD5 1d8c846c3f16787629bad87ff4e9977f
BLAKE2b-256 b33400b1989f992cd7a926691483118b7141225d16c8162a8876616f66a04643

See more details on using hashes here.

File details

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

File metadata

  • Download URL: raven_sdk-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for raven_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 42c68f97ed45da7392819c9eee828cede589d54a00dc029f86566219429e721a
MD5 2b32de0a7580d38109c269ba0f5a1ce2
BLAKE2b-256 86edbaae31cdd49b18a33c27114de33e5f2a2973691327ab168651f133a3d928

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