A asyncio driver for ClickHouse with native tcp protocol
Project description
asynch
Introduction
asynch
is a asyncio ClickHouse Python Driver with native (TCP) interface support, which reuse most of clickhouse-driver
and comply with PEP249.
Install
> pip install asynch
Usage
connect
from asynch import connect
conn = connect(
host: str = "127.0.0.1",
port: int = 9000,
database: str = "default",
user: str = "default",
password: str = "",
)
create table
async def create_table():
async with conn.cursor(cursor=DictCursor) as cursor:
await cursor.execute('create database if not exists test')
await cursor.execute("""
CREATE TABLE if not exists test.asynch
(
`id` Int32,
`decimal` Decimal(10, 2),
`date` Date,
`datetime` DateTime,
`float` Float32,
`uuid` UUID,
`string` String,
`ipv4` IPv4,
`ipv6` IPv6
)
ENGINE = MergeTree
ORDER BY id"""
)
fetchone
async def fetchone():
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = cursor.fetchone()
assert ret == (1,)
fetchmany
async def fetchall():
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = cursor.fetchall()
assert ret == [(1,)]
DictCursor
async def dict_cursor():
async with conn.cursor(cursor=DictCursor) as cursor:
await cursor.execute("SELECT 1")
ret = cursor.fetchall()
assert ret == [{"1": 1}]
insert
from asynch.cursors import DictCursor
async def insert_dict():
async with conn.cursor(cursor=DictCursor) as cursor:
ret = await cursor.execute(
"""INSERT INTO test.asynch(id,decimal,date,datetime,float,uuid,string,ipv4,ipv6) VALUES""",
[
{
"id": 1,
"decimal": 1,
"date": "2020-08-08",
"datetime": "2020-08-08 00:00:00",
"float": 1,
"uuid": "59e182c4-545d-4f30-8b32-cefea2d0d5ba",
"string": "1",
"ipv4": "0.0.0.0",
"ipv6": "::",
}
],
)
assert ret == 1
insert with dict
async def insert_tuple():
async with conn.cursor(cursor=DictCursor) as cursor:
ret = await cursor.execute(
"""INSERT INTO test.asynch(id,decimal,date,datetime,float,uuid,string,ipv4,ipv6) VALUES""",
[
(
1,
1,
"2020-08-08",
"2020-08-08 00:00:00",
1,
"59e182c4-545d-4f30-8b32-cefea2d0d5ba",
"1",
"0.0.0.0",
"::",
)
],
)
assert ret == 1
ThanksTo
- clickhouse-driver, ClickHouse Python Driver with native interface support.
License
This project is licensed under the Apache-2.0 License.
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
asynch-0.1.0.tar.gz
(44.7 kB
view details)
Built Distribution
asynch-0.1.0-py3-none-any.whl
(63.3 kB
view details)
File details
Details for the file asynch-0.1.0.tar.gz
.
File metadata
- Download URL: asynch-0.1.0.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ee52a7cc98fe6573733351c57a1db9e4854f2073515c1be25b038b0ecaa620f |
|
MD5 | 4d072739860e086d70ad4771b3699f7b |
|
BLAKE2b-256 | 75fa3481ea2869b6ada6d729205375c3dadf29f255369e67d704006adf4141fb |
File details
Details for the file asynch-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: asynch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 63.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b55205677b1951a62c32e6b58e6ad98ecfa69eadb920ee5356d2c2dbf6ef269 |
|
MD5 | 0045133d5af2757da8e2013a2e4af0f9 |
|
BLAKE2b-256 | 9c7cabae6e63d1ab59737acdfb6e7a2b17859a005ca323ff3dd258f4b925b9b3 |