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.1.tar.gz (10.1 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.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_surrealdb-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.1.tar.gz
Algorithm Hash digest
SHA256 b2bf1362d5620297555f3d9b64dac7c96d32a0bbbe6ccae634d7a71bb98490ca
MD5 a1a804746c375c701554f3aa4953e1fa
BLAKE2b-256 e0d76712d3cf63006344f4f7e6dd0e5f5bd7fd01f44652dd57dddc6ae67df262

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlalchemy_surrealdb-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd7d9665e1c5b0f60161d277cab944d6c7732befa8705767ce6cd34414a8d535
MD5 e1403cdf1091404c45c695d43a77bd5d
BLAKE2b-256 e87b62a22ac55cde53ca2d57c10229df7dee47de21fa56e343bb5fe9394cd2a8

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