{"id":603,"library":"aiosqlite","title":"AsyncIO SQLite","description":"aiosqlite provides a friendly, async interface to SQLite databases, replicating the standard `sqlite3` module but with asynchronous versions of all connection and cursor methods. It enables interaction with SQLite databases on the main AsyncIO event loop without blocking, utilizing a single, shared thread per connection for query execution. The current version is 0.22.1, and it maintains an active release cadence.","status":"active","version":"0.22.1","language":"python","source_language":"en","source_url":"https://github.com/omnilib/aiosqlite","tags":["asyncio","sqlite","database","orm"],"install":[{"cmd":"pip install aiosqlite","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"wrong":"import aiosqlite","symbol":"connect","correct":"from aiosqlite import connect"}],"quickstart":{"code":"import asyncio\nimport aiosqlite\nimport os\n\nasync def main():\n    db_path = os.environ.get('AIOSQLITE_DB_PATH', 'my_database.db')\n    async with aiosqlite.connect(db_path) as db:\n        # Create a table\n        await db.execute('''\n            CREATE TABLE IF NOT EXISTS users (\n                id INTEGER PRIMARY KEY AUTOINCREMENT,\n                name TEXT NOT NULL,\n                age INTEGER\n            )\n        ''')\n        await db.commit()\n\n        # Insert data\n        await db.execute(\"INSERT INTO users (name, age) VALUES (?, ?)\", (\"Alice\", 30))\n        await db.execute(\"INSERT INTO users (name, age) VALUES (?, ?)\", (\"Bob\", 24))\n        await db.commit()\n\n        # Query data\n        async with db.execute(\"SELECT id, name, age FROM users WHERE age > ?\", (25,)) as cursor:\n            print(\"Users older than 25:\")\n            async for row in cursor:\n                print(f\"  ID: {row[0]}, Name: {row[1]}, Age: {row[2]}\")\n\n        # Update data\n        await db.execute(\"UPDATE users SET age = ? WHERE name = ?\", (31, \"Alice\"))\n        await db.commit()\n\n        # Delete data\n        await db.execute(\"DELETE FROM users WHERE name = ?\", (\"Bob\",))\n        await db.commit()\n\n        async with db.execute(\"SELECT COUNT(*) FROM users\") as cursor:\n            (count,) = await cursor.fetchone()\n            print(f\"Total users remaining: {count}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates creating a database, defining a table, inserting, querying, updating, and deleting data using `aiosqlite`'s async context managers for connections and cursors. It ensures proper resource management by automatically committing transactions and closing connections."},"warnings":[{"fix":"Increase the `timeout` parameter when calling `aiosqlite.connect()` to allow SQLite more time to acquire locks (e.g., `aiosqlite.connect('db.db', timeout=10)`). Consider optimizing database schemas, queries, or using a connection pool (`aiosqlitepool`) for high-concurrency applications.","message":"Encountering 'Database is Locked' errors, especially in concurrent scenarios, is a common SQLite issue. While `aiosqlite` provides an async interface, SQLite itself is a single-file database and can face contention.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project runs on Python 3.9 or newer. Upgrade your Python environment if using an older version.","message":"Older Python versions are no longer supported. Python 3.7 and 3.8 support was dropped in versions 0.20.0 and 0.21.0 respectively.","severity":"breaking","affected_versions":"0.20.0+"},{"fix":"If using SQLAlchemy with `aiosqlite >= 0.22.0`, ensure you explicitly call `await engine.dispose()` at the end of your application's main function to properly close all connections and avoid hanging processes. Alternatively, disable connection pooling by using `NullPool`.","message":"When used with SQLAlchemy, `aiosqlite` versions 0.22.0 and above changed the internal connection class, which is no longer a daemon thread. This can cause applications to hang on exit if SQLAlchemy's `aiosqlite` dialect doesn't explicitly call `await engine.dispose()` to close connections.","severity":"breaking","affected_versions":"0.22.0+"}],"env_vars":null,"search_vec":"'0.22.1':55 'activ':60 'aiosqlit':3 'async':7 'asynchron':19 'asyncio':1,36,63 'block':40 'cadenc':62 'connect':23,47 'current':52 'cursor':25 'databas':11,32,65 'enabl':28 'event':37 'execut':50 'friend':6 'interact':29 'interfac':8 'loop':38 'main':35 'maintain':58 'method':26 'modul':16 'orm':66 'per':46 'provid':4 'queri':49 'releas':61 'replic':12 'share':44 'singl':43 'sqlite':2,10,31,64 'sqlite3':15 'standard':14 'thread':45 'util':41 'version':20,53 'without':39","created_at":"2026-03-28T17:06:48.893402+00:00","updated_at":"2026-04-15T19:42:03.181159+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"0.22.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/omnilib/aiosqlite","docs":"https://aiosqlite.omnilib.dev","changelog":null,"pypi":"https://pypi.org/project/aiosqlite/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":"verified"}}