On this page
sqlite3.connect
Prev: sqlite3.complete_statement | Up: sqlite3 | Next: sqlite3.Connection
Rel: sqlite3.adapt, sqlite3.Binary, sqlite3.Blob, sqlite3.complete_statement
Ref: docs.python.org — sqlite3.connect
Tags: #public #python3 #stdlib #sqlite3
Import
import sqlite3
from sqlite3 import connect
Signature & Overview
sqlite3.connect(...)
Open a connection to the SQLite database file 'database'.
Usage
import sqlite3
con = sqlite3.connect(":memory:", timeout=10.0)
try:
assert con.execute("SELECT 2 + 2").fetchone() == (4,)
finally:
con.close()
Gotchas
- Creates the database file if missing: Pass
uri=Truewith"file:app.db?mode=ro"to open strictly read-only. - Close connections explicitly:
with sqlite3.connect(...) as con:commits/rolls back transactions, but does not closecon.
REPL Inspect
from sqlite3 import connect
help(connect)
Linked from
Related notes
- tuts/python3/stdlib_module/sqlite3 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/adapt Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Binary Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Blob Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/complete_statement Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Connection Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib