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.4-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

native_dumper-0.3.4.4-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.4-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

native_dumper-0.3.4.4-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.4-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

native_dumper-0.3.4.4-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.4-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

native_dumper-0.3.4.4-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.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2dcd6614aca4afb4b3df43e11581ad8e172791cd5f22f029da3fa285f0113040
MD5 4bac140bd9e05c7ae88caa65b697663a
BLAKE2b-256 604b2930eac4b563b5c5fd3f554cc0d67672d8da6c6acb5bad2fc5fb9737b5fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8bc935c7a651832e9b76ecdc4bf9495f7e1334277af98bf7ab247b4c940bf5da
MD5 ff54c1f311dfa17e86d40a549eb29882
BLAKE2b-256 7788489801ee415911f716f165b4a4763f2a32997b25f856c7991905b6ad1e9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b73c2efc548e2bb6a923f018a1ae439ef63735b517ea10bf86341fe0abd4d245
MD5 cfc47f64c91694f453108ef1f52e5fca
BLAKE2b-256 848f24156a9886777c39fcaebc3a6707afcd900f685f41e290b8e7bcafa61fe4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d4befd458b2af164cc3136cf12852faee482e86ffc6ddbd85eae8395290ce5bb
MD5 6bd9b8843fd6f0d956153558969bcbd6
BLAKE2b-256 370c29f9ee1c616524cc6c3589d64b1179f92bfc21e601e991377e2c72dcec28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3965d479efd7ffc9517f50cbfa2c0452d31ea6fb319239ea5e7253462c220fe0
MD5 6e5fecac4aedcc4a9eeea43fc5864af5
BLAKE2b-256 e6cfa7e97ffe0ba8d3f129f64dc1d18c04999308b5cae8842df60c3e53970fe3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8000e7b36947b4ff854a8405bc7596126e83fdf6ca8aaba8cfdadd87a5a3db9e
MD5 b12e1f006cfe470e19db66b417c8c73a
BLAKE2b-256 f392ab5da174485ede14425829e9bd29f587c72bd1f8e5233ed07bb18aa584b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e305121c57340d5fe897af4480f04ac807d04c5d2ee448ebb2c79f36435b83c4
MD5 b6fb64ac5a76c668085fc7bbf35a99f7
BLAKE2b-256 24369baa82c0150e969d55d675272a7c7e9b599ba4a09b4f5030a7df67fb2cdf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.4-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f6c801b11ba036de8c9a8ed680382f5365375c38a36c18c9526547cbea67fd43
MD5 5d5fcb541526ade412483b66e9ee4cae
BLAKE2b-256 47cde0521f7cb1ff45ee1fec7985e611b0e00575241e4756b422cc962b3a7647

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