# pydoc > _sqlite3

---
type: CommandReference
command: _sqlite3
mode: pydoc
section: 3
source: pydoc3
---

## Quick Reference

- `_sqlite3.connect(database)` — opens a connection to a SQLite database file
- `conn.execute(sql, parameters)` — executes an SQL statement
- `conn.executemany(sql, seq_of_parameters)` — repeatedly executes a statement
- `conn.executescript(sql_script)` — executes multiple SQL statements
- `cursor.execute(sql, parameters)` — executes a statement
- `cursor.fetchone()` — fetches one row
- `cursor.fetchall()` — fetches all rows
- `conn.commit()` — commits pending transaction

## Name

`_sqlite3` — SQLite database module

## Synopsis

`import _sqlite3`

## Classes

### Exception hierarchy

- `sqlite3.Error` (inherits `builtins.Exception`)
  - `sqlite3.InterfaceError` (inherits `Error`)
  - `sqlite3.DatabaseError` (inherits `Error`)
    - `sqlite3.DataError` (inherits `DatabaseError`)
    - `sqlite3.IntegrityError` (inherits `DatabaseError`)
    - `sqlite3.InternalError` (inherits `DatabaseError`)
    - `sqlite3.NotSupportedError` (inherits `DatabaseError`)
    - `sqlite3.OperationalError` (inherits `DatabaseError`)
    - `sqlite3.ProgrammingError` (inherits `DatabaseError`)
- `sqlite3.Warning` (inherits `builtins.Exception`)

All exception classes inherit standard `Exception` methods (`__init__`, `__new__`, `__str__`, `with_traceback`, etc.) and data descriptors (`args`, `__cause__`, `__context__`, `__traceback__`, `__dict__`).

### `sqlite3.Connection` — SQLite database connection object

**Methods:**

- `__init__(self, /, *args, **kwargs)` — initialize self
- `__enter__(self, /)` — context manager entry; returns self
- `__exit__(self, type, value, traceback, /)` — context manager exit; rolls back on exception, otherwise commits
- `backup(self, /, target, *, pages=-1, progress=None, name='main', sleep=0.25)` — makes a backup of the database
- `close(self, /)` — close the database connection (does not commit pending transaction)
- `commit(self, /)` — commit any pending transaction
- `create_aggregate(self, /, name, n_arg, aggregate_class)` — creates a new aggregate
- `create_collation(self, name, callback, /)` — creates a collation function
- `create_function(self, /, name, narg, func, *, deterministic=False)` — creates a new function
- `cursor(...)` — return a cursor for the connection
- `enable_load_extension(self, enable, /)` — enable dynamic loading of SQLite extension modules
- `execute(...)` — executes an SQL statement
- `executemany(self, sql, parameters, /)` — repeatedly executes an SQL statement
- `executescript(self, sql_script, /)` — executes multiple SQL statements at once
- `interrupt(self, /)` — abort any pending database operation
- `iterdump(self, /)` — returns iterator to the dump of the database in SQL text format
- `load_extension(self, name, /)` — load SQLite extension module
- `rollback(self, /)` — roll back to the start of any pending transaction
- `set_authorizer(self, /, authorizer_callback)` — sets authorizer callback
- `set_progress_handler(self, /, progress_handler, n)` — sets progress handler callback
- `set_trace_callback(self, /, trace_callback)` — sets a trace callback called for each SQL statement (passed as unicode)

**Data descriptors:**

- `DataError`, `DatabaseError`, `Error`, `IntegrityError`, `InterfaceError`, `InternalError`, `NotSupportedError`, `OperationalError`, `ProgrammingError`, `Warning` — exception classes
- `in_transaction` — whether a transaction is currently active
- `isolation_level` — isolation level for the connection
- `row_factory` — a callable that accepts cursor and row and returns a custom row object
- `text_factory` — a callable that accepts a bytes object and returns a string
- `total_changes` — total number of database rows changed by the connection

### `sqlite3.Cursor` — SQLite database cursor class

**Methods:**

- `__init__(self, /, *args, **kwargs)` — initialize self
- `__iter__(self, /)` — implement iter(self)
- `__next__(self, /)` — implement next(self)
- `close(self, /)` — closes the cursor
- `execute(self, sql, parameters=(), /)` — executes an SQL statement
- `executemany(self, sql, seq_of_parameters, /)` — repeatedly executes an SQL statement
- `executescript(self, sql_script, /)` — executes multiple SQL statements at once
- `fetchall(self, /)` — fetches all rows from the resultset
- `fetchmany(self, /, size=1)` — fetches several rows (default size from `arraysize`)
- `fetchone(self, /)` — fetches one row
- `setinputsizes(self, sizes, /)` — required by DB-API; does nothing in sqlite3
- `setoutputsize(self, size, column=None, /)` — required by DB-API; does nothing in sqlite3

