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, magickspace, 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",
            magickspace_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

MagickSpaces

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

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

📖 Learn more: MagickSpace 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 MagickSpaces
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.5.0.tar.gz (143.7 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.5.0-py3-none-any.whl (75.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for magickmind-0.5.0.tar.gz
Algorithm Hash digest
SHA256 aa3c59847d5619463585c0a376ca4ef81889eaf4e31926285a62c67df7cc9242
MD5 c0e8967f5e0cd7e1ed70b429c0032295
BLAKE2b-256 2fe18cab0714c705a3cb1e78a10ec4c6f49d7752e1b48458fe6df625939eefd1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for magickmind-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e09e94165ddde1b2735144d44ab9ad7d76175a58aa216ee47a06cf7e446862ed
MD5 b8b5097ea395a0b83f0fdd990669c764
BLAKE2b-256 6e7eede72d29d73bfd54c5b6a7333d8b0f18c2f6598ff4ae32ecc5a9a36ae250

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