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

spres_ai-1.0.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

spres_ai-1.0.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spres_ai-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4b8cdd89036e5941cc913899fbaa6b5683512a564718b249305e78c32c44077a
MD5 d694d518aefbc1758e3c3f21c087a02b
BLAKE2b-256 3b0b3902d53e10442ca2e0ea1eb452907fb568cc53e65e745efae00d591b1d7e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for spres_ai-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5141d8e2f50477d4b6a0a150b0e58cdaccdcf9d062a00357e989265618e351f
MD5 36e812625de7bcbed19b29e7a9325985
BLAKE2b-256 7874d16c238da7ca4974bb41c989699c660cf75a8e3f044240e92b3b428caa03

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