Lightweight Django-style ORM for SurrealDB using the official Python SDK. Async support with Pydantic validation.
Project description
Surreal ORM Lite
Surreal ORM Lite is a lightweight, Django-style ORM for SurrealDB that uses the official SurrealDB Python SDK. It provides a simple and intuitive interface for database operations with full async support and Pydantic validation.
Why This Project?
This ORM is designed to:
- Use the official SurrealDB SDK (
surrealdb>=1.0.8) for maximum compatibility - Stay lightweight with minimal dependencies
- Keep up-to-date with SurrealDB and SDK releases
- Provide Django-style query syntax that developers love
Requirements
| Dependency | Version |
|---|---|
| Python | 3.11+ |
| SurrealDB | 2.6.0+ |
| Official SDK | surrealdb>=1.0.8 |
| Pydantic | >=2.12.5 |
Installation
pip install surreal-orm-lite
Or with uv:
uv add surreal-orm-lite
Quick Start
1. Configure the Connection
from surreal_orm_lite import SurrealDBConnectionManager
SurrealDBConnectionManager.set_connection(
url="http://localhost:8000",
user="root",
password="root",
namespace="my_namespace",
database="my_database",
)
2. Define a Model
from surreal_orm_lite import BaseSurrealModel
from pydantic import Field
class User(BaseSurrealModel):
id: str | None = None
name: str = Field(..., max_length=100)
email: str
age: int = Field(..., ge=0)
3. CRUD Operations
# Create
user = User(name="Alice", email="alice@example.com", age=30)
await user.save()
# Read
user = await User.objects().get("alice_id")
users = await User.objects().filter(age__gte=18).exec()
# Update
user.age = 31
await user.update()
# Or partial update
await user.merge(age=31)
# Delete
await user.delete()
4. QuerySet Methods
# Filter with Django-style lookups
users = await User.objects().filter(
age__gte=18,
name__startswith="A"
).exec()
# Ordering
users = await User.objects().order_by("name").exec()
users = await User.objects().order_by("age", OrderBy.DESC).exec()
# Pagination
users = await User.objects().limit(10).offset(20).exec()
# Select specific fields
results = await User.objects().select("name", "email").exec()
# Get first result
user = await User.objects().filter(name="Alice").first()
# Get all records
all_users = await User.objects().all()
# Custom query
results = await User.objects().query(
"SELECT * FROM User WHERE age > $min_age",
{"min_age": 21}
)
Features
| Feature | Status |
|---|---|
| Async/await support | ✅ |
| Pydantic validation | ✅ |
| CRUD operations | ✅ |
| QuerySet with filters | ✅ |
| Django-style lookups | ✅ |
| Custom primary keys | ✅ |
| HTTP connections | ✅ |
| WebSocket connections | ✅ |
Supported Filter Lookups
exact(default)gt,gte,lt,lteincontains,icontainsstartswith,istartswithendswith,iendswith
Configuration Options
Custom Primary Key
from surreal_orm_lite import BaseSurrealModel, SurrealConfigDict
class Product(BaseSurrealModel):
model_config = SurrealConfigDict(primary_key="sku")
sku: str
name: str
price: float
Context Manager
async with SurrealDBConnectionManager():
users = await User.objects().all()
# Connection automatically closed
Compatibility
This ORM is tested and compatible with:
| SurrealDB Version | SDK Version | Status |
|---|---|---|
| 2.6.0 | 1.0.8 | ✅ Tested |
| 2.5.x | 1.0.8 | ✅ Compatible |
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m "Add amazing feature") - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Advanced Features?
This project prioritizes stability and compatibility with the official SurrealDB Python SDK. Due to current SDK limitations, some advanced features cannot be implemented here.
For a feature-rich ORM with relations, transactions, and more, see:
- GitHub: SurrealDB-ORM
- PyPI: surrealdb-orm
When the official SDK supports additional features, they will be incorporated into this lite version.
License
MIT License - see LICENSE for details.
Author
Yannick Croteau GitHub: @EulogySnowfall
Related Projects
- SurrealDB - The database
- surrealdb.py - Official Python SDK
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file surreal_orm_lite-0.2.0.tar.gz.
File metadata
- Download URL: surreal_orm_lite-0.2.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72b205d0be06c7bc4d01227613fe8978a2ca4db27c8276c76d8d6d0066da1b14
|
|
| MD5 |
ebfb65161bc5e22e2261611a63a84a88
|
|
| BLAKE2b-256 |
08c49c635dc552e528462fa5786f1202d2ce06281315ad1067b65b788c5af081
|
Provenance
The following attestation bundles were made for surreal_orm_lite-0.2.0.tar.gz:
Publisher:
publish.yml on EulogySnowfall/SurrealDB-ORM-lite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
surreal_orm_lite-0.2.0.tar.gz -
Subject digest:
72b205d0be06c7bc4d01227613fe8978a2ca4db27c8276c76d8d6d0066da1b14 - Sigstore transparency entry: 909600419
- Sigstore integration time:
-
Permalink:
EulogySnowfall/SurrealDB-ORM-lite@8d4fdc8f75f0cbfd7ce8d2a2bcdf49c8fad09902 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/EulogySnowfall
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d4fdc8f75f0cbfd7ce8d2a2bcdf49c8fad09902 -
Trigger Event:
push
-
Statement type:
File details
Details for the file surreal_orm_lite-0.2.0-py3-none-any.whl.
File metadata
- Download URL: surreal_orm_lite-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66899582ae0f6347f23e56d758856f946408dcc456869d10bc9dbd3c2727fce3
|
|
| MD5 |
95f61a4170de2e38da272f114fd31ae0
|
|
| BLAKE2b-256 |
d2c72f740a0c19902e7f58599bbfe3a61b63d7115d63f649ce4ea174214f6ea4
|
Provenance
The following attestation bundles were made for surreal_orm_lite-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on EulogySnowfall/SurrealDB-ORM-lite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
surreal_orm_lite-0.2.0-py3-none-any.whl -
Subject digest:
66899582ae0f6347f23e56d758856f946408dcc456869d10bc9dbd3c2727fce3 - Sigstore transparency entry: 909600420
- Sigstore integration time:
-
Permalink:
EulogySnowfall/SurrealDB-ORM-lite@8d4fdc8f75f0cbfd7ce8d2a2bcdf49c8fad09902 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/EulogySnowfall
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d4fdc8f75f0cbfd7ce8d2a2bcdf49c8fad09902 -
Trigger Event:
push
-
Statement type: