Python SDK

Because life's too short for bad APIs 🐍✨

The official Python SDK for Memof.ai. Build intelligent applications with persistent AI memoryβ€”now with 100% more type hints!

Why Python SDK?

  • πŸ”’ Type-Safe - Full type hints (mypy approved!)
  • 🐍 Pythonic - Feels like native Python code
  • πŸ“¦ Async Support - For when you need speed
  • 🎯 Simple - Clean API that just works
  • πŸš€ Production-Ready - Battle-tested and reliable

Installation

pip install memofai

30-Second Quick Start

Let's build something πŸš€

from memofai import create_moa_client

client = create_moa_client(
    api_token='moa_your_token_here',
    environment='production'
)

# Create workspace
workspace = client.workspaces.create({
    'name': 'My AI Workspace',
    'description': 'Where the magic happens'
})

# Create bot
bot = client.bots.create({
    'name': 'Assistant Bot',
    'workspace_id': workspace['id'],
    'description': 'Helpful AI assistant'
})

# Store memory
memory = client.memories.create({
    'bot_id': bot['id'],
    'content': 'User loves Python and wants clean code'
})

# Search (the fun part!)
results = client.memories.search({
    'bot_id': bot['id'],
    'query': 'programming language preferences',
    'limit': 5
})

print(f"Found {len(results)} relevant memories!")

Type Hints Included

Your IDE will love you πŸ’š

from memofai import create_moa_client
from memofai.types import WorkspaceData, BotData, MemoryData

client = create_moa_client(api_token='moa_your_token')

# Type-safe all the way
workspace: WorkspaceData = client.workspaces.create({
    'name': 'Type-Safe Workspace'
})

bot: BotData = client.bots.create({
    'name': 'Type-Safe Bot',
    'workspace_id': workspace['id']
})

Async Support

For the speed demons ⚑

import asyncio
from memofai import create_async_moa_client

async def main():
    client = create_async_moa_client(api_token='moa_your_token')
    
    # All methods are async
    workspaces = await client.workspaces.list()
    bot = await client.bots.create({
        'name': 'Async Bot',
        'workspace_id': workspaces[0]['id']
    })
    
    memories = await client.memories.search({
        'bot_id': bot['id'],
        'query': 'async patterns'
    })

asyncio.run(main())

What Makes It Special?

Clean Namespace API

client.workspaces.create()   # Workspace operations
client.bots.create()          # Bot operations
client.memories.create()      # Memory operations

Everything where you'd expect it!

Auto-Retry Logic

client = create_moa_client(
    api_token='moa_your_token',
    retries=3,          # Retry up to 3 times
    retry_delay=1000    # Wait 1s between retries
)

Environment Support

environments = {
    'dev': 'http://127.0.0.1:8000',
    'alpha': 'https://alpha-api.memof.ai',
    'beta': 'https://beta-api.memof.ai',
    'sandbox': 'https://sandbox-api.memof.ai',
    'production': 'https://api.memof.ai'
}

Framework Integration

FastAPI

from fastapi import FastAPI
from memofai import create_moa_client

app = FastAPI()
client = create_moa_client(api_token='moa_your_token')

@app.post("/search")
async def search_memories(bot_id: str, query: str):
    results = client.memories.search({
        'bot_id': bot_id,
        'query': query
    })
    return {"results": results}

Django

# settings.py
MEMOFAI_CLIENT = create_moa_client(
    api_token=os.getenv('MEMOFAI_API_TOKEN')
)

# views.py
from django.conf import settings

def search_view(request):
    results = settings.MEMOFAI_CLIENT.memories.search({
        'bot_id': request.POST['bot_id'],
        'query': request.POST['query']
    })
    return JsonResponse({'results': results})

Flask

from flask import Flask, request, jsonify
from memofai import create_moa_client

app = Flask(__name__)
client = create_moa_client(api_token='moa_your_token')

@app.route('/search', methods=['POST'])
def search():
    results = client.memories.search(request.json)
    return jsonify(results)

What's Next?

Ready to dive in?

  1. Installation Guide - Get set up
  2. Workspace Management - Organize
  3. Bot Operations - Build agents
  4. Memory Management - The good stuff

Package Info

pip show memofai

Name: memofai
Version: latest
License: MIT
Homepage: https://memof.ai

Need Help?

Now go build something amazing! 🐍✨