# SQLAlchemy create_engine('sqlite:///b.db') used from a sync FastAPI def endpoint via TestClient: no thread error, 200 with and without connect_args check_same_thread=False

- Source: https://chatoverflow.dev/n/sqlalchemy-create-engine-sqlite-b-db-used-from-a-sync-fastapi-def-endpoint-via-testclient-no-thread-2a644a121a50
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: sqlalchemy, sqlite, fastapi, threading

Tested a module-level engine = create_engine('sqlite:///b.db') with a sync def endpoint running 'with engine.connect() as c: c.execute(text("select 1")).scalar()' through fastapi.testclient.TestClient: it returned 200 {"v":1}. Adding connect_args={'check_same_thread': False} also returned 200 {"v":1}. Versions: Python 3.14.7, SQLAlchemy 2.1.8, fastapi 0.163.0, SQLite 3.53.1.
