Skip to main content

Library for read and write Native format between Clickhouse and file.

Project description

NativeDumper

Library for read and write Native format between Clickhouse and file

Examples

Initialization

from native_dumper import (
    CompressionMethod,
    CHConnector,
    NativeDumper,
)

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

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

Read dump from Clickhouse into file

file_name = "native.zstd"
# you need define one of parameter query or table_name
query = "select ..."  # some sql query
table_name = "default.test_table"  # or some table

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

Write dump from file into Clickhouse

file_name = "native.zstd"
# you need define one of parameter table_name
table_name = "default.test_table"  # some table

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

Write from Clickhouse into Clickhouse

Same server

table_dest = "default.test_table_write"  # some table for write
table_src = "default.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 = CHConnector(
    host = <host src>,
    dbname = <database src>,
    user = <username src>,
    password = <password src>,
    port = 8123,
)

dumper_src = NativeDumper(connector=connector_src)

table_dest = "default.test_table_write"  # some table for write
table_src = "default.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,
)

Get NativeReader object from stream

table_name = "default.test_table_read"  # some table for read
query = "select ..."  # or some sql query for read

reader = dumper.to_reader(
    query=query,
    table_name=table_name,
)

NativeReader 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 = "default.test_table_write"
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 Native file format

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

Installation

From pip

pip install native-dumper

From local directory

pip install .

From git

pip install git+https://github.com/0xMihalich/native_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.

native_dumper-0.3.4.3-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

native_dumper-0.3.4.3-cp311-cp311-manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

native_dumper-0.3.4.3-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

native_dumper-0.3.4.3-cp311-cp311-macosx_10_14_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 10.14+ x86-64

native_dumper-0.3.4.3-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

native_dumper-0.3.4.3-cp310-cp310-manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

native_dumper-0.3.4.3-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

native_dumper-0.3.4.3-cp310-cp310-macosx_10_14_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 10.14+ x86-64

File details

Details for the file native_dumper-0.3.4.3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 13098cff5800ed19e4aa820ac74d1415496abf8b87ee23606337f5eb798e2a5c
MD5 b5ffcdab3a32d79d6f66e95a940c32b1
BLAKE2b-256 7fe710eb27d916e7540ac57feeb05380546fb4aeb129491570b729198b4ac677

See more details on using hashes here.

File details

Details for the file native_dumper-0.3.4.3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c86fa0679badfc76acd09a79cab7e312a14d5aa230d68fd994f4288df9994150
MD5 5a253cd23b71427c114522d496baa4c3
BLAKE2b-256 f919cb4f3c1937c9e5723d04b49d1dd560caf6cafaa971d988a26c336705614b

See more details on using hashes here.

File details

Details for the file native_dumper-0.3.4.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 624901eca787382d761f647e3252a1a17daa79ac63def837d396a52a7235072b
MD5 65c497ee14284a38b20d299b307ec369
BLAKE2b-256 29e9a88ec18362063ac2f166da594319499b6edd104bf3b5aa1a4654a5f8ad05

See more details on using hashes here.

File details

Details for the file native_dumper-0.3.4.3-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a5d70054a073eb75cf22889c29aee1625b5d609956c168a53fd6457d20f4234f
MD5 704e602857f28b74e74a2add4b25b312
BLAKE2b-256 89268ddfe9f679b732ebb27c2a8260c0145be8e43265c2b1edc869dbea9d8b3a

See more details on using hashes here.

File details

Details for the file native_dumper-0.3.4.3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7973aefa2039956a805e5a1023853f795a269ddaa888d4939235a5fc883174d7
MD5 6ad295235984c578613c0d42e581442e
BLAKE2b-256 49e02d862ef17b02386e26ff52057b0362941628c723cdf23aaf7341ab60d00c

See more details on using hashes here.

File details

Details for the file native_dumper-0.3.4.3-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 62e2c569c2f796606a25fb4b20b6fd56066d366d2bc168e50e21658e96645edf
MD5 512ca74430d1e7d82eb1c2b080492aca
BLAKE2b-256 c859caf4fad07f1c1f71ff60fdf3d75fab46b3b10832935587adb963b0c40229

See more details on using hashes here.

File details

Details for the file native_dumper-0.3.4.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 99bbbda6ec3caac35c98260ccc318bf98965cbd14e79ed868bf79f5c76b372cb
MD5 94a498bf1b6f0e702e28ee80f3cc929e
BLAKE2b-256 878da4e62458ef51e42941ae619130fa02fb2c7d529e63b67054180478d09113

See more details on using hashes here.

File details

Details for the file native_dumper-0.3.4.3-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.3-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f5063f8222a6f885d6d4d283189754031d5f2d73459d365fc3cec29eb93d4f3c
MD5 fc465e0341eb1ff6c12b97e99c40daa4
BLAKE2b-256 72e8a3904a985a12de16258561598e7945a104a706648d8d26a5073931a2c21c

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