Skip to main content

Official Python SDK for the MagickMind AI platform.

Project description

Magick Mind SDK

Python SDK for backend services integrating with the Magick Mind platform. Provides type-safe, validated access to chat, mindspace, and realtime features.

Installation

Using uv (recommended):

uv add magick-mind

Using pip:

pip install magick-mind

For development:

git clone <repository-url>
cd magick-mind-sdk
uv sync --all-extras

Quick Start

Authentication

from magick_mind import MagickMind

# Create client with email/password
client = MagickMind(
    email="user@example.com",
    password="your_password",
    base_url="https://api.magickmind.ai"
)

# Authentication happens automatically on first API call
# Tokens are automatically refreshed when needed
print(f"Authenticated: {client.is_authenticated()}")

Note: The api_key you might see in chat requests is not for SDK authentication. It's a parameter you pass when calling LLM endpoints (for tracking/billing). The SDK itself authenticates with JWT tokens from /v1/auth/login.

Basic Chat

# Make a chat request
response = client.http.post(
    "/v1/magickmind/chat",
    json={
        "api_key": "sk-your-llm-key",
        "message": "Hello!",
        "chat_id": "chat-123",
        "sender_id": "user-456",
        "mindspace_id": "mind-789"
    }
)

# Response streams via Centrifugo WebSocket (see Realtime section)

Realtime (Simple Listener)

import asyncio
from magick_mind import MagickMind
from magick_mind.realtime.handler import RealtimeEventHandler

class MyHandler(RealtimeEventHandler):
    async def on_message(self, user_id: str, payload):
        print(f"Update for {user_id}: {payload}")

async def main():
    client = MagickMind(
        email="user@example.com",
        password="password", 
        base_url="https://api.magickmind.ai",
        ws_endpoint="wss://api.magickmind.ai/connection/websocket"
    )
    
    # Connect and subscribe
    await client.realtime.connect(events=MyHandler())
    await client.realtime.subscribe_many(["user-1", "user-2"])
    
    # Keep listening...
    await asyncio.sleep(60)

asyncio.run(main())

Key Concepts

Mindspaces

Mindspace is the central organizing concept in the Magick Mind API - it's where conversations, knowledge, and collaboration converge:

  • All chat conversations happen within a mindspace
  • Knowledge (corpus) attaches to mindspaces to provide context for AI responses
  • Users collaborate through mindspaces (private for individuals, group for teams)
  • Most operations reference a mindspace_id

📖 Learn more: Mindspace Resource Guide

Service Users

This SDK is designed for service-level authentication (email/password). Your backend authenticates as a service user and acts on behalf of end users.

Common architecture:

[Your Frontend/App] ←→ [Your Backend + This SDK] ←→ [Magick Mind API]

For direct device-to-API patterns (robotics/IoT), see Event-Driven Patterns.

Documentation

Architecture

Guides

  • Backend Integration - Production patterns for message deduplication, hybrid sync, recovery
  • Error Handling - Exception types, retry patterns, production examples
  • Advanced Usage - Direct HTTP client access for power users
  • Realtime Guide - Complete WebSocket guide with bulk operations and relay architecture

Resources

Contributing

Development

Setup

# Clone repository
git clone <repository-url>
cd magick-mind-sdk

# Install dependencies
uv sync --all-extras

Testing

# Run all tests
uv run pytest tests/ -v

# Run specific test file
uv run pytest tests/test_auth.py -v

# Run with coverage
uv run pytest tests/ --cov=magick_mind --cov-report=html

Type Checking

uv run pyright

Formatting

uv run ruff format .

Examples

The examples/ directory contains 7 working examples demonstrating key SDK patterns:

Example Description
authentication.py Email/password authentication with auto-refresh
resource_management.py CRUD operations for End Users, Projects, and Mindspaces
chat_workflow.py Complete chat workflow with realtime streaming
bulk_subscribe.py Bulk subscriptions with message deduplication
backend_service.py Production-ready backend service pattern
error_handling_patterns.py Comprehensive error handling patterns
setup_resources.py Setup script for creating test resources

📖 See examples/README.md for detailed descriptions and usage.

Quick start:

# 1. Set environment variables
export MAGICKMIND_BASE_URL="http://localhost:8888"
export MAGICKMIND_EMAIL="user@example.com"
export MAGICKMIND_PASSWORD="your_password"

# 2. Create test resources
uv run python examples/setup_resources.py

# 3. Run an example
uv run python examples/authentication.py

License

MIT License - see LICENSE file for details.

Authors

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

magickmind-0.2.1.tar.gz (129.0 kB view details)

Uploaded Source

Built Distribution

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

magickmind-0.2.1-py3-none-any.whl (66.5 kB view details)

Uploaded Python 3

File details

Details for the file magickmind-0.2.1.tar.gz.

File metadata

  • Download URL: magickmind-0.2.1.tar.gz
  • Upload date:
  • Size: 129.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for magickmind-0.2.1.tar.gz
Algorithm Hash digest
SHA256 393788b86c6c9cad65362625461f71c4012631e933c06035e9a34cf23a7ed4f9
MD5 33d339331dd8dd9798da53e884ec7d11
BLAKE2b-256 49c8191021b818656a4296379d4fa4bf4ab682a2c476a2d8102035adefbc509e

See more details on using hashes here.

File details

Details for the file magickmind-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: magickmind-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 66.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for magickmind-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 74516bac00dde5ef9f16f9aa912d1cf2f8e696db8b43c694c3fdcf47fa1c3565
MD5 6fe49ec83e58b446638d3f83e2326f8f
BLAKE2b-256 461bf9b9ea73a2bf54559421c64e5ea13550f2bfba98ac0356c546beaeffe28c

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