Skip to main content

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.4.0)

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

For process-local cache lookups, 0.5 adds fetch_scalar()/fetch_blob(), an opt-in raw_fetch_scalar() path, reusable conn.prepare(...) operations, and opt-in session_affinity=True. These APIs are measured separately from the general row API; use the Phase 0.5 benchmark and do not treat unmatched raw SQLite or published Redis figures as a direct speed claim.

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.

  • ✅ 0.1–0.3 – Async core, aiosqlite compatibility, callbacks, pooling, True Async DBAPI, SQLAlchemy/Alembic integration, and advanced SQLite features
  • ✅ 0.4 – Post-v0.3.3 compatibility, security, CI, SQLAlchemy 2.1 support, and release stabilization (v0.4.0)
  • ✅ 0.5 – Released as v0.5.0: measured low-latency execution, hot-path reductions, scalar/BLOB and prepared-query paths, opt-in session affinity, and an opt-in raw path
  • 📋 0.6 – In progress: cache get/set with TTL shipped in v0.5.0; bulk operations and multiplexed concurrent reads remain
  • 📋 0.7–0.9 – Pooling, observability, reliability, ecosystem tooling, and stabilization toward 1.0

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

Metadata

Release files for rapsqlite 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rapsqlite 0.5.1
File Size Uploaded
rapsqlite-0.5.1.tar.gz 466.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for rapsqlite 0.5.1
File
rapsqlite-0.5.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
rapsqlite-0.5.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
rapsqlite-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
rapsqlite-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
rapsqlite-0.5.1-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
rapsqlite-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
rapsqlite-0.5.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
rapsqlite-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 27.0 MB

Release files / rapsqlite-0.5.1.tar.gz

Download URL rapsqlite-0.5.1.tar.gz
Size 466.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a26c4544042a92086d24651d24468cf14708fae409ae0cabc9e2d8d18f4415d1
BLAKE2b-256 checksum
How to use checksums
dfd613db9b93604565b4124fa713c2401181196daa72dae19b197eed8bc33106
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-win_arm64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-win_arm64.whl
Size 3.1 MB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
c65678dbdbcd8481f7d943076f5ae9d8aa61bf441e14ef3efdc5f7f9385ae6da
BLAKE2b-256 checksum
How to use checksums
ddbbfdce3c203e3706e0234f5d0791e28b7b369fb0d271dfb69c8cd364b3c11f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-win_amd64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-win_amd64.whl
Size 3.6 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d4837fdc58e41f5cbfe0f897d7136d6b813a195fbfd9d94ff6501ea8292efaa0
BLAKE2b-256 checksum
How to use checksums
4a23b0588ab7a20af7b1736a9da96ae1f12728a3d435ba0a8f9ff20601b34222
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 3.5 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
b68eef2b108ddd2f81b4b1be551fe0f8acbff3a9829e1b472be9e8b9978f7965
BLAKE2b-256 checksum
How to use checksums
67d3b7b3da4a568e69afe52437ae088890a45632ff56c91dfb72aae185014e29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 3.5 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
b6a7145422b34221a042e6ed68b38696c9effd27be102d22c5032c328fe01e25
BLAKE2b-256 checksum
How to use checksums
a8aa4472e48921319aae1d3239bf0fe6d51f402763ca37d9952db5c1c4849361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-manylinux_2_28_aarch64.whl
Size 3.3 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
a4ccac5555428402180fac57c9eed79a04c9919ba321348790b0d290b4f20c73
BLAKE2b-256 checksum
How to use checksums
4045ef864618baa3f37b151d11318d2567b5f51bc0d8f143e8e74afda7d0e956
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
361593b16c7670034b056a939639509b301881c795981f2d616d321012d3892b
BLAKE2b-256 checksum
How to use checksums
cef3fa82164464cb73ac9df1a61ebfe86dc53cc783afc73a043211a46267b3b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
Size 3.1 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2ce2122b8838e3285804170914de07236b61ab1d7d88fb4e14604bf566a6d706
BLAKE2b-256 checksum
How to use checksums
dbeeabddea63e26564569860620462eeac557ba4679fa09fbfd9637adfeb0772
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / rapsqlite-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL rapsqlite-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.2 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
41126c6d2763cf841232b8a14ae9db2902dd8b847f12d7e13d28ec42fed9729d
BLAKE2b-256 checksum
How to use checksums
204d8599b8271bc8f092290a8be98511c6ce3b5a78258c5267f95c93481bdae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.5.1 This release

9 release files

0.5.0

9 release files

0.4.0

9 release files

0.3.3

9 release files

0.3.2

8 release files

0.3.1

33 release files

0.2.0

40 release files

0.1.2

40 release files

0.1.1

34 release files

0.1.0

28 release files

0.0.2

34 release files

0.0.1

34 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page