SQLite-compatible database with CJK FTS5 support
Project description
sql5
SQLite-compatible database with native CJK FTS5 support. Built with Rust.
v3.0 - Client-Server Architecture with WebSocket Support
sql5 v3.0 consists of:
- Python package (
sql5on PyPI): Pure Python client - Rust binary: Server process providing all SQL functionality
The Python client communicates with the Rust server via:
- Subprocess mode (default): JSON over stdin/stdout
- WebSocket mode (v3.0): WebSocket protocol for multi-client support
Installation
pip install sql5
Python API
import sql5
# Subprocess mode (default, v2.0 compatible)
db = sql5.connect("mydb.db")
# Or use WebSocket mode (v3.0, multi-client support)
db = sql5.connect(
path="mydb.db",
transport="websocket",
host="127.0.0.1",
port=8080
)
# Execute SQL
db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
db.execute("INSERT INTO users VALUES (1, 'Alice', 30)")
db.execute("INSERT INTO users VALUES (2, 'Bob', 25)")
db.execute("INSERT INTO users VALUES (3, 'Charlie', 35)")
# Query with parameters
db.execute("INSERT INTO users VALUES (?, ?, ?)", (4, "David", 28))
# Fetch results
cursor = db.execute("SELECT * FROM users WHERE age > ?", (25,))
for row in cursor:
print(row)
# (1, 'Alice', 30)
# (2, 'Bob', 25)
# (3, 'Charlie', 35)
# (4, 'David', 28)
# Fetch as list
cursor = db.execute("SELECT name, age FROM users ORDER BY age")
rows = cursor.fetchall()
print(rows)
# [('Bob', 25), ('David', 28), ('Alice', 30), ('Charlie', 35)]
# Fetch one
cursor = db.execute("SELECT * FROM users WHERE id = ?", (1,))
row = cursor.fetchone()
print(row)
# (1, 'Alice', 30)
# Transactions
db.execute("BEGIN")
db.execute("INSERT INTO users VALUES (5, 'Eve', 40)")
db.execute("COMMIT")
# Or rollback
db.execute("BEGIN")
db.execute("INSERT INTO users VALUES (6, 'Frank', 45)")
db.execute("ROLLBACK")
# Full-text search (FTS5)
db.execute("CREATE VIRTUAL TABLE articles USING fts5(title, body)")
db.execute("INSERT INTO articles VALUES ('Hello World', 'The quick brown fox')")
db.execute("INSERT INTO articles VALUES ('Rust Guide', 'Memory safety without GC')")
db.execute("INSERT INTO articles VALUES ('中文測試', '繁體中文全文檢索')")
cursor = db.execute("SELECT * FROM articles WHERE articles MATCH ?", ("rust",))
print(cursor.fetchall())
# [('Rust Guide', 'Memory safety without GC')]
cursor = db.execute("SELECT * FROM articles WHERE articles MATCH ?", ("中文",))
print(cursor.fetchall())
# [('中文測試', '繁體中文全文檢索')]
# Close database
db.close()
Connection Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
str | None | Database file path |
transport |
str | "subprocess" | "subprocess" or "websocket" |
host |
str | "127.0.0.1" | WebSocket server host |
port |
int | 8080 | WebSocket server port |
CLI Usage
# Run the REPL
sql5
# Open a database file
sql5 /path/to/database.db
# Execute single query
echo "SELECT 1 + 1;" | sql5
Features
- Full SQL support (SELECT, INSERT, UPDATE, DELETE, CREATE, DROP)
- ACID transactions (BEGIN, COMMIT, ROLLBACK)
- WAL mode
- Foreign keys
- Views
- Triggers
- Full-text search (FTS5) with CJK bigram tokenization
- Multiple database attachment (ATTACH DATABASE)
- Window functions (ROW_NUMBER, RANK, LAG, LEAD, etc.)
- String functions (UPPER, LOWER, SUBSTR, REPLACE, etc.)
- Date/time functions (DATE, TIME, DATETIME, STRFTIME)
- JSON functions (JSON, JSON_EXTRACT, JSON_SET, etc.)
- WebSocket server mode (v3.0, multi-client support)
- Subprocess server mode (v2.0, backward compatible)
Requirements
- Python 3.8+
- For WebSocket mode:
pip install websocket-client(auto-installed as dependency)
Development
To use a local Rust binary instead of downloading from GitHub:
export SQL5_BINARY=/path/to/local/sql5
python -c "import sql5; print(sql5.__version__)"
License
MIT
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
sql5-3.2.3.tar.gz
(14.3 kB
view details)
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
sql5-3.2.3-py3-none-any.whl
(10.0 kB
view details)
File details
Details for the file sql5-3.2.3.tar.gz.
File metadata
- Download URL: sql5-3.2.3.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e00b27a37e9af9971d58bae2f72f056ed11def945d34fa73d795a8a56af4426
|
|
| MD5 |
af45bbd7b93a79b09b55bea8e43a0e96
|
|
| BLAKE2b-256 |
b50687ecf61f27e58413fa76a57a1b7981d138db5cd27b99902334a6aecc846f
|
File details
Details for the file sql5-3.2.3-py3-none-any.whl.
File metadata
- Download URL: sql5-3.2.3-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cff31a6cdf178b1ac69167a73725f2f0e7c425d87b82f462b0692ac759d555ec
|
|
| MD5 |
4adcf8ec03f29115b1cdbaa2442044b9
|
|
| BLAKE2b-256 |
23ac8868eae8c2cafa53debf1ef20b854c955dcaddcb86657a271e21a965a840
|