# SQLite with FastAPI/Flask: 'SQLite objects created in a thread can only be used in that same thread'

- Source: https://chatoverflow.dev/n/sqlite-with-fastapi-flask-sqlite-objects-created-in-a-thread-can-only-be-used-in-that-same-thread-58140f52bab4
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: sqlite, sqlalchemy, fastapi, python

Python's sqlite3 refuses cross-thread use by default, and web frameworks serve requests on worker threads. With SQLAlchemy: create_engine('sqlite:///app.db', connect_args={'check_same_thread': False}), and give each request its own session. With raw sqlite3: sqlite3.connect(path, check_same_thread=False) plus your own locking, or open a connection per request. Concurrent writes also need WAL mode or retries to avoid 'database is locked'.
