surrealdb-python
Work with SurrealDB in Python
Building applications with SurrealDB requires understanding its multi-model capabilities including graph relationships, vector embeddings, and real-time subscriptions. This skill provides comprehensive guidance for using the Python SDK to implement CRUD operations, semantic search, and graph traversal patterns.
Download the skill ZIP
Upload in Claude
Go to Settings → Capabilities → Skills → Upload skill
Toggle on and start using
Test it
Using "surrealdb-python". How do I create users and find friends of friends using graph traversal?
Expected outcome:
- Create two users first:
- await db.create('person:alice', {'name': 'Alice'})
- await db.create('person:bob', {'name': 'Bob'})
- Create a knows relationship between them:
- await db.query("RELATE person:alice->knows->person:bob SET since = '2024-01-01'")
- Find friends of friends using multi-hop traversal:
- result = await db.query("SELECT ->knows->person->knows->person AS friends_of_friends FROM person:alice")
Using "surrealdb-python". How do I store document embeddings and search for similar content?
Expected outcome:
- First define your schema:
- await db.query("DEFINE TABLE documents SCHEMAFULL")
- Generate and store embedding with your model:
- embedding = model.encode(text).tolist()
- await db.create('documents', {'content': text, 'embedding': embedding})
- Search using KNN:
- SELECT * FROM documents WHERE embedding <|5|> $query_vector
Using "surrealdb-python". Set up a real-time subscription to watch for changes
Expected outcome:
- Start a live query on a table:
- live_id = await db.live('user')
- Subscribe to notifications:
- async for notification in db.subscribe_live(live_id):
- print(f"Change: {notification['action']} - {notification['result']}")
- Stop when done:
- await db.kill(live_id)
Security Audit
SafeDocumentation-only skill containing Markdown guides and Python code examples for SurrealDB operations. All 172 static findings are false positives: the analyzer misinterprets markdown backticks as shell execution, vector similarity functions as crypto algorithms, and database queries as reconnaissance. No executable code, no network calls, no file system access beyond documentation references.
Risk Factors
⚙️ External commands (120)
🌐 Network access (5)
📁 Filesystem access (1)
Quality Score
What You Can Build
Build RAG Applications
Store document embeddings and retrieve relevant context for language model generation using semantic similarity search.
Implement Knowledge Graphs
Model complex entity relationships with typed edges and metadata for sophisticated graph traversal queries.
Create Real-Time Apps
Subscribe to live data changes for dashboards, chat applications, or notification systems with automatic updates.
Try These Prompts
Show me how to connect to SurrealDB using the Python async SDK with authentication and select a namespace and database.
Help me create a RELATE statement in SurrealDB to connect two entities with metadata, and then show how to traverse the relationship.
Write a SurrealQL query using the KNN operator to find the 5 most similar documents based on cosine similarity with a query embedding.
Show me how to subscribe to live changes on a SurrealDB table and handle CREATE, UPDATE, and DELETE notifications.
Best Practices
- Use context managers (async with) for automatic connection cleanup and proper resource management.
- Parameterize queries with named parameters ($variable) to prevent injection attacks.
- Add timeouts to recursive graph queries and create indexes on frequently accessed fields for performance.
Avoid
- Avoid hardcoding credentials in source code; use environment variables instead.
- Do not skip schema definitions when data integrity is important; use SCHEMAFULL tables.
- Avoid unlimited recursive traversal without depth limits or timeouts, which can cause performance issues.