**Data descriptors:**

- `arraysize` — number of rows to fetch with `fetchmany()`
- `connection` — connection that created this cursor
- `description` — column descriptions of the last executed query
- `lastrowid` — rowid of the last inserted row (if any)
- `row_factory` — row factory for this cursor
- `rowcount` — number of rows modified by the last DML statement

### `sqlite3.PrepareProtocol` — PEP 246 style object adaption protocol type

- `__init__(self, /, *args, **kwargs)` — initialize self

### `sqlite3.Row` — a row object

**Methods:**

- `__eq__(self, value, /)` — equality
- `__ge__(self, value, /)` — greater-or-equal
- `__getitem__(self, key, /)` — return self[key]
- `__gt__(self, value, /)` — greater than
- `__hash__(self, /)` — hash
- `__iter__(self, /)` — iterate over columns
- `__le__(self, value, /)` — less-or-equal
- `__len__(self, /)` — number of columns
- `__lt__(self, value, /)` — less than
- `__ne__(self, value, /)` — not equal
- `keys(self, /)` — returns the keys of the row (column names)

## Functions

- `adapt(obj, protocol, /)` — adapt given object to given protocol
- `complete_statement(sql, /)` — checks if a string contains a complete SQL statement
- `connect(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements, uri])` — opens a connection to the SQLite database file. Use `":memory:"` for in-memory database.
- `enable_callback_tracebacks(enable, /)` — enable or disable callback functions throwing errors to stderr
- `enable_shared_cache(enable, /)` — enable or disable shared cache mode (deprecated in Python 3.12); use URI `cache=shared` instead
- `register_adapter(type, callable, /)` — register a function to adapt Python objects to SQLite values
- `register_converter(typename, callable, /)` — register a function to convert SQLite values to Python objects

## Data

- `PARSE_COLNAMES = 2`
- `PARSE_DECLTYPES = 1`
- `SQLITE_ALTER_TABLE = 26`
- `SQLITE_ANALYZE = 28`
- `SQLITE_ATTACH = 24`
- `SQLITE_CREATE_INDEX = 1`
- `SQLITE_CREATE_TABLE = 2`
- `SQLITE_CREATE_TEMP_INDEX = 3`
- `SQLITE_CREATE_TEMP_TABLE = 4`
- `SQLITE_CREATE_TEMP_TRIGGER = 5`
- `SQLITE_CREATE_TEMP_VIEW = 6`
- `SQLITE_CREATE_TRIGGER = 7`
- `SQLITE_CREATE_VIEW = 8`
- `SQLITE_CREATE_VTABLE = 29`
- `SQLITE_DELETE = 9`
- `SQLITE_DENY = 1`
- `SQLITE_DETACH = 25`
- `SQLITE_DONE = 101`
- `SQLITE_DROP_INDEX = 10`
- `SQLITE_DROP_TABLE = 11`
- `SQLITE_DROP_TEMP_INDEX = 12`
- `SQLITE_DROP_TEMP_TABLE = 13`
- `SQLITE_DROP_TEMP_TRIGGER = 14`
- `SQLITE_DROP_TEMP_VIEW = 15`
- `SQLITE_DROP_TRIGGER = 16`
- `SQLITE_DROP_VIEW = 17`
- `SQLITE_DROP_VTABLE = 30`
- `SQLITE_FUNCTION = 31`
- `SQLITE_IGNORE = 2`
- `SQLITE_INSERT = 18`
- `SQLITE_OK = 0`
- `SQLITE_PRAGMA = 19`
- `SQLITE_READ = 20`
- `SQLITE_RECURSIVE = 33`
- `SQLITE_REINDEX = 27`
- `SQLITE_SAVEPOINT = 32`
- `SQLITE_SELECT = 21`
- `SQLITE_TRANSACTION = 22`
- `SQLITE_UPDATE = 23`
- `adapters = {}` (dict of registered adapters)
- `converters = {}` (dict of registered converters)
- `sqlite_version = '3.37.2'`
- `version = '2.6.0'`

## See Also

- [Python _sqlite3 module documentation](https://docs.python.org/3.10/library/_sqlite3.html)