pypgsync
Python utility to sync two postgresql databases
Installation
pip install pypgsync
Usage
Given two databases, pypgsync can determine which records differ. In the primarykey use case,
records are identified by their primary key.
import psycopg
from pypgsync.mode.primarykey import delta_by_primary_key, apply_delta_by_primary_key
con_source = psycopg.connect(host="host_source", dbname="db_source", user="user_source",
password="secret_source")
con_destination = psycopg.connect(host="host_destination", dbname="db_destination",
user="user_destination", password="secret_destination")
cur_source = con_source.cursor()
cur_destination = con_destination.cursor()
delta = delta_by_primary_key(cur_source=cur_source, cur_destination=cur_destination,
table_name="products", primary_key="id",
columns=["name", "count", "price"], pk_values=[1, 2, 3, 4, 5],)
delta provides an overview of the differences between the two database tables, in terms of which
database operations (delete, insert, update) have to be applied to the destination database
in order to match the source database. The primary key identifies the rows that have to be modified.
{
"table_name": "products",
"primary_key": "id",
"intersection": set([1, 2]),
"delete": set([3, ]),
"insert": [{"id": 5, "name": "bread", "count": 5, "price": 3.2}],
"update": [{"id": 2, "count": 20}, ]
}
delta can then be used to apply the necessary changes to the destination database.
from pypgsync.mode.primarykey import apply_delta_by_primary_key
apply_delta_by_primary_key(con_destination, delta)
After which the two database tables are identical within the column and primary key range specified.
To accomplish the sync in one step, use the sync_by_primary_key function.
from pypgsync.mode.primarykey import sync_by_primary_key
sync_by_primary_key(cur_source, con_destination, table_name="products", primary_key="id")
Metadata
Release files for pypgsync 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypgsync-1.2.0.tar.gz | 7.9 kB | Without provenance | Details for pypgsync-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypgsync-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for pypgsync-1.2.0-py3-none-any.whl |
Total release size: 17.2 kB
Release files / pypgsync-1.2.0.tar.gz
| Download URL | pypgsync-1.2.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a040c6960c80595cb98f340ca4bc1eaaa79da24690a6f57eee4ebd7574e22ecc
|
|
BLAKE2b-256 checksum How to use checksums |
79b02bc28ffa428928627a937cc9c801f14b9d2724ad8b5674d80b4ea1c6207e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.8.14 Darwin/19.6.0
|
Release files / pypgsync-1.2.0-py3-none-any.whl
| Download URL | pypgsync-1.2.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b87432723601f40a2da7050732a9bed44c441f10ccdd4028602abe944e506576
|
|
BLAKE2b-256 checksum How to use checksums |
d9ae8764e83945ea04a15627e7c4602c4cc3404899d77a2e3c54c714920b5285
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.8.14 Darwin/19.6.0
|
Security for pypgsync 1.2.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.
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.