asynch
Introduction
asynch is an asyncio ClickHouse Python Driver with native (TCP) interface support, which reuse most of clickhouse-driver and comply with PEP249.
Install
> pip install asynch
or if you want to install clickhouse-cityhash to enable
transport compression
> pip install asynch[compression]
Usage
Connect to ClickHouse
from asynch import connect
async def connect_database():
conn = await connect(
host = "127.0.0.1",
port = 9000,
database = "default",
user = "default",
password = "",
)
Create table by sql
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"""
)
Use fetchone
async def fetchone():
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = await cursor.fetchone()
assert ret == (1,)
Use fetchmany
async def fetchall():
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = await cursor.fetchall()
assert ret == [(1,)]
Use DictCursor to get result with dict
async def dict_cursor():
async with conn.cursor(cursor=DictCursor) as cursor:
await cursor.execute("SELECT 1")
ret = await cursor.fetchall()
assert ret == [{"1": 1}]
Insert data with dict
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 data with tuple
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
Use connection pool
async def use_pool():
pool = await asynch.create_pool()
async with pool.acquire() as conn:
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = await cursor.fetchone()
assert ret == (1,)
pool.close()
await pool.wait_closed()
ThanksTo
- clickhouse-driver, ClickHouse Python Driver with native interface support.
License
This project is licensed under the Apache-2.0 License.
Metadata
Release files for asynch-lxneng 0.2.5
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 |
|---|---|---|---|---|
| asynch_lxneng-0.2.5.tar.gz | 53.0 kB | Without provenance | Details for asynch_lxneng-0.2.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asynch_lxneng-0.2.5-py3-none-any.whl | Python 3 | none | any | Details for asynch_lxneng-0.2.5-py3-none-any.whl |
Total release size: 126.7 kB
Release files / asynch_lxneng-0.2.5.tar.gz
| Download URL | asynch_lxneng-0.2.5.tar.gz |
|---|---|
| Size | 53.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27729f39a83c51cf94c9e81e0a95b8e2c17e9eb7acbfad16b8ed317f48c255a1
|
|
BLAKE2b-256 checksum How to use checksums |
b82891c00323b58091fdec8729ae8c7a284a8a896ce16e851160b302ad08a5d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.13 Darwin/23.4.0
|
Release files / asynch_lxneng-0.2.5-py3-none-any.whl
| Download URL | asynch_lxneng-0.2.5-py3-none-any.whl |
|---|---|
| Size | 73.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5f02d9f8ddee123c97de5d36a7c1fccd1b0023fb64871ca162288c66bb9a04d
|
|
BLAKE2b-256 checksum How to use checksums |
994863b37473567234e1e116539854387de7f766368f09f6c7ba7be029e33a92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.13 Darwin/23.4.0
|
Security for asynch-lxneng 0.2.5
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.