SingleStoreDB SQLAlchemy Dialect
This project contains a SQLAlchemy dialect which allows you to use the SQLAlchemy APIs with the SingleStoreDB database.
Features
- SingleStore-specific data types: VECTOR for AI/ML embeddings, JSON for semi-structured data
- Computed columns: PersistedColumn for server-side computed values
- Data distribution: ShardKey for optimal data partitioning across nodes
- Query optimization: SortKey for improved query performance
- Vector similarity search: VectorKey for AI/ML similarity operations
- Full-text search: FullTextIndex for text search capabilities
- JSON array indexing: MultiValueIndex for efficient JSON array queries
- Table types: ColumnStore (analytical) and RowStore (transactional) with reference table support
- Wide table optimization: ColumnGroup for tables with many columns
Install
This package can be installed from PyPI using pip:
pip install sqlalchemy-singlestoredb
Quick Start
Connecting to SingleStoreDB
from sqlalchemy import create_engine, text
# Basic connection
engine = create_engine('singlestoredb://user:password@host:3306/database')
# Test the connection
with engine.connect() as conn:
result = conn.execute(text('SELECT 1'))
print(result.fetchone())
Creating Tables (Core API)
from sqlalchemy import Column, DateTime, Integer, MetaData, String, Table
from sqlalchemy_singlestoredb import ShardKey, SortKey, VECTOR, JSON
metadata = MetaData()
users = Table(
'users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(100)),
Column('email', String(255)),
Column('created_at', DateTime),
singlestoredb_shard_key=ShardKey('id'),
singlestoredb_sort_key=SortKey('created_at'),
)
metadata.create_all(engine)
Creating Tables (ORM)
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.orm import declarative_base
from sqlalchemy_singlestoredb import ShardKey, SortKey
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String(100))
email = Column(String(255))
created_at = Column(DateTime)
__table_args__ = {
'singlestoredb_shard_key': ShardKey('id'),
'singlestoredb_sort_key': SortKey('created_at'),
}
Base.metadata.create_all(engine)
Key SingleStore Features
Vector Search for AI/ML
SingleStoreDB supports vector similarity search for AI/ML applications:
from sqlalchemy import Column, Integer, String, func, select
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy_singlestoredb import VECTOR, VectorKey, ColumnStore
Base = declarative_base()
class Document(Base):
__tablename__ = 'documents'
id = Column(Integer, primary_key=True)
title = Column(String(200))
embedding = Column(VECTOR(1536))
__table_args__ = {
'singlestoredb_table_type': ColumnStore(),
'singlestoredb_vector_key': [
VectorKey('embedding', index_options={'metric_type': 'COSINE_SIMILARITY'}),
],
}
# Find similar documents
query_embedding = [0.1, 0.2, ...] # Your embedding vector
with Session(engine) as session:
stmt = (
select(Document)
.order_by(func.dot_product(Document.embedding, query_embedding).desc())
.limit(10)
)
similar_docs = session.execute(stmt).scalars().all()
Data Distribution with Shard Keys
Shard keys control how data is distributed across nodes:
from sqlalchemy_singlestoredb import ShardKey
__table_args__ = {
# Single column shard key
'singlestoredb_shard_key': ShardKey('user_id'),
# Multi-column shard key
'singlestoredb_shard_key': ShardKey('user_id', 'region_id'),
# Empty shard key for random distribution
'singlestoredb_shard_key': ShardKey(),
}
Table Types
Choose the right table type for your workload:
from sqlalchemy_singlestoredb import ColumnStore, RowStore
# ColumnStore (default) - Best for analytical workloads
__table_args__ = {'singlestoredb_table_type': ColumnStore()}
# RowStore - Best for transactional workloads
__table_args__ = {'singlestoredb_table_type': RowStore()}
# Reference table - Replicated to all nodes for fast joins
__table_args__ = {'singlestoredb_table_type': RowStore(reference=True)}
License
This library is licensed under the Apache 2.0 License.
Resources
Metadata
Release files for sqlalchemy-singlestoredb 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlalchemy_singlestoredb-1.2.2.tar.gz | 92.9 kB | With provenance | Details for sqlalchemy_singlestoredb-1.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlalchemy_singlestoredb-1.2.2-py3-none-any.whl | Python 3 | none | any | Details for sqlalchemy_singlestoredb-1.2.2-py3-none-any.whl |
Total release size: 205.1 kB
Release files / sqlalchemy_singlestoredb-1.2.2.tar.gz
| Download URL | sqlalchemy_singlestoredb-1.2.2.tar.gz |
|---|---|
| Size | 92.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26efb48441652c5b00bb594aa118fb3ed9b74aed722a761ee544b8a213a7869f
|
|
BLAKE2b-256 checksum How to use checksums |
bd1273b720e83f9de3de495c6936753288a4bbab01e3215ee1df57952dd7c60c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / sqlalchemy_singlestoredb-1.2.2-py3-none-any.whl
| Download URL | sqlalchemy_singlestoredb-1.2.2-py3-none-any.whl |
|---|---|
| Size | 112.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
96e085715075c93aef0f6553ccb2c0bfab34ebc70797c5542b6fd2cbe96d7d14
|
|
BLAKE2b-256 checksum How to use checksums |
caf20f190677d578c864ebe6822f69621da5cf9700f120ba21d99ddda17b5e90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for sqlalchemy-singlestoredb 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sqlalchemy_singlestoredb-1.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.