Skip to main content

True async SQLite — no fake async, no GIL stalls.

Project description

rapsqlite

True async SQLite — no fake async, no GIL stalls.

PyPI version Downloads Python 3.10+ License: MIT Documentation

Overview

rapsqlite provides true async SQLite for Python, backed by Rust, Tokio, and sqlx. Database operations run outside the Python GIL, so the event loop never stalls. Use it as a drop-in replacement for aiosqlite with better concurrency and no thread pools.

📚 Full Documentation · Quickstart · API Reference · ROADMAP

Why rap*?

Packages prefixed with rap stand for Real Async Python. Unlike many libraries that merely wrap blocking I/O in async syntax, rap* packages guarantee that all I/O work is executed outside the Python GIL using native runtimes (primarily Rust). This means event loops are never stalled by hidden thread pools, blocking syscalls, or cooperative yielding tricks. If a rap* API is async, it is structurally non-blocking by design, not by convention. The rap prefix is a contract: measurable concurrency, real parallelism, and verifiable async behavior under load.

See the rap-manifesto for philosophy and guarantees.

Top Features

  • True async — All SQLite I/O runs outside the Python GIL (Rust + Tokio + sqlx)
  • 🚫 No fake async — Zero thread pools; event-loop-safe concurrency
  • 🔄 aiosqlite-compatible — ~95% API parity, drop-in replacement
  • 🏊 Connection pooling — Configurable size and timeouts
  • 🚀 Prepared statement caching — Automatic (2–5x faster repeated queries)
  • 🐍 SQLAlchemy 2.0+sqlite+rapsqlite dialect for async Core and ORM
  • 📦 Alembic — Full support for async migrations (alembic init -t async)

See the documentation for the full feature list (transactions, cursors, row factories, backup, callbacks, type adapters, and more).

Requirements

  • Python 3.10+ (including Python 3.13 and 3.14)
  • Rust 1.70+ (for building from source)
  • Python development headers (included with most Python installations)

Installation

pip install rapsqlite

To verify: run the installation example in the docs (it prints [[1]]). For building from source, see Installation.

Documentation

📖 rapsqlite.readthedocs.io – Quickstart, API reference, migration from aiosqlite, performance, and advanced usage. Code examples are tested and show real output.


Quick Start

import asyncio
from rapsqlite import connect

async def main():
    async with connect("example.db") as conn:
        await conn.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)")
        await conn.execute("INSERT INTO users (name) VALUES ('Alice')")
        rows = await conn.fetch_all("SELECT * FROM users")
        print(rows)

asyncio.run(main())

Output: [[1, 'Alice']]

SQLAlchemy & Alembic (0.3.2)

Use the sqlite+rapsqlite dialect with SQLAlchemy 2.0+ for true async ORM and Core. Alembic migrations are fully supported with the async template (alembic init -t async).

import asyncio
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine

async def main():
    engine = create_async_engine("sqlite+rapsqlite:///app.db")
    async with engine.connect() as conn:
        result = await conn.execute(text("SELECT 1"))
        print(result.scalar())  # 1
    await engine.dispose()

asyncio.run(main())

Install with pip install rapsqlite[sqlalchemy] (or pip install rapsqlite sqlalchemy). For Alembic, use pip install rapsqlite[sqlalchemy] alembic. See the Compatibility Guide for AsyncSession, ORM, and step-by-step Alembic setup.

For more (transactions, cursors, row factories), see the Quickstart Guide and API Reference. Code examples in the docs are tested and show real output.

API Reference

Complete API documentation is at rapsqlite.readthedocs.io:

Backup Support

The Connection.backup() method supports backing up to both rapsqlite.Connection and Python's standard sqlite3.Connection targets. For sqlite3.Connection targets, the backup uses Python's sqlite3 backup API on the on-disk database file (file-backed databases only; :memory: and non-file URIs are not supported).

For more details, see the Backup documentation in the API reference.

Performance

This package passes the Fake Async Detector. For detailed performance benchmarks and optimization tips, see the Performance Guide.

Key advantages:

  • True async: All operations execute outside the Python GIL
  • Prepared statement caching: Automatic query optimization via sqlx (2-5x faster for repeated queries)
  • Better throughput: Superior performance under concurrent load due to GIL independence
  • Connection pooling: Efficient connection reuse with configurable pool size

Migration from aiosqlite

rapsqlite is designed to be a drop-in replacement for aiosqlite. The simplest migration is a one-line change:

# Before
import aiosqlite

# After
import rapsqlite as aiosqlite

For most applications, this is all you need! All core aiosqlite APIs are supported, including:

  • Connection and cursor APIs
  • async with db.execute(...) pattern
  • Async iteration on cursors (async for row in cursor)
  • Parameterized queries (named and positional)
  • Transactions and context managers
  • Row factories (including rapsqlite.Row class)
  • Connection properties (total_changes, in_transaction, text_factory)
  • executescript() and load_extension() methods
  • Exception types

Practical compatibility notes:

  • total_changes / in_transaction: both aiosqlite and rapsqlite expose these as properties (same API):

    # aiosqlite and rapsqlite
    changes = db.total_changes
    in_tx = db.in_transaction
    
  • iterdump(): rapsqlite supports both async iteration (aiosqlite-style) and await-to-list:

    # aiosqlite and rapsqlite (async iterator)
    lines = [line async for line in db.iterdump()]
    
    # rapsqlite
    lines = await db.iterdump()
    dump_sql = "\n".join(lines)
    
  • backup() targets: rapsqlite supports backups to both rapsqlite.Connection and sqlite3.Connection targets. For sqlite3.Connection targets, only file-backed databases are supported (not :memory: or non-file URIs).

