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 ingestfile_path(str, optional): File path for referencemetadata(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 questionsession_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 (
.pyfiles) - JavaScript (
.jsfiles) - TypeScript/React (
.ts,.tsxfiles)
Metadata
Release files for brainbox-sdk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| brainbox_sdk-1.0.0.tar.gz | 5.7 kB | Without provenance | Details for brainbox_sdk-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| brainbox_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for brainbox_sdk-1.0.0-py3-none-any.whl |
Total release size: 11.4 kB
Release files / brainbox_sdk-1.0.0.tar.gz
| Download URL | brainbox_sdk-1.0.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f23f88d19dc21bf4b393fa1538cc0ec5531c257f06ee6c55e478d4c7c6cfa91
|
|
BLAKE2b-256 checksum How to use checksums |
95f28910f19d6c61b0d66bca2c8f9ae6c1e7923800775b2b7c8bac7088f1b2c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.15
|
Release files / brainbox_sdk-1.0.0-py3-none-any.whl
| Download URL | brainbox_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5fe071ce051f2b27c3216f065614acd366076db79cfff08fa2612eca7c746a1e
|
|
BLAKE2b-256 checksum How to use checksums |
ba4789fa8e8ffb4065393cf99062f3b0511fe8231e6bdc633de0b2ec1006ff50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.15
|
Security for brainbox-sdk 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.