clickhouse-driver-decorators
Bunch of decorators to decorate clickhouse-driver's execute method
Available decorators:
add_column_names-- converts each row to dict or namedtuple with column names as keys;apply_callback-- applies a given callback to each row of result;convert_string_to_datetime-- converts string datetime to python datetime object in a needed timezone for a given column. String datetime have to be in UTC;convert_timestamp_to_datetime-- converts timestamp to python datetime object in a needed timezone for a given column.transform_to_pandas_dataframe-- creates pandas frame based on result from db
Examples
For a closer look, check out the tests
from typing import Generator
from pandas import DataFrame
from clickhouse_driver import Client
from clickhouse_driver_decorators import *
def replace_empty_with_none(row: tuple) -> Generator:
yield tuple([None if v == '' else v for v in row])
class A:
def __init__(self, client: Client):
self.__client = client
def get_data(self) -> Generator[]:
return self.__decorated_execute("""
select
toUnixTimestamp(now()) as now_ts,
formatDateTime(now(), '%F %T', 'UTC') as now_str,
'' as empty
""")
@add_column_names()
@apply_callback(on_row_callable=replace_empty_with_none)
@convert_timestamp_to_datetime(columns_to_convert={'now_ts': 'Europe/Moscow'})
@convert_string_to_datetime(date_format='%Y-%m-%d %H:%M:%S', columns_to_convert={'now_str': 'Europe/Moscow'})
def __decorated_execute(self, query: str):
return self.__client.execute(query, with_column_types=True)
class B:
def __init__(self, client: Client):
self.__client = client
def get_pandas_df(self) -> DataFrame:
return self.__decorated_execute("select 'val1' as col1, 'val2' as col2")
@transform_to_pandas_dataframe()
def __decorated_execute(self, query: str):
return self.__client.execute(query, with_column_types=True)
Metadata
Release files for clickhouse-driver-decorators 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clickhouse-driver-decorators-0.2.0.tar.gz | 4.6 kB | Without provenance | Details for clickhouse-driver-decorators-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clickhouse_driver_decorators-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for clickhouse_driver_decorators-0.2.0-py3-none-any.whl |
Total release size: 12.5 kB
Release files / clickhouse-driver-decorators-0.2.0.tar.gz
| Download URL | clickhouse-driver-decorators-0.2.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32154434cc50d2982f40258501ea02f2e372475a0472cf3cf88ce423f198991a
|
|
BLAKE2b-256 checksum How to use checksums |
571fd7b723c0d3a2c15fdb8add0c64c44eb0251e1f19e27cd50a75d9667ca1f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.3
|
Release files / clickhouse_driver_decorators-0.2.0-py3-none-any.whl
| Download URL | clickhouse_driver_decorators-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df05e25e7f2428d1ec478324e0fcaddb0d47e52fd0b0a0ec20d21b8013744dee
|
|
BLAKE2b-256 checksum How to use checksums |
1e5fd357ca76c9791d495d1e00aff112adc665c845156b3708623f2a409816bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.3
|
Security for clickhouse-driver-decorators 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.