See the Migration Guide for a complete migration guide with:

  • Step-by-step migration instructions
  • Code examples for common patterns
  • API differences and limitations
  • Troubleshooting guide
  • Performance considerations

Compatibility Analysis: See the Compatibility Guide for detailed analysis based on running the aiosqlite test suite. Overall compatibility: ~95% for core use cases (updated 2026-01-26). All high-priority compatibility features implemented including total_changes(), in_transaction(), executescript(), load_extension(), text_factory, Row class, and async iteration on cursors.

Roadmap

See docs/ROADMAP.md for full details.

  • Phase 1 – Connection lifecycle, transactions, type system, error handling, cursor API
  • Phase 2 – Parameterized queries, pool/row factory, transaction context managers, backup/dump, schema introspection, init hooks, prepared statement caching
  • Phase 3 – Type adapters/converters, custom aggregates/collations, True Async DBAPI, aiosqlite-style API parity
  • 🔜 Next – Dynamic pool sizing, deadlock handling, 100% aiosqlite test suite coverage

Related Projects

Changelog

See CHANGELOG.md for detailed release notes and version history.

Limitations

  • Async only – Not designed for synchronous use; use sqlite3 for sync code.
  • Backup to sqlite3.Connection – Supported for file-backed databases only (not :memory: or non-file URIs). See Backup Support above.

Release history and full feature list: CHANGELOG.md.

Contributing

Contributions are welcome! Please see our contributing guidelines.

License

MIT

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

rapsqlite-0.3.3.tar.gz (296.5 kB view details)

Uploaded Source

Built Distributions

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

rapsqlite-0.3.3-cp310-abi3-win_arm64.whl (2.7 MB view details)

Uploaded CPython 3.10+Windows ARM64

rapsqlite-0.3.3-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

rapsqlite-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

rapsqlite-0.3.3-cp310-abi3-musllinux_1_2_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

rapsqlite-0.3.3-cp310-abi3-manylinux_2_28_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

rapsqlite-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

rapsqlite-0.3.3-cp310-abi3-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

rapsqlite-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file rapsqlite-0.3.3.tar.gz.

File metadata

  • Download URL: rapsqlite-0.3.3.tar.gz
  • Upload date:
  • Size: 296.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for rapsqlite-0.3.3.tar.gz
Algorithm Hash digest
SHA256 f3719ab9cd3c24163b958b80a0a107baa1a984d0af7de22f3588f833cf01e4de
MD5 194f11a339f3f87d3525405756723f49
BLAKE2b-256 d66b2ba6ab8ef2d4a8faece7234f0698adf8312514a6d517742cf1a61e134969

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b0ea51067ee9800beaf5077ba474b0e9bf48bc19066ff2d51313a0b26024e4cf
MD5 0245e484d4d653cc093216c6b1648f8f
BLAKE2b-256 04545f7d63cb6b31c0e22816831c0c5bb4403efc46789efa416bdcf8f4350843

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1498ebbb2e88ae4fd8296cea981529f905f2610747d898f1de13f2d4602886cc
MD5 7807fa6fdef4e626c567eb5a9b645e38
BLAKE2b-256 49fd7f6bafe28934e76c3e6e539d108aa1d7edb0e8ce47e54d90a6255a6e7155

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c93d3f4d66a20cdff92845ddde331aa3073aabcd06f427d765d6464a719f5f0d
MD5 61dc99e808e65ff18a3af50f663a85e9
BLAKE2b-256 aeae4ef330be0892a0ffd06da846293b1e87ab45d9ff99f0123ceac48db08c0e

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fc9b07a279578c8a104c2469647f0e50b0a1ee81468e1884774996b971d480d2
MD5 e516ced60b867b0391ae4fd5f719e061
BLAKE2b-256 ac9491b4b2ca22ce5c59f3c134cb97bc1ba0f3214237399f094c6e0e31efab0b

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d188527d9e515d665b28d086af9c0080971a4f31776903356fb7518445b1d48a
MD5 09d03b077cd33baa2bbd54ca2463d1bb
BLAKE2b-256 4c9915987ec2266441819b28dc5ce20db8d405fa2c284b771c37477281cf6806

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4309a081c5242d32b2fb3211a42bb8c98e3530c792afc15e9f0df3b418e3df7
MD5 59462562b4378a778a8f4eb7a931dc5f
BLAKE2b-256 d9d122863aa2b380d2b8c648294e23d90e073104fc35117378f3c8416de35bd5

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c2c2252efc426f7d33caa43cb9bf90ff4fcb7f15c8287bfe932f6e3b8fd9a12d
MD5 e4fb90ab9f3a57a2dc039a11462845e0
BLAKE2b-256 ce134cbe5e28cc24f45f577b5424c3b4c64e79353a0e0284299cb5840c34f1e4

See more details on using hashes here.

File details

Details for the file rapsqlite-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rapsqlite-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f9d0a2a970de56c06e3a72a6645a772477c9c913bf8b7212a92082db35ce2c9a
MD5 e8f6edca5de53fa01c53713256f4fc63
BLAKE2b-256 12eb1f920aa9e124aaae3ff199dd90e06da9fb541a94a7a76244e75462e699d0

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