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

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
  • 📋 0.5 – Low-latency execution and session affinity
  • 📋 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.4.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.4.0
File Size Uploaded
rapsqlite-0.4.0.tar.gz 321.3 kB Details

Built distributions (wheels)

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

Total release size: 25.2 MB

Release files / rapsqlite-0.4.0.tar.gz

Download URL rapsqlite-0.4.0.tar.gz
Size 321.3 kB
Tags Source
SHA-256 checksum
How to use checksums
39b7c77292aa908949b5d65603de6abe3fd27093fad066231b67fbc610c4399a
BLAKE2b-256 checksum
How to use checksums
1ec70a3dde9462848b8ccdb4b5953a25fa9b2b58b071bfc263f7cbf4ddf3a09c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

Download URL rapsqlite-0.4.0-cp310-abi3-win_amd64.whl
Size 3.3 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0d259e62b42e25eb1f21342e3f70fc9d4f2315d0be451b705fa139bd780f7958
BLAKE2b-256 checksum
How to use checksums
5024b330a8562d074b298e35fd668a5a1da7f3586dc24f6d3793ac3c503c5c95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

Download URL rapsqlite-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Size 2.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5d88f9f13215671826960f81012751432e23e9e88d8fb6bb85445ce8f607cdd8
BLAKE2b-256 checksum
How to use checksums
57e547379d5cc99100079615faa5f3ebba22b5e86d3ca41b5596c8eb165a7cf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

Download URL rapsqlite-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8c9f5038be85a7b3a76c9c3fc94eb581cdc4cb12d25083e9e8d721ad93cc655b
BLAKE2b-256 checksum
How to use checksums
d4e2a9a36ccfb6a7df46612643717a4b390b5ef746169f07313656e6353e0774
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.4.0 This release

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