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.2.tar.gz (296.4 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.2-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

rapsqlite-0.3.2-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.2-cp310-abi3-musllinux_1_2_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

rapsqlite-0.3.2-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.2-cp310-abi3-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

rapsqlite-0.3.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for rapsqlite-0.3.2.tar.gz
Algorithm Hash digest
SHA256 1120bd7e87e72df414796227ee311491b10ea7b5986d64d734e98d7836cfbc23
MD5 1b2ebde9af044cca1dfb90cea4f2aba7
BLAKE2b-256 e8427dcb36dafb09c2c99138d82079f510eeb1a999d24ffd1c8a5d081c30a1f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rapsqlite-0.3.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 56384f81a762d9a4c61d82d3f48568311708c3370633ac6969d531c1d43e68ea
MD5 e58a09d248dfd8be247d839976e47af8
BLAKE2b-256 3a709106bcb194699ce27ca3b59997f7fa88bfb7d3c59c8e605ae8b39254067f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rapsqlite-0.3.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 48481e658815c649698ea58e59e558ead43dbdba245c86304d1c1ab41bb94385
MD5 56b407b18c1409a8a2b8c48a34138ac3
BLAKE2b-256 16f7a7125fab1137a6a944d5ae4226cf6d7b5dff0e46debc93111103eb9c0f0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rapsqlite-0.3.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fdbe85b0e4fc0b1126d00a79fabd76fe269a7ee03a18ee35e8f494753ed4f622
MD5 6c1b9fa004fb538ab0b2137efa0c8d96
BLAKE2b-256 41b662ffac925179c08d54a60e30bd9230f54188a4216109729745676ecca47d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rapsqlite-0.3.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 752337e7bd0410660d8e9d45507a108541f9824730369cecbe5de76fc23c9f0a
MD5 66dca13d247c0de71a2765050790759f
BLAKE2b-256 d413aa4c652df70875d72df7abb744cfe16130006ba76e87e4b70e46a0c45293

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rapsqlite-0.3.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a388d305441992632d6c0cb0a165ffb141d60fdba62255d3161a66568fe9abb1
MD5 7d1f8079c1952c176490f613bc8835ef
BLAKE2b-256 099d42e9e7713d1cad0aa0d3f74abe8eb1e2dabae428f35dce1cee45e88c3160

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rapsqlite-0.3.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83deb419f75e11f2a2a0e9db41199f187fbf9604e364e2a9e6b79056ec0195d2
MD5 fb1a16711bf1bee95dabcc7c182ea016
BLAKE2b-256 263426ec3769fb5c675589c4245009ad2a291a07363332864df6ac0278ec4e90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rapsqlite-0.3.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 363cea98677badf76ce1d11c63aa213227251adfd9aab1ffd992e45f7e4f5e16
MD5 93a90f4290c884fbe489f92ab450a7b3
BLAKE2b-256 29eb9c37238dd25bbb51d912e84d9b0b55fd78613714a0643c12a2e78b153a87

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