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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

native_dumper-0.3.4.5-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.5-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

native_dumper-0.3.4.5-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.5-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bcaac2e3c6954fcde8e61bbf3efddfd58f2a68dd4e12ac018ac8f6601939b91e
MD5 db100d97a64760347229753284513d41
BLAKE2b-256 00d021e2a963e56ba07e33a14b343bcad127ca5ff266abb86ba4178c47663ffb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1eec35ba9abecea941998b842b0ba9a6c2699c718e348a8edb92e9195cab46ba
MD5 985989b3fda5069e96cb2624372bc9c3
BLAKE2b-256 a70656eead68da208b302714f497094eb9e95da4f779feb5e535b6fdc8b29d02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 558622c16de9164c5ef75769606c3c6cddb38174fc1f4fd3e88216b0cdc68fe1
MD5 2af208b2f78160b592c1d21ba22084de
BLAKE2b-256 2a2071dbb2cf9182c147ff950a24f0c26548328513672e5722a7a9353661ccf5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 fe99be2c688ee10ad160be967373acaadb466d8f936c615cb7d40b262a2df6af
MD5 40ec2aaca2015101b2c8eab7c972269d
BLAKE2b-256 d14851f757328c421adca826665f9f97bcac69f2b93597316d45effb514dfaf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c6d1d6bc4596fa6732bed0d2f16f971fdd367c01cc7764d2364038273c6085ff
MD5 5fcce0285a11f4606878a8a1840f848e
BLAKE2b-256 7aa3e7a10d6fa35a263ec6ae341593ec8e14574468f014b8d4aa6a30f921c585

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2315aa1eff92b16fdb1c83618eca109fc973e7045f361cb8a3d85a5f5adfeca6
MD5 9c9c90972d595f300ed0c227bd570c8b
BLAKE2b-256 291c765115bcee086c5f94317ada895edba9938a521ebde3654033a8285b1601

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d211056a21ccb6b6cd0aeb72653206c5a37721158affb8dbcb007d9689a48f1a
MD5 391dd51fa0eaecc650497decf4e2609f
BLAKE2b-256 76fab42e2605b9883c11c36fc290dda0ae8929e670580987aae0be60ce7bf95f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for native_dumper-0.3.4.5-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1578f750b965bb7893d34c657c527050351e982eb715d289c388fd2e84f0187e
MD5 ca178591058a3f70ab43f01fd6de9afb
BLAKE2b-256 958279452e9b4aaae4b77a191be359573586b2d73bcc91986e7f6c60ac6eabba

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