Skip to main content

PGCopy dump packed into LZ4, ZSTD or uncompressed with meta data information packed into zlib.

Project description

PGPack format

Storage format for PGCopy dump packed into LZ4, ZSTD or uncompressed with meta data information packed into zlib

PGPack structure

  • header b"PGPACK\n\x00" 8 bytes
  • unsigned long integer zlib.crc32 for packed metadata 4 bytes
  • unsigned long integer zlib packed metadata length 4 bytes
  • zlib packed metadata
  • unsigned char compression method 1 byte
  • unsigned long long integer packed pgcopy data length 8 bytes
  • unsigned long long integer unpacked pgcopy data length 8 bytes
  • packed pgcopy data

Installation

From pip

pip install pgpack

From local directory

pip install .

From git

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

Metadata format

Metadata for PGCopy dump contained Column names and OID Types

Decompressed metadata structure

list[
    list[
        column number int,
        list[
            column name str,
            column oid int,
            column lengths int,
            column scale int,
            column nested int,
        ]
    ]
]

Compression methods

  • NONE (value = 0x02) PGCopy dump without compression
  • LZ4 (value = 0x82) PGCopy dump with lz4 compression
  • ZSTD (value = 0x90) PGCopy dump with zstd compression

Get ENUM for set compression method

from pgpack import CompressionMethod

compression_method = CompressionMethod.NONE  # no compression
compression_method = CompressionMethod.LZ4  # lz4 compression (default)
compression_method = CompressionMethod.ZSTD  # zstd compression

Class PGPackReader

Initialization parameters

  • fileobj - BufferedReader object (file, BytesIO e t.c)

Methods and attributes

  • columns - List columns names
  • pgtypes - List PGOid for all columns
  • pgparam - List PGParam for all columns
  • pgcopy - PGCopy object
  • header - b"PGPack\n" 8 bytes
  • metadata_crc - integer crc32 sign for metadata_zlib object
  • metadata_length - integer length metadata_zlib in bytes
  • metadata_zlib - zlib packed metadata in bytes
  • compression_method - CompressionMethod object
  • pgcopy_compressed_length - integer packed pgcopy data length
  • pgcopy_data_length - integer unpacked pgcopy data length
  • offset_opener - OffsetOpener object
  • pgcopy_compressor - File object for reading uncompressed PGCopy data
  • to_bytes() - Method for reading uncompressed PGCopy data as bytes
  • to_python() - Method for reading uncompressed PGCopy data as list of python objects
  • to_pandas() - Method for reading uncompressed PGCopy data as pandas.DataFrame
  • to_polars() - Method for reading uncompressed PGCopy data as polars.DataFrame

Class PGPackWriter

Initialization parameters

  • fileobj - BufferedReader object (file, BytesIO e t.c)
  • compression_method - CompressionMethod object (default is CompressionMethod.LZ4)

Methods and attributes

  • columns - List columns names
  • pgtypes - List PGOid for all columns
  • pgparam - List PGParam for all columns
  • metadata_end - Integer, zlib packed metadata end position
  • fileobj_end - Integer, packed pgcopy data end position
  • pgcopy_compressed_length - integer packed pgcopy data length
  • pgcopy_data_length - integer unpacked pgcopy data length
  • write_metadata(metadata) - Make first blocks with metadata. Parameter: metadata as bytes
  • write_pgcopy(pgcopy) - Make second blocks with pgcopy. Parameter: pgcopy as BufferedReader
  • write(metadata, pgcopy) - Write PGPack file. Parameters: metadata as bytes, pgcopy as BufferedReader
  • from_python(dtype_data) - Write PGPack file from python objects. Parameter: dtype_data as python object list
  • from_pandas(data_frame) - Write PGPack file from pandas.DataFrame. Parameter: data_frame as pandas.DataFrame
  • from_polars(data_frame) - Write PGPack file from polars.DataFrame. Parameter: data_frame as polars.DataFrame

Errors

  • PGPackError - Base PGPack error
  • PGPackHeaderError - Error header signature
  • PGPackMetadataCrcError - Error metadata crc32
  • PGPackModeError - Error fileobject mode

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-0.2.0.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

pgpack-0.2.0.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file pgpack-0.2.0.1.tar.gz.

File metadata

  • Download URL: pgpack-0.2.0.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for pgpack-0.2.0.1.tar.gz
Algorithm Hash digest
SHA256 3c4dc3b8e12d49395f4c2eab3344092569dba71d952873b640a2f71e258f5871
MD5 1f2ef78103bb4adc9399b924c0c388c3
BLAKE2b-256 754bd4fb47b6d0568edd2b115a58078ced34be0c868505dcb42e95a471f2fba7

See more details on using hashes here.

File details

Details for the file pgpack-0.2.0.1-py3-none-any.whl.

File metadata

  • Download URL: pgpack-0.2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for pgpack-0.2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 868e72e8c14a617c9af9fb37907a09ccd21ecbc3f4b3255ed3fead444a7f0780
MD5 f6e6490ae5b9e73daf2fcea3b13d92b5
BLAKE2b-256 af7f0ce2ba21c7ce2e3fb1ea696d367f1a3d97c9779a611a3483a0c737ad8dc8

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