On this page
sqlite3.Blob
Prev: sqlite3.Binary | Up: sqlite3 | Next: sqlite3.complete_statement
Rel: sqlite3.adapt, sqlite3.Binary, sqlite3.complete_statement, sqlite3.connect
Ref: docs.python.org — sqlite3.Blob
Tags: #public #python3 #stdlib #sqlite3
Import
import sqlite3
from sqlite3 import Blob
Signature & Overview
sqlite3.Blob()
sqlite3.Blob class.
Methods & Attributes
Blob.close(self, /)— Close the blob.Blob.read(self, length=-1, /)— Read data at the current offset position.Blob.seek(self, offset, origin=0, /)— Set the current access position to offset.Blob.tell(self, /)— Return the current access position for the blob.Blob.write(self, data, /)— Write data at the current offset.
Usage
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE files (id INTEGER PRIMARY KEY, data BLOB)")
con.execute("INSERT INTO files VALUES (1, zeroblob(8))")
with con.blobopen("files", "data", 1) as blob:
blob.write(b"12345678")
blob.seek(0)
assert blob.read(4) == b"1234"
con.close()
Gotchas
- Requires Python 3.11+: Opened via
con.blobopen(table, column, rowid)for streaming random-access I/O on large BLOBs without loading them fully into RAM. - Fixed size: A
Blobhandle cannot resize the column—pre-allocate withzeroblob(n).
REPL Inspect
from sqlite3 import Blob
help(Blob)
Linked from
- tuts/python3/stdlib_module/sqlite3
- tuts/python3/stdlib_module/sqlite3/adapt
- tuts/python3/stdlib_module/sqlite3/Binary
- tuts/python3/stdlib_module/sqlite3/complete_statement
- tuts/python3/stdlib_module/sqlite3/connect
- tuts/python3/stdlib_module/sqlite3/Connection
- tuts/python3/stdlib_module/sqlite3/Cursor
- tuts/python3/stdlib_module/sqlite3/DatabaseError
- tuts/python3/stdlib_module/sqlite3/DataError
- tuts/python3/stdlib_module/sqlite3/Date
- tuts/python3/stdlib_module/sqlite3/DateFromTicks
- tuts/python3/stdlib_module/sqlite3/enable_callback_tracebacks
- tuts/python3/stdlib_module/sqlite3/Error
- tuts/python3/stdlib_module/sqlite3/IntegrityError
- tuts/python3/stdlib_module/sqlite3/InterfaceError
- tuts/python3/stdlib_module/sqlite3/InternalError
- tuts/python3/stdlib_module/sqlite3/NotSupportedError
- tuts/python3/stdlib_module/sqlite3/OperationalError
- tuts/python3/stdlib_module/sqlite3/PrepareProtocol
- tuts/python3/stdlib_module/sqlite3/ProgrammingError
- tuts/python3/stdlib_module/sqlite3/register_adapter
- tuts/python3/stdlib_module/sqlite3/register_converter
- tuts/python3/stdlib_module/sqlite3/Row
- tuts/python3/stdlib_module/sqlite3/Time
- tuts/python3/stdlib_module/sqlite3/TimeFromTicks
- tuts/python3/stdlib_module/sqlite3/Timestamp
- tuts/python3/stdlib_module/sqlite3/TimestampFromTicks
- tuts/python3/stdlib_module/sqlite3/Warning
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/complete_statement Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/connect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Connection links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Cursor links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/DatabaseError links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/DataError links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Date links to this page; shared tags: #stdlib