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.0.tar.gz (128.8 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.0-py3-none-any.whl (66.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for magickmind-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8f1e343482b889ef69d7a87a3766683e98255cb3503ae10159bf84ac5d3be563
MD5 5fd1311530550a25ee0230ab3095e01e
BLAKE2b-256 4bc62acf4f7dc3c1b41f7bdce7e490c3f416856603a9d89b20639d35460c981a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for magickmind-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b4a2761a368fd99eb7f5c83eb945c20d8960444831bc8758bd78d4837adda42
MD5 d86a549c643e775b73f9655f04f7e9a0
BLAKE2b-256 d19798b5b0b236a08c843fb8a58136c2c4d4c2e49168c7506157a6833423ed19

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