Skip to main content

SQLAlchemy Dialect for SurrealDB

Project description

SQLAlchemy SurrealDB Dialect

English | 简体中文

⚠️ Experimental Stage: This project is in an experimental stage. Breaking changes may occur at any time. Use in production at your own risk.

A SQLAlchemy dialect for SurrealDB.

Installation

uv add sqlalchemy-surrealdb
# or
pip install sqlalchemy-surrealdb

Connection String

surrealdb://username:password@host:port/database

Example:

from sqlalchemy import create_engine

engine = create_engine("surrealdb://root:root@127.0.0.1:5070/test")

Usage

from sqlalchemy import Column, String, Integer, create_engine
from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy_surrealdb.types import SurrealRecordID
from surrealdb import RecordID
import uuid

Base = declarative_base()

class User(Base):
    __tablename__ = "users"

    id = Column(
        SurrealRecordID,
        primary_key=True,
        default=lambda: RecordID("users", uuid.uuid4().hex),
    )
    username = Column(String(50), unique=True, nullable=False)
    email = Column(String(120), unique=True, nullable=False)
    age = Column(Integer, nullable=True)

# Create tables
engine = create_engine("surrealdb://root:root@127.0.0.1:5070/test")
Base.metadata.create_all(bind=engine)

# Use session
SessionLocal = sessionmaker(bind=engine, expire_on_commit=False)
session = SessionLocal()

# CRUD operations
user = User(username="alice", email="alice@example.com", age=25)
session.add(user)
session.commit()

Features

  • Basic CRUD operations
  • SQLAlchemy ORM support
  • Custom SurrealRecordID type for SurrealDB RecordID handling

Limitations

  • Complex expressions have not yet been fully tested
  • Asynchronous operations are not yet supported
  • SQL statement construction currently inherits from SQLAlchemy and modifies the results, which may lead to unexpected issues and result in a performance overhead

Requirements

  • Python >= 3.9
  • SQLAlchemy >= 2.0
  • SurrealDB server running (tested with SurrealDB 3.0.4)

License

AGPL-v3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy_surrealdb-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_surrealdb-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_surrealdb-0.1.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_surrealdb-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sqlalchemy_surrealdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 388e646b8f831cf1d5ede7c859e5ea4e15423afe01d92b8e739d570d2386894c
MD5 c22ad7d37975c5e28406105fe1db05e0
BLAKE2b-256 88e171b69a73478f351bba7da10e290b3a239e821fc25efdb381d7cb00791bb2

See more details on using hashes here.

File details

Details for the file sqlalchemy_surrealdb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_surrealdb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sqlalchemy_surrealdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abb99b5d5f88ca5dc3afcfdff7f602de914dc7a6f7c4120780f448823b0897d8
MD5 07ddf7caa95aec80ce6e5a8178ee5cac
BLAKE2b-256 8d7791b6473044709c1894946f58574e5082c567c021682f21cc3d8138b5d49c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page