asynch-0.2.2
توضیحات
A asyncio driver for ClickHouse with native tcp protocol
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | asynch-0.2.2 |
| نام | asynch |
| نسخه کتابخانه | 0.2.2 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | long2ice |
| ایمیل نویسنده | long2ice@gmail.com |
| آدرس صفحه اصلی | https://github.com/long2ice/asynch |
| آدرس اینترنتی | https://pypi.org/project/asynch/ |
| مجوز | Apache-2.0 |
# asynch




## Introduction
`asynch` is an asyncio ClickHouse Python Driver with native (TCP) interface support, which reuse most of [clickhouse-driver](https://github.com/mymarilyn/clickhouse-driver) and comply with [PEP249](https://www.python.org/dev/peps/pep-0249/).
## Install
```shell
> pip install asynch
```
## Usage
Connect to ClickHouse
```python
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
```python
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`
```python
async def fetchone():
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = await cursor.fetchone()
assert ret == (1,)
```
Use `fetchmany`
```python
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
```python
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
```python
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
```python
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
```python
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](https://github.com/mymarilyn/clickhouse-driver), ClickHouse Python Driver with native interface support.
## License
This project is licensed under the [Apache-2.0](https://github.com/long2ice/asynch/blob/master/LICENSE) License.
نیازمندی
| مقدار | نام |
|---|---|
| - | ciso8601 |
| - | clickhouse-cityhash |
| - | leb128 |
| - | lz4 |
| - | pytz |
| - | tzlocal |
| - | zstd |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7,<4.0 | Python |
نحوه نصب
نصب پکیج whl asynch-0.2.2:
pip install asynch-0.2.2.whl
نصب پکیج tar.gz asynch-0.2.2:
pip install asynch-0.2.2.tar.gz