Skip to main content

XDump

Build Coverage Version Python versions License

XDump is a utility to make a consistent partial dump and load it into the database.

The idea is to provide an ability to specify what to include in the dump via SQL queries.

Installation

$ pip install xdump

Usage example

Make a dump (on production replica for example):

from xdump.postgresql import PostgreSQLBackend

backend = PostgreSQLBackend(dbname="app_db", user="prod", password="pass", host="127.0.0.1", port="5432")
backend.dump(
    "/path/to/dump.zip",
    full_tables=["groups"],
    partial_tables={"employees": "SELECT * FROM employees ORDER BY id DESC LIMIT 2"},
)

Load a dump on your local machine:

backend = PostgreSQLBackend(dbname="app_db", user="local", password="pass", host="127.0.0.1", port="5432")
# If you need a clear DB
backend.recreate_database()  # or `backend.truncate()`
backend.load("/path/to/dump.zip")

Dump is compressed by default. Compression level could be changed with passing compression argument to dump method. Valid options are zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED, zipfile.ZIP_BZIP2 and zipfile.ZIP_LZMA.

The verbosity of the output could be customized via verbosity (with values 0, 1 or 2) argument of a backend class.

There are two options to control the content of the dump:

  • dump_schema - controls if the schema should be included
  • dump_data - controls if the data should be included

You don't have to specify all queries for related objects - XDump will load them for you automatically. It covers both, recursive and non-recursive relations. For example, if the employees table has foreign keys group_id (to groups table) and manager_id (to employees table) the resulting dump will have all objects related to selected employees (as well as for objects related to related objects, recursively).

Command Line Interface

xdump creates a dump.

$ xdump [postgres|sqlite] [OPTIONS]

Common options:

-o, --output TEXT               output file name  [required]
-f, --full TEXT                 table name to be fully dumped. Could be used
                                multiple times
-p, --partial TEXT              partial tables specification in a form
                                "table_name:select SQL". Could be used
                                multiple times
-c, --compression [deflated|stored|bzip2|lzma]
                                dump compression level
--schema / --no-schema          include / exclude the schema from the dump
--data / --no-data              include / exclude the data from the dump
-D, --dbname TEXT               database to work with  [required]
-v, --verbosity                 verbosity level

PostgreSQL-specific options:

-U, --user TEXT                 connect as specified database user
                                [required]
-W, --password TEXT             password for the DB connection
-H, --host TEXT                 database server host or socket directory
-P, --port TEXT                 database server port number

xload loads a dump into a database.

$ xload [postgres|sqlite] [OPTIONS]

Common options:

-i, --input TEXT                input file name  [required]
-m, --cleanup-method [recreate|truncate]
                                method of DB cleaning up
-D, --dbname TEXT               database to work with  [required]
-v, --verbosity                 verbosity level

PostgreSQL-specific options are the same as for xdump.

RDBMS support

At the moment only the following are supported:

  • PostgreSQL
  • SQLite >= 3.8.3

pg_dump and the sqlite3 command-line tool should be available in PATH.

Django support

Add xdump.extra.django to your INSTALLED_APPS settings:

INSTALLED_APPS = [
    ...,
    "xdump.extra.django",
]

Add XDUMP to your project settings file. It should contain minimum two entries:

  • FULL_TABLES - a list of tables that should be fully dumped.
  • PARTIAL_TABLES - a dictionary with table_name: select SQL
XDUMP = {
    "FULL_TABLES": ["groups"],
    "PARTIAL_TABLES": {"employees": "SELECT * FROM employees WHERE id > 100"},
}

Optionally you could use a custom backend:

XDUMP = {
    ...,
    "BACKEND": "importable.string",
}

Run xdump command:

$ ./manage.py xdump dump.zip

Run xload command:

$ ./manage.py xload dump.zip

Possible options to both commands:

  • -a/--alias - allows you to choose database config from DATABASES, that is used during the execution;
  • -b/--backend - importable string, that leads to custom dump backend class.

Options for xdump command:

  • -s/--dump-schema - controls if the schema should be included;
  • -d/--dump-data - controls if the data should be included.

Options for xload command:

  • -m/--cleanup-method - optionally re-creates DB or truncates the data.

NOTE. If the dump has no schema inside, DB won't be re-created.

The following make command could be useful to get a configured dump from production to your local machine:

sync-production:
	ssh -t $(TARGET) "DJANGO_SETTINGS_MODULE=settings.production /path/to/manage.py xdump /tmp/dump.zip"
	scp $(TARGET):/tmp/dump.zip ./dump.zip
	ssh -t $(TARGET) "rm /tmp/dump.zip"
	DJANGO_SETTINGS_MODULE=settings.local $(PYTHON) manage.py xload ./dump.zip

And the usage is:

$ make sync-production TARGET=john@production.com PYTHON=/path/to/python/in/venv

Python support

XDump supports Python 3.11–3.15 and PyPy.

Metadata

Release files for xdump 1.0.0

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

Source distribution (sdist)

Source distribution for xdump 1.0.0
File Size Uploaded Provenance Actions
xdump-1.0.0.tar.gz 23.0 kB With provenance Details for xdump-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 43.8 kB

Release files / xdump-1.0.0.tar.gz

Download URL xdump-1.0.0.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a13287d2cd74e19f25214fcdd65cdeeb2c175a10a67a9a1a846dbafef1ffc433
BLAKE2b-256 checksum
How to use checksums
342c07ff818088baa6a12b0c55d36ea4828a47be0aa053e3d48ed4b06cf26b17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / xdump-1.0.0-py3-none-any.whl

Download URL xdump-1.0.0-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
600720affd6725843c27740a1ede16fe1075a05b8d95541c1cca46507586d2b3
BLAKE2b-256 checksum
How to use checksums
4c60a540654d839846ec5eeed8592056da21e6bcacac66342e966833d847d52a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for xdump 1.0.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for xdump-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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.

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