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 (Decorator API)

import asyncio
from magick_mind import MagickMind
from magick_mind.realtime.events import ChatMessageEvent, EventContext

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"
    )

    # Register handler — optional EventContext identifies the end user
    @client.realtime.on("chat_message")
    async def handle_chat(event: ChatMessageEvent, ctx: EventContext):
        print(f"Message for {ctx.target_user_id}: {event.payload.message}")

    # Connect and subscribe
    await client.realtime.connect()
    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

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 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
persona_workflow.py Persona creation, versioning, and prepare (system prompt generation)
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.2.tar.gz (130.6 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.2-py3-none-any.whl (67.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for magickmind-0.2.2.tar.gz
Algorithm Hash digest
SHA256 2364b641faf763541f90efdffa61a865eebb1c1eb2c7eec6b1cf34ae4b476365
MD5 a35e7729b18efd513020212ae4452410
BLAKE2b-256 32ac981e306ef9fc4817da90299c0b8f682edc776a1c42446d05ba8a6891945c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for magickmind-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 efeaf3ffbad3b331f3a1def766f306ae73c0d68c1b1c4624253b50d0109c46ef
MD5 aeef0b35f55db6980d0be04e7f02c49d
BLAKE2b-256 b9b79fa58b8f73a5970a03a862e65457edb9157c2abb953888a2420bdb58af69

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