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,
)
Write from python lists
dtype_data = Iterable[Any] | list[list[Any]] # some python data
table_name = "default.test_table_write" # some table for write
dumper.from_rows(
dtype_data=dtype_data,
table_name=table_name,
)
Write from pandas.DataFrame
data_frame = pandas.DataFrame({<some data>})
table_name = "default.test_table_write" # some table for write
dumper.from_pandas(
data_frame=data_frame,
table_name=table_name,
)
Write from polars.DataFrame
data_frame = polars.DataFrame({<some data>})
table_name = "default.test_table_write" # some table for write
dumper.from_polars(
data_frame=data_frame,
table_name=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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
native_dumper-0.0.2.0.tar.gz
(8.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file native_dumper-0.0.2.0.tar.gz.
File metadata
- Download URL: native_dumper-0.0.2.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cb045766e887a603cc2c5c14482ee6935c665822ef06762ff810ceeb1b0c45a
|
|
| MD5 |
68bbd2aabba59f25dde37da557fdff67
|
|
| BLAKE2b-256 |
b3a3eb7baff344d3425443f8e9122ab042c8dcce154a858d7ef48d1078f9cdd5
|
File details
Details for the file native_dumper-0.0.2.0-py3-none-any.whl.
File metadata
- Download URL: native_dumper-0.0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4f808df92a52df7e22d06593cddb289123c078d2e37ed22251422dd65740699
|
|
| MD5 |
ccbae5f67d80bc78bc63f0e7378c2f65
|
|
| BLAKE2b-256 |
f3a3fd9a897e2d918ad4763ac47e2e1ad649c76af965ce630b64e7ceaa495ba3
|