Official Python SDK for Recursor - Memory system for LLMs that ensures lasting context, consistency, and learning across sessions
Project description
Recursor SDK (Python)
Complete Python SDK for interacting with the Recursor API. Provides authentication, project management, real-time updates via WebSocket, and full access to all platform features.
Installation
pip install recursor-sdk
Or build from source:
cd sdk/python
python -m pip install build
python -m build
pip install dist/recursor_sdk-*.whl
Quick Start
Basic Usage
from recursor_sdk import RecursorSDK
sdk = RecursorSDK(base_url="https://api.recursor.dev/api/v1")
# Check health
healthy = sdk.check_health()
print(f"API is healthy: {healthy}")
Authentication
# Register a new user
user = sdk.register(
email="user@example.com",
password="SecurePass123",
username="johndoe",
full_name="John Doe"
)
# Login
response = sdk.login("user@example.com", "SecurePass123")
# Access token is automatically set for future requests
# Get user profile
profile = sdk.get_profile()
print(f"User: {profile['email']}")
# Update profile
updated = sdk.update_profile(full_name="John Smith")
# Change password
sdk.change_password("SecurePass123", "NewSecurePass456")
Project Management
# Create a project
project = sdk.create_project(
name="My Project",
organization_id="org-123",
description="Project description"
)
# Get project
project_details = sdk.get_project(project["id"])
# List projects
projects = sdk.list_projects("org-123")
# Get MCP configuration
mcp_config = sdk.get_mcp_config(project["id"])
print(f"MCP Config: {mcp_config}")
# Regenerate API key
api_key_response = sdk.regenerate_project_api_key(project["id"])
# Update project
updated = sdk.update_project(
project["id"],
name="Updated Project Name",
description="New description"
)
# Delete project
sdk.delete_project(project["id"])
Organizations & Teams
# Create organization
org = sdk.create_organization(
name="My Organization",
description="Organization description"
)
# List organizations
orgs = sdk.list_organizations()
# Add member
sdk.add_member_to_organization(org["id"], "user-123")
# Remove member
sdk.remove_member_from_organization(org["id"], "user-123")
Corrections
# Create correction
correction = sdk.create_correction(
input_text="incorrect code",
output_text="correct code",
expected_output="correct code",
context={"explanation": "Fix bug"},
correction_type="bug"
)
# List corrections
result = sdk.list_corrections(page=1, page_size=50)
corrections = result.get("corrections", [])
# Search corrections
results = sdk.search_corrections("authentication", limit=10)
# Get correction
correction_details = sdk.get_correction(correction["id"])
# Update correction
updated = sdk.update_correction(
correction["id"],
{"context": {"explanation": "Updated explanation"}}
)
# Get statistics
stats = sdk.get_correction_stats()
Code Intelligence
# Detect intent
intent = sdk.detect_intent(
user_request="Add error handling to login",
current_file="auth.py",
tags=["error-handling"]
)
# Get intent history
history = sdk.get_intent_history(limit=50)
# Correct code
result = sdk.correct_code("def func(): pass", "python")
# Get analytics
dashboard = sdk.get_analytics_dashboard("user-123", period="30d")
time_saved = sdk.get_time_saved("user-123", period="30d")
quality = sdk.get_quality_metrics("user-123", period="30d")
Billing & Usage
# Get current usage
usage = sdk.get_usage()
print(f"API Calls: {usage['api_calls']['used']} / {usage['api_calls']['limit']}")
# Get usage history
history = sdk.get_usage_history(days=30, resource_type="api_call")
# List billing plans
plans = sdk.list_billing_plans()
# Get subscription
subscription = sdk.get_subscription()
Notifications
# List notifications
notifications = sdk.list_notifications()
# Mark as read
sdk.mark_notification_as_read("notification-123")
# Mark all as read
sdk.mark_all_notifications_as_read()
# Delete notification
sdk.delete_notification("notification-123")
Settings
# Get settings
settings = sdk.get_settings()
# Update account
sdk.update_account(full_name="John Smith", email="newemail@example.com")
# Update preferences
sdk.update_preferences({"theme": "dark", "notifications": True})
# Get guidelines
guidelines = sdk.get_guidelines()
WebSocket (Real-time Updates)
import asyncio
from recursor_sdk import RecursorSDK
async def main():
sdk = RecursorSDK(base_url="https://api.recursor.dev/api/v1")
# Login first to get access token
sdk.login("user@example.com", "password")
# Create and connect WebSocket
ws = await sdk.connect_websocket()
# Subscribe to events
def on_notification(data):
print(f"New notification: {data}")
def on_usage(data):
print(f"Usage updated: {data}")
ws.on("notification.new", on_notification)
ws.on("usage.updated", on_usage)
# Keep connection alive
await asyncio.sleep(60)
# Disconnect when done
await sdk.disconnect_websocket()
asyncio.run(main())
Gateway Endpoints
# LLM Gateway
policy = sdk.get_llm_gateway_policy()
chat_response = sdk.gateway_chat(
messages=[{"role": "user", "content": "Hello!"}],
provider="openai",
model="gpt-4",
call_provider=True
)
# Robotics Gateway
robotics_policy = sdk.get_robotics_gateway_policy()
robotics_result = sdk.robotics_gateway_observe(
state={"position": [0, 0, 0]},
command={"action": "move"}
)
# AV Gateway
av_policy = sdk.get_av_gateway_policy()
av_result = sdk.av_gateway_observe(
sensors={"camera": "data"},
state={"speed": 60},
action={"brake": False},
timestamp=int(time.time()),
vehicle_id="vehicle-123"
)
Environment Variables
RECURSOR_API_URL- API base URL (default:http://localhost:8000/api/v1)RECURSOR_API_KEY- API key for authenticationRECURSOR_ACCESS_TOKEN- Access token for authentication
API Reference
Authentication Methods
register(email, password, username, full_name=None)- Register new userlogin(email, password)- Login and get access tokenlogout()- Logout current userrefresh_token(refresh_token)- Refresh access tokenget_profile()- Get user profileupdate_profile(full_name=None, username=None)- Update user profilechange_password(current_password, new_password)- Change passwordgenerate_api_key()- Generate API keyrevoke_api_key()- Revoke API keyget_password_requirements()- Get password requirements
Project Methods
create_project(name, organization_id, description=None, settings=None)- Create projectget_project(project_id)- Get projectlist_projects(organization_id=None)- List projectsupdate_project(project_id, name=None, description=None, settings=None, is_active=None)- Update projectdelete_project(project_id)- Delete projectregenerate_project_api_key(project_id)- Regenerate API keyget_mcp_config(project_id)- Get MCP configurationget_mcp_stats(project_id)- Get MCP statistics
Organization Methods
create_organization(name, description=None)- Create organizationlist_organizations()- List organizationsget_organization(org_id)- Get organizationupdate_organization(org_id, name=None, description=None)- Update organizationadd_member_to_organization(org_id, user_id)- Add memberremove_member_from_organization(org_id, user_id)- Remove member
Correction Methods
create_correction(input_text, output_text, expected_output=None, context=None, correction_type=None, organization_id=None)- Create correctionlist_corrections(page=1, page_size=50, include_inactive=False, organization_id=None)- List correctionssearch_corrections(query, limit=10, organization_id=None)- Search correctionsget_correction(correction_id)- Get correctionupdate_correction(correction_id, updates)- Update correctionget_correction_stats()- Get statistics
Code Intelligence Methods
detect_intent(user_request, current_file=None, user_id=None, project_id=None, tags=None, similar_limit=5, organization_id=None)- Detect intentget_intent_history(limit=50, project_id=None)- Get intent historycorrect_code(code, language, project_profile=None)- Correct codecorrect_config(config, config_type)- Correct configcorrect_documentation(markdown, doc_type="README")- Correct documentationapply_auto_corrections(user_id, model_name, corrections)- Apply auto correctionsget_trust_score(user_id, model_name)- Get trust scoresubmit_feedback(prediction_id, accepted)- Submit feedbackget_auto_correct_stats(user_id)- Get auto correction statsget_patterns(user_id=None)- Get patternsget_analytics_dashboard(user_id, period="30d", project_id=None)- Get analytics dashboardget_time_saved(user_id, period="30d", project_id=None)- Get time saved metricsget_quality_metrics(user_id, period="30d", project_id=None)- Get quality metricsget_ai_agent_metrics(user_id, project_id=None)- Get AI agent metrics
Billing Methods
get_usage()- Get current usageget_usage_history(days=30, resource_type=None)- Get usage historylist_billing_plans()- List billing plansget_subscription()- Get subscription
Notification Methods
list_notifications()- List notificationsmark_notification_as_read(notification_id)- Mark as readmark_all_notifications_as_read()- Mark all as readdelete_notification(notification_id)- Delete notification
Settings Methods
get_settings()- Get settingsupdate_account(full_name=None, email=None)- Update accountupdate_preferences(preferences)- Update preferencesget_guidelines()- Get guidelineschange_password_via_settings(current_password, new_password)- Change passworddelete_account()- Delete account
Activity Methods
list_activity_logs(page=1, page_size=50)- List activity logsexport_activity_logs()- Export activity logs (returns bytes)
WebSocket Methods
create_websocket()- Create WebSocket clientconnect_websocket()- Connect WebSocket (async)disconnect_websocket()- Disconnect WebSocket (async)
Gateway Methods
get_llm_gateway_policy()- Get LLM gateway policygateway_chat(messages, provider="openai", model=None, call_provider=False, user_id=None, organization_id=None)- LLM gateway chatget_robotics_gateway_policy()- Get robotics gateway policyrobotics_gateway_observe(state, command=None, environment=None, user_id=None, organization_id=None)- Robotics gateway observeget_av_gateway_policy()- Get AV gateway policyav_gateway_observe(sensors, state, action, timestamp, vehicle_id, user_id=None, organization_id=None)- AV gateway observe
Error Handling
The SDK raises exceptions for failed requests:
try:
sdk.login("wrong", "wrong")
except Exception as e:
print(f"Login failed: {e}")
# HTTPStatusError: 401 Unauthorized
Type Hints
Full type hints included for better IDE support and type checking.
License
MIT License. See LICENSE file.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file recursor_sdk-1.0.0.tar.gz.
File metadata
- Download URL: recursor_sdk-1.0.0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d1fbcf95a9f9928a441813cd3ba7b91c2479f1c127187f8df57a0037a71a73e
|
|
| MD5 |
3f849ca608c171211dba64bbd79feb69
|
|
| BLAKE2b-256 |
eaec92a74d437a69450c7dc6cac6558490e53a26cbf957455466bde98183b806
|
File details
Details for the file recursor_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: recursor_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6917f380cff9a8b32b44f56a563ea9ad38887f444df7f6d10b57aad740ef6c2
|
|
| MD5 |
a8c1e838ace0bea12377ca9d299105b1
|
|
| BLAKE2b-256 |
52083c35410d85eb337fbede5c55e0a837d352174da453aac71b4fbfab8ca8ed
|