Skip to main content

Library for read and write PGPack format between PostgreSQL and file.

Project description

PGPackDumper

Library for read and write PGPack format between PostgreSQL and file

Examples

Initialization

from pgpack_dumper import (
    CompressionMethod,
    PGConnector,
    PGPackDumper,
)

connector = PGConnector(
    host = <your host>,
    dbname = <your database>,
    user = <your username>,
    password = <your password>,
    port = <your port>,
)

dumper = PGPackDumper(
    connector=connector,
    compression_method=CompressionMethod.LZ4,  # or CompressionMethod.ZSTD or CompressionMethod.NONE
)

Read dump from PostgreSQL into file

file_name = "pgpack.lz4"
# you need define one of parameter query or table_name
query = "select ..."  # some sql query
table_name = "public.test_table"  # or some table

with open(file_name, "wb") as fileobj:
    dumper.read_dump(
        fileobj,
        query,
        table_name,
    )

Write dump from file into PostgreSQL

file_name = "pgpack.lz4"
# you need define one of parameter table_name
table_name = "public.test_table"  # some table

with open(file_name, "rb") as fileobj:
    dumper.write_dump(
        fileobj,
        table_name,
    )

Write from PostgreSQL into PostgreSQL

Same server

table_dest = "public.test_table_write"  # some table for write
table_src = "public.test_table_read"  # some table for read
query_src = "select ..."  # or some sql query for read

dumper.write_between(
    table_dest,
    table_src,
    query_src,
)

Different servers

connector_src = PGConnector(
    host = <host src>,
    dbname = <database src>,
    user = <username src>,
    password = <password src>,
    port = <port src>,
)

dumper_src = PGPackDumper(connector=connector_src)

table_dest = "public.test_table_write"  # some table for write
table_src = "public.test_table_read"  # some table for read
query_src = "select ..."  # or some sql query for read

dumper.write_between(
    table_dest,
    table_src,
    query_src,
    dumper_src.cursor,
)

Open PGPack file format

Get info from my another repository https://github.com/0xMihalich/pgpack

Installation

From pip

pip install pgpack_dumper

From local directory

pip install .

From git

pip install git+https://github.com/0xMihalich/pgpack_dumper

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgpack_dumper-0.1.2.1.tar.gz (9.2 kB view details)

Uploaded Source

File details

Details for the file pgpack_dumper-0.1.2.1.tar.gz.

File metadata

  • Download URL: pgpack_dumper-0.1.2.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for pgpack_dumper-0.1.2.1.tar.gz
Algorithm Hash digest
SHA256 662c24a4bd624a99d5d48959791a2f4d83d30b4523137d431078b6e68b23c564
MD5 bbaafad957ff5ba1e35614b19ee75829
BLAKE2b-256 e3dae66ee08c46202a94aac1c027913c1ba51a5668e7b456c61f95b29c6d73a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page