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 magickmind

Using pip:

pip install magickmind

For development:

git clone https://github.com/General-Magick-Industries/py-magickmind
cd py-magickmind
uv sync --all-extras

Quick Start

Authentication

import asyncio
from magick_mind import MagickMind

async def main():
    async with MagickMind(
        email="user@example.com",
        password="your_password",
        base_url="https://api.magickmind.ai",
    ) as client:
        # Authentication happens automatically on first API call.
        # Tokens are automatically refreshed when needed.
        user_id = await client.get_user_id()
        print(f"Authenticated as: {user_id}")

asyncio.run(main())

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

import asyncio
from magick_mind import MagickMind

async def main():
    async with MagickMind(
        email="user@example.com",
        password="your_password",
        base_url="https://api.magickmind.ai",
    ) as client:
        response = await client.v1.chat.send(
            api_key="sk-your-llm-key",
            mindspace_id="mind-789",
            message="Hello!",
            enduser_id="user-456",
        )
        print(response.content.content)  # AI response text

asyncio.run(main())

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 https://github.com/General-Magick-Industries/py-magickmind
cd py-magickmind

# 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.4.1.tar.gz (149.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.4.1-py3-none-any.whl (75.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for magickmind-0.4.1.tar.gz
Algorithm Hash digest
SHA256 227013643962beb1f136c06407c5ae687e4e2da3c7cdcf6352e5657ec1d6b683
MD5 471371db95ff764286528eb6d5d7141e
BLAKE2b-256 ad5f845688dda9d5adfde11ac07beb013271ef3eba8082c36398241a2d143def

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magickmind-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 acc96517c4f59c17347e825637d7e211e8770f73ae2cda304ed6e9f92b15a0ac
MD5 ee02cc96ce64c0277fcc1a3a350a9c17
BLAKE2b-256 4dd122f05ce27fb2b16e102c7858af0fb8ec6342be2698b658a54b5aa9ba118b

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