Skip to main content

Official Spres-Ai-Agent SDK for Python

Project description

Brainbox Python SDK

Python client library for Brainbox AI Backend.

Installation

pip install requests

Quick Start

from brainbox_sdk import BrainboxPythonSDK

sdk = BrainboxPythonSDK(
    api_url="http://localhost:8000",
    api_key="your-api-key",
    tenant_id="company-1"
)

# Ingest data
result = sdk.ingest(
    source_type="logs",
    content="ERROR: Database connection failed",
    file_path="/var/log/app.log"
)
print(f"Task ID: {result['task_id']}")

# Chat
response = sdk.chat("What happened to the database?")
print(f"Answer: {response['response']}")

Methods

ingest(source_type, content, file_path=None, metadata=None)

Send data to Brainbox for processing.

Parameters:

  • source_type (str): Type of data (logs, codebase, json, csv, docker_logs, nginx_logs, postgres_logs)
  • content (str): The actual content to ingest
  • file_path (str, optional): File path for reference
  • metadata (dict, optional): Additional metadata

Returns: Dictionary with task_id and status

chat(question, session_id=None)

Ask a question to the AI.

Parameters:

  • question (str): Your question
  • session_id (str, optional): Chat session ID

Returns: Dictionary with response, reasoning, and search_results

get_ingest_status(task_id)

Check ingestion task status.

Parameters:

  • task_id (str): Task ID from ingest response

Returns: Task status dictionary

create_chat_session(title=None)

Create a new chat session.

Parameters:

  • title (str, optional): Session title

Returns: Dictionary with session_id

health_check()

Check if backend is running.

Returns: Service health status

Examples

Ingest Logs

sdk.ingest(
    source_type="logs",
    content=open("/var/log/nginx/error.log").read(),
    file_path="/var/log/nginx/error.log"
)

Ingest Code

sdk.ingest(
    source_type="codebase",
    content=open("app.py").read(),
    file_path="app.py"
)

Ingest JSON

sdk.ingest(
    source_type="json",
    content='{"error": "Failed", "code": 500}',
    file_path="config.json"
)

Chat Session

# Create session
session = sdk.create_chat_session(title="Troubleshooting")
session_id = session['session_id']

# Ask questions in the session
response = sdk.chat("What's happening?", session_id=session_id)
response = sdk.chat("How do I fix it?", session_id=session_id)

Error Handling

try:
    response = sdk.chat("Question")
except Exception as e:
    print(f"Error: {e}")

Source Types

Type Use Case
logs Generic log files
nginx_logs Nginx access/error logs
docker_logs Docker container logs
postgres_logs PostgreSQL logs
codebase Source code
json JSON formatted data
csv CSV formatted data

Function Locator (Built-in)

Find functions in your codebase without needing a separate tool.

Find a Specific Function

sdk = BrainboxPythonSDK("http://localhost:8000", "api-key", "tenant-1")

# Find login function
login_funcs = sdk.find_function("login", directory="./src")
for func in login_funcs:
    print(f"Found: {func.name}")
    print(f"Location: {func.file_path}:{func.line_number}")
    print(f"Signature: {func.signature}")
    print(f"Parameters: {func.parameters}")

Find All Functions

# Get all functions in codebase
all_funcs = sdk.find_all_functions(directory="./src")
print(f"Total functions: {len(all_funcs)}")

Find Functions in Specific File

# Get all functions in a file
auth_funcs = sdk.find_function_by_file("./src/auth.py")
for func in auth_funcs:
    print(f"  {func.name} at line {func.line_number}")

Find Async Functions

# Find all async/await functions
async_funcs = sdk.find_async_functions(directory="./src")
print(f"Found {len(async_funcs)} async functions")

for func in async_funcs:
    print(f"  {func.name} (async) in {func.file_path}")

Function Info Object

func = sdk.find_function("login")[0]

# Access function details
print(func.name)           # "login"
print(func.file_path)      # "/app/auth.py"
print(func.line_number)    # 45
print(func.signature)      # "def login(username, password)"
print(func.parameters)     # ["username", "password"]
print(func.is_async)       # False
print(func.language)       # "python"
print(func.class_name)     # None (or class name if method)

# Convert to dict
func_dict = func.to_dict()

Supported Languages

  • Python (.py files)
  • JavaScript (.js files)
  • TypeScript/React (.ts, .tsx files)

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

brainbox_sdk-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

brainbox_sdk-1.0.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file brainbox_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: brainbox_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.15

File hashes

Hashes for brainbox_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3f23f88d19dc21bf4b393fa1538cc0ec5531c257f06ee6c55e478d4c7c6cfa91
MD5 23c49fad8d397225b43ee3f7795dc9e1
BLAKE2b-256 95f28910f19d6c61b0d66bca2c8f9ae6c1e7923800775b2b7c8bac7088f1b2c8

See more details on using hashes here.

File details

Details for the file brainbox_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: brainbox_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.15

File hashes

Hashes for brainbox_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fe071ce051f2b27c3216f065614acd366076db79cfff08fa2612eca7c746a1e
MD5 bf474f8be4e1c549312dd029c561e1c6
BLAKE2b-256 ba4789fa8e8ffb4065393cf99062f3b0511fe8231e6bdc633de0b2ec1006ff50

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