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 – Implementation complete: measured low-latency execution, hot-path reductions, scalar/BLOB and prepared-query paths, opt-in session affinity, and an opt-in raw path; release validation remains
  • 📋 0.6 – Cache-specific APIs, bulk operations, and concurrent workloads
  • 📋 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

Release files for rapsqlite 0.5.0

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.0
File Size Uploaded
rapsqlite-0.5.0.tar.gz 452.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for rapsqlite 0.5.0
File
rapsqlite-0.5.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
rapsqlite-0.5.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
rapsqlite-0.5.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
rapsqlite-0.5.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
rapsqlite-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
rapsqlite-0.5.0-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.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
rapsqlite-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 26.2 MB

Release files / rapsqlite-0.5.0.tar.gz

Download URL rapsqlite-0.5.0.tar.gz
Size 452.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c527c7e96fbb5e68d05e9c31241513fdafa5dee26fa1dc4a4fc1997076ee3f04
BLAKE2b-256 checksum
How to use checksums
697593e328c56692b197bda693f5e10e88cdfcb46e806740e77096ee31ec41cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

Download URL rapsqlite-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 3.2 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
216923ca1752d8f183a3b67d857bb75e34f1f0ece086d8195ad0b2ee55795e0f
BLAKE2b-256 checksum
How to use checksums
09a14edd32ed76bc5a604accfb4357502bd24b4d948dd2214c9b66b2e0153f3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

Download URL rapsqlite-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a34eaea6d2f13846b388f22a88392569f91264aff9f2747cb0d53ca782aa729f
BLAKE2b-256 checksum
How to use checksums
b23b0c99ad28ce981510a511430a3c075bfdb260113f1035b6b803bdb48214d3
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.0 This release

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