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_keyyou 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
- Backend Architecture - Service-level integration patterns
- Event-Driven Patterns - Events as source of truth vs. notifications
- Realtime Patterns - WebSocket subscription patterns
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
- Persona & Prepare - AI persona creation, versioning, and system prompt generation
- Realtime Guide - Complete WebSocket guide with bulk operations and relay architecture
Resources
- MagickSpace - Central organizing concept
- Corpus - Knowledge base management
- Artifact - Document/blob storage
- End User - User identity management
- Project - Project organization
Contributing
- Contributing Guide - How to extend the SDK
- Resource Implementation Guide - Template for adding typed resources
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
- Adrian (adrian@magickmind.ai)
- Minnie (minnie@magickmind.ai)
- Turtle (turtle@magickmind.ai)
Metadata
Release files for magickmind 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| magickmind-0.5.0.tar.gz | 143.7 kB | Without provenance | Details for magickmind-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| magickmind-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for magickmind-0.5.0-py3-none-any.whl |
Total release size: 219.3 kB
Release files / magickmind-0.5.0.tar.gz
| Download URL | magickmind-0.5.0.tar.gz |
|---|---|
| Size | 143.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa3c59847d5619463585c0a376ca4ef81889eaf4e31926285a62c67df7cc9242
|
|
BLAKE2b-256 checksum How to use checksums |
2fe18cab0714c705a3cb1e78a10ec4c6f49d7752e1b48458fe6df625939eefd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.3
|
Release files / magickmind-0.5.0-py3-none-any.whl
| Download URL | magickmind-0.5.0-py3-none-any.whl |
|---|---|
| Size | 75.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e09e94165ddde1b2735144d44ab9ad7d76175a58aa216ee47a06cf7e446862ed
|
|
BLAKE2b-256 checksum How to use checksums |
6e7eede72d29d73bfd54c5b6a7333d8b0f18c2f6598ff4ae32ecc5a9a36ae250
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.3
|
Security for magickmind 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.