python-async-sqlite

Enforces safe SQLite patterns for asyncio-based Python applications.

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/ZaxbyHub/ragappv3 --skill python-async-sqlite-zaxbyhub
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-async-sqlite
Source: https://github.com/ZaxbyHub/ragappv3/tree/main/.opencode/skills/generated/python-async-sqlite
Command: npx skills add https://github.com/ZaxbyHub/ragappv3 --skill python-async-sqlite-zaxbyhub

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Mixing synchronous SQLite calls with asyncio causes subtle bugs: cursors are not thread-safe, async functions passed to asyncio.to_thread() return coroutines instead of results, and rollbacks executed outside the worker thread leave transactions in a broken state. This Skill codifies the correct patterns so these errors never reach production. ## Core Features & Use Cases - Thread-Safe Query Patterns: Consolidate execute() and fetch*() calls into a single asyncio.to_thread() invocation so cursors never cross thread boundaries. - Transaction Safety: Handle commit and rollback inside the same named function that runs in the worker thread, preventing partial transaction states. - Connection Configuration: Enforce check_same_thread=False on connections shared across threads, including pool-managed connections. - Use Case: When refactoring a FastAPI endpoint from sync to async database access, apply these rules to avoid "coroutine object has no attribute 'fetchone'" errors and "database is locked" failures. ## Quick Start Review my FastAPI database code and fix any unsafe SQLite asyncio patterns using the python-async-sqlite rules.

Frequently Asked Questions about python-async-sqlite

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use SQLite with asyncio in Python?▼

Wrap synchronous sqlite3 calls in asyncio.to_thread() with a single sync function that performs execute and fetch together. Never pass async functions to to_thread, and set check_same_thread=False on the connection.

How to fix "coroutine object has no attribute 'fetchone'" error?▼

This error means an async function was passed to asyncio.to_thread(), so it returned a coroutine instead of query results. Convert the inner function to a regular synchronous def and await the to_thread call.

Are SQLite cursors thread-safe in Python?▼

No, sqlite3 cursor objects are not thread-safe. Splitting execute() and fetchone() across separate asyncio.to_thread() calls can corrupt the cursor. Consolidate both operations into one function running in a single thread.

Why does SQLite raise "database is locked" with asyncio?▼

This typically happens when multiple threads access a connection created without check_same_thread=False, or when transactions are left open. Set check_same_thread=False and handle commit/rollback inside the worker function.

How do I handle SQLite transaction rollback with asyncio.to_thread?▼

Place the try/except with commit and rollback inside the same named function passed to to_thread. Rolling back in an outer exception handler runs in a different thread than the transaction, leaving partial state.

Can I use a SQLite connection pool with asyncio?▼

Yes, pool checkout is synchronous and safe to wrap in to_thread. Apply the same consolidation rule for all operations on a checked-out connection, and set check_same_thread=False in the pool's connection factory.