Skip to main content

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)

Metadata

Release files for spres-ai 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spres-ai 1.0.0
File Size Uploaded Provenance Actions
spres_ai-1.0.0.tar.gz 6.0 kB Without provenance Details for spres_ai-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spres-ai 1.0.0
File Interpreter ABI Platform Actions
spres_ai-1.0.0-py3-none-any.whl Python 3 none any Details for spres_ai-1.0.0-py3-none-any.whl

Total release size: 11.6 kB

Release files / spres_ai-1.0.0.tar.gz

Download URL spres_ai-1.0.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4b8cdd89036e5941cc913899fbaa6b5683512a564718b249305e78c32c44077a
BLAKE2b-256 checksum
How to use checksums
3b0b3902d53e10442ca2e0ea1eb452907fb568cc53e65e745efae00d591b1d7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.15

Release files / spres_ai-1.0.0-py3-none-any.whl

Download URL spres_ai-1.0.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5141d8e2f50477d4b6a0a150b0e58cdaccdcf9d062a00357e989265618e351f
BLAKE2b-256 checksum
How to use checksums
7874d16c238da7ca4974bb41c989699c660cf75a8e3f044240e92b3b428caa03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.15

Security for spres-ai 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page