SurrealEngine Documentation¶
SurrealEngine is a comprehensive Object-Document Mapper (ODM) for SurrealDB that provides an intuitive Python interface for database operations. It supports both synchronous and asynchronous operations, connection pooling, field validation, query building, and graph-based relationships.
Key Features¶
Dual sync/async support for all operations
Connection pooling and management with automatic retry logic
Rich field types with comprehensive validation
Query builder with Django-style filtering and chaining
Graph relationships and path traversal
Materialized views and data aggregations
Schema management and migrations
Signals for model lifecycle events
Multi-backend support for SurrealDB and ClickHouse
Quick Start¶
from surrealengine import Document, StringField, IntField, create_connection
# Define a document model
class User(Document):
name = StringField(required=True)
age = IntField()
class Meta:
collection = "users"
# Create connection and save user
async def main():
connection = create_connection("ws://localhost:8000/rpc")
await connection.connect()
user = User(name="Alice", age=30)
await user.save()
print(f"Created user: {user.id}")
Installation¶
Install SurrealEngine using pip:
pip install surrealengine
Or with optional dependencies:
pip install surrealengine[all]
Table of Contents¶
User Guide
- Getting Started
- Tutorial: Building a Blog Application
- What You’ll Build
- Project Setup
- Step 1: Define Document Models
- Step 2: Initialize Database
- Step 3: User Management
- Step 4: Blog Post Operations
- Step 5: Advanced Queries
- Step 6: Real-Time Comments with LIVE Queries
- Step 7: Putting It All Together
- Expected Output
- Next Steps
- Additional Resources
- Complete Example
- Connection Management
- Connections, Pooling, and Observability
- Document Models
- Field Types
- Querying
- Relationships
- Schema Management
- Signals
- Materialized Views
- LIVE Queries (Subscriptions)
- Performance Optimization
API Reference
Development