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.ZSTD,  # or CompressionMethod.LZ4 or CompressionMethod.NONE
)

Read dump from PostgreSQL into file

file_name = "test_table.pgpack"
# 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 = "test_table.pgpack"
# 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,
)

Get stream object

# you need define one of parameter query or table_name
query = "select ..."  # some sql query
table_name = "public.test_table"  # or some table
reader = dumper.to_reader(query=query, table_name=table_name)
print(reader)
# <PostgreSQL/GreenPlum stream reader>
# ┌─────────────────┬─────────────────┐
# │ Column Name     │ PostgreSQL Type │
# ╞═════════════════╪═════════════════╡
# │ column1         │ date            │
# │-----------------+-----------------│
# │ column2         │ bpchar          │
# │-----------------+-----------------│
# │ column3         │ bpchar          │
# └─────────────────┴─────────────────┘
# Total columns: 3
# Readed rows: 0

StreamReader has three methods available, but only one of the methods is available at a time within a single session.

# read as python generator object
reader.to_rows()
# or read as pandas.DataFrame
reader.to_pandas()
# or read as polars.DataFrame
reader.to_polars()

Write from python objects into target table

# some table for write data
table_name = "public.test_table"
dtype_data: Itarable[Any]
pandas_frame: pandas.DataFrame
polars_frame: polars.DataFrame

# write from python object
dumper.from_rows(dtype_data, table_name)
# write from pandas.DataFrame
dumper.from_pandas(pandas_frame, table_name)
# write from polars.DataFrame
dumper.from_polars(polars_frame, table_name)

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pgpack_dumper-0.3.4.2-cp311-cp311-win_amd64.whl (42.2 kB view details)

Uploaded CPython 3.11Windows x86-64

pgpack_dumper-0.3.4.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (154.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

pgpack_dumper-0.3.4.2-cp311-cp311-macosx_11_0_arm64.whl (46.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pgpack_dumper-0.3.4.2-cp311-cp311-macosx_10_14_x86_64.whl (46.0 kB view details)

Uploaded CPython 3.11macOS 10.14+ x86-64

pgpack_dumper-0.3.4.2-cp310-cp310-win_amd64.whl (43.1 kB view details)

Uploaded CPython 3.10Windows x86-64

pgpack_dumper-0.3.4.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (156.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

pgpack_dumper-0.3.4.2-cp310-cp310-macosx_11_0_arm64.whl (46.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pgpack_dumper-0.3.4.2-cp310-cp310-macosx_10_14_x86_64.whl (46.3 kB view details)

Uploaded CPython 3.10macOS 10.14+ x86-64

File details

Details for the file pgpack_dumper-0.3.4.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 35f56ae79a962b3ad939a60ac781e1d85cb143754d4fe04e27b704e87e330309
MD5 4c82d37399d8b6314d36dbd3271dd031
BLAKE2b-256 77953986556188dc52968df3c1b034bae1a1d1bd4cca9064ac259706f7761795

See more details on using hashes here.

File details

Details for the file pgpack_dumper-0.3.4.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7997cc087f8e38a62524426e1b4d1d3442e09c2660a721653da6234fddb139d6
MD5 e2a54040824411a4b390cd1b0c0f8f76
BLAKE2b-256 c5b41355eae8d72d5d6bd4116d47eceb86fa3beab809a58b25fc061f3f0e094c

See more details on using hashes here.

File details

Details for the file pgpack_dumper-0.3.4.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 783db2122b4c6b0f5b88c89383fbbe3fc18835256f3ba2d937d890a748bbdbb7
MD5 803d990b958cf4b4a3b5fd2ea063e020
BLAKE2b-256 54b9c4528cc003d7e5b0ab46248d8b0e5454ebbc0b34a83ad25ffdce7103ed1f

See more details on using hashes here.

File details

Details for the file pgpack_dumper-0.3.4.2-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 7819537ce789080cb0fcaeea8e6e6053c1eb91399489d56f55454ddd0865f79a
MD5 a954fd2abd7eb76c502e41e60777a1b0
BLAKE2b-256 b384294ad7ecd19cd53c765c1f7ebcc5106a71138ea9d1405eec8f1bb471ebda

See more details on using hashes here.

File details

Details for the file pgpack_dumper-0.3.4.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e8b5bc2b4c11d3aad4da69b96c40fe475b66629f2a8cb31fd153fdb181c5abfa
MD5 e306e61bab84d5d4e0dffd378ebfea36
BLAKE2b-256 785bd24e6cab13a22bcdffe6ebd14ef70847355b4c52c101588eedef49a9fb6d

See more details on using hashes here.

File details

Details for the file pgpack_dumper-0.3.4.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b765bd2b39b473d786143120cc99f8a58fc5313ffd7c98c6b9be15eec1639d06
MD5 240005d488b3a55c15c5c17379ba89b4
BLAKE2b-256 4c66884b1376550cc9ca44a591b068aa557e5dc8650af83c32c1c32ccb3fe996

See more details on using hashes here.

File details

Details for the file pgpack_dumper-0.3.4.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 01acf0d96745eb944fe2524a1856153d106787a983be99d31b45312e5fe35ba1
MD5 e3a7be4ec4ede625c867e1e9912d67cf
BLAKE2b-256 a2a4df9c0a1a41d1571c37bab41c54ee42f781f25bb8bc7a9d62ee6b335de21c

See more details on using hashes here.

File details

Details for the file pgpack_dumper-0.3.4.2-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for pgpack_dumper-0.3.4.2-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 627aecd96bf5ceca1cc6c3dd6406f1fa6c771cbffb129169e9d1ef19eda75345
MD5 27c1a274f95b52ded5e12a12cfc8a806
BLAKE2b-256 c31e77d093336ab56d245d9700c8949e09beb1057c6006ef69a233e55a92be83

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