Skip to main content

SQLite database dumper, dump any SQLite database into JSON-ready Python objects with schema introspection, caching, and a checksummed binary config system.

Features

  • Full dumps + table filters: dump everything, or restrict to specific tables.
  • JSON-ready output: to_dict(), to_json(), and atomic save() to file.
  • Schema introspection: CREATE statements, view names, and index names captured.
  • Smart caching: LRU cache invalidated automatically when the database file changes (mtime/size) or the table filter differs.
  • Safety limits: row limits with truncation flags, database size guards, optional strict mode.
  • Binary config files: sha256-checksummed, tamper-detecting, optionally bz2/lzma/zlib-compressed.
  • Zero dependencies: pure Python standard library (sqlite3, json, hashlib, pickle, bz2, lzma, zlib)

Installation

pip install dumpb

Requires Python 3.8+. No third-party dependencies.

Quickstart

import dumpb

# Dump the whole database
result = dumpb.dump("app.db")

print(result.stats())
# {'tables': 3, 'rows': 128, 'views': 1, 'indexes': 2}

users = result.get_table("users")
print(users.schema)      # 'CREATE TABLE users (...)' as stored in sqlite_master
print(users.rows)        # [{'id': 1, 'name': 'alice', 'score': 9.5}, ...]
print(users.row_count)   # 3

# Persist as pretty-printed JSON (written atomically)
result.save("dump.json", indent=2)

Filtered dumps

result = dumpb.dump("app.db", tables=["users", "orders"])
result.tables        # [TableDump users, TableDump orders]

Requesting a table that does not exist records an error in result.errors instead of raising — unless strict mode is on.

Custom engine

from dumpb import DumpEngine

engine = DumpEngine({
    "row_limit": 100,        # max rows per table
    "strict_mode": True,     # raise DumpbError on any dump issue
    "max_file_size_mb": 50,  # refuse databases larger than 50 MB
})
result = engine.dump("app.db")

Reusing an engine enables the LRU result cache: dumping the same database twice (unchanged file, same filter) returns the same DumpResult instantly.

Configuration keys

Defaults live in dumpb.DEFAULT_CONFIG and can be overridden per engine, per config file, or per dump() call (table filters only).

Key Type Default Description
tables list / None None Table filter; None dumps all tables
include_schema bool True Capture CREATE statements in each TableDump
row_limit int / None None Max rows per table; sets truncated when hit
max_file_size_mb float / None 100 Refuse databases larger than this; 0 disables
cache_size int 20 LRU cache capacity (number of dump results)
read_only bool True Open the database in SQLite read-only URI mode
detect_types bool True Enable sqlite3.PARSE_DECLTYPES type detection
strict_mode bool False Raise DumpbError instead of collecting errors

Config files

dumpb.settings persists engine settings with a strict binary layout:

raw:   [8-byte sha256 checksum][4-byte size][pickle payload]
bz2:   [8-byte sha256 checksum][4-byte size][bz2.compress(pickle payload)]
lzma:  [8-byte sha256 checksum][4-byte size][lzma.compress(pickle payload)]
zlib:  [8-byte sha256 checksum][4-byte size][zlib.compress(pickle payload)]
from dumpb import save_config, load_config, find_default_config

save_config({"row_limit": 42}, "engine.config")            # raw
save_config({"row_limit": 7}, "engine.config", "lzma")     # compressed
save_config({"row_limit": 3}, "engine.config", "bz2")      # compressed
cfg = load_config("engine.config")
cfg.get("row_limit")                                       # 7

# No path: locates schema.tpl next to the caller's module
save_config({"tables": ["users"]})
find_default_config()                                      # Path to schema.tpl

Data model

DumpResult

Member Description
database Path of the dumped database
tables List of TableDump (tables only; views are names)
views, indexes Metadata name lists from sqlite_master
errors Non-fatal issues collected during the dump
get_table(name) TableDump by name, or None
iter_tables() Iterator over tables
total_rows() Sum of row counts
stats() {'tables': n, 'rows': n, 'views': n, 'indexes': n}
to_dict() / to_json() Structured dict / JSON string (default=str)
save(path, indent=None) Atomic JSON file write; returns the Path

TableDump

Member Description
name Table name
otype Object type ('table')
schema CREATE statement from sqlite_master (if enabled)
rows List of row dicts (column name → value)
truncated True when row_limit cut rows off
row_count Number of captured rows
column_names() Union of column keys across rows, in first-seen order

Error handling

DumpbError                    # dump failures, limits, strict-mode issues
ConfigLoadError               # missing, unreadable, malformed, unsafe configs
├── ConfigChecksumError       # payload fails its checksum (tamper/corruption)
└── ConfigDecompressError     # xz/zlib payload cannot be decompressed
import dumpb
from dumpb import DumpbError, ConfigChecksumError

try:
    dumpb.dump("missing.db")
except DumpbError as exc:
    print("dump failed:", exc)

Behavior notes

  • Internal sqlite_* objects (sqlite_sequence, autoindexes, …) are excluded.
  • Views and indexes are listed as metadata; only tables are row-dumped.
  • bytes values (BLOB columns) are kept as-is in Python and stringified safely by to_json() / save().
  • Cache keys combine the absolute path, mtime, size, and the effective table filter, so editing the database or changing filters never returns stale data.
  • read_only=True opens the file in SQLite URI read-only mode, falling back to a normal connection on unsupported platforms.

API reference

Module Exports
dumpb dump, DumpEngine, DumpResult, TableDump, DEFAULT_CONFIG, Config, load_config, save_config, find_default_config, all errors
dumpb.dumper DumpEngine, LRUCache, DEFAULT_CONFIG
dumpb.reader DatabaseReader
dumpb.model DumpResult, TableDump
dumpb.settings Config, load_config, save_config, find_default_config
dumpb.errors DumpbError, ConfigLoadError, ConfigChecksumError, ConfigDecompressError

License

MIT

Metadata

Release files for dumpb 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dumpb 0.0.3
File Size Uploaded Provenance Actions
dumpb-0.0.3.tar.gz 15.1 kB Without provenance Details for dumpb-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dumpb 0.0.3
File Interpreter ABI Platform Actions
dumpb-0.0.3-py3-none-any.whl Python 3 none any Details for dumpb-0.0.3-py3-none-any.whl

Total release size: 29.0 kB

Release files / dumpb-0.0.3.tar.gz

Download URL dumpb-0.0.3.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f271d07ef3ee08a14e390e26184f7d1d8fc3485eca6f155d999792c898feb716
BLAKE2b-256 checksum
How to use checksums
122b671dc60a580e81b511788855a7794a4cb083ee619d59c98526c010641c67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / dumpb-0.0.3-py3-none-any.whl

Download URL dumpb-0.0.3-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48aa88c7476dcccb346cb44732e0106eb5d858a001f1f7db19b2e3202740dbf4
BLAKE2b-256 checksum
How to use checksums
5e52e3d554b9244df357a39d110dc2f0e6830be3906c362677679efbbb21e13b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for dumpb 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page