# asynch
![pypi](https://img.shields.io/pypi/v/asynch.svg?style=flat)
![license](https://img.shields.io/github/license/long2ice/asynch)
![workflows](https://github.com/long2ice/asynch/workflows/pypi/badge.svg)
![workflows](https://github.com/long2ice/asynch/workflows/ci/badge.svg)
## 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
```
or if you want to install [`clickhouse-cityhash`](https://pypi.org/project/clickhouse-cityhash/) to enable
transport compression
```shell
> pip install asynch[compression]
```
## 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.
Raw data
{
"_id": null,
"home_page": "https://github.com/long2ice/asynch",
"name": "asynch-lxneng",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "ClickHouse,asyncio,driver",
"author": "long2ice",
"author_email": "long2ice@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d4/a1/c78c62b463017e79ec0d17ae0de6e463ff8475fce7159596d690ac27d329/asynch_lxneng-0.2.4.tar.gz",
"platform": null,
"description": "# asynch\n\n![pypi](https://img.shields.io/pypi/v/asynch.svg?style=flat)\n![license](https://img.shields.io/github/license/long2ice/asynch)\n![workflows](https://github.com/long2ice/asynch/workflows/pypi/badge.svg)\n![workflows](https://github.com/long2ice/asynch/workflows/ci/badge.svg)\n\n## Introduction\n\n`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/).\n\n## Install\n\n```shell\n> pip install asynch\n```\n\nor if you want to install [`clickhouse-cityhash`](https://pypi.org/project/clickhouse-cityhash/) to enable\ntransport compression\n\n```shell\n> pip install asynch[compression]\n```\n\n## Usage\n\nConnect to ClickHouse\n\n```python\nfrom asynch import connect\n\nasync def connect_database():\n conn = await connect(\n host = \"127.0.0.1\",\n port = 9000,\n database = \"default\",\n user = \"default\",\n password = \"\",\n )\n```\n\nCreate table by sql\n\n```python\nasync def create_table():\n async with conn.cursor(cursor=DictCursor) as cursor:\n await cursor.execute('create database if not exists test')\n await cursor.execute(\"\"\"\n CREATE TABLE if not exists test.asynch\n (\n `id` Int32,\n `decimal` Decimal(10, 2),\n `date` Date,\n `datetime` DateTime,\n `float` Float32,\n `uuid` UUID,\n `string` String,\n `ipv4` IPv4,\n `ipv6` IPv6\n\n )\n ENGINE = MergeTree\n ORDER BY id\"\"\"\n )\n```\n\nUse `fetchone`\n\n```python\nasync def fetchone():\n async with conn.cursor() as cursor:\n await cursor.execute(\"SELECT 1\")\n ret = await cursor.fetchone()\n assert ret == (1,)\n```\n\nUse `fetchmany`\n\n```python\nasync def fetchall():\n async with conn.cursor() as cursor:\n await cursor.execute(\"SELECT 1\")\n ret = await cursor.fetchall()\n assert ret == [(1,)]\n```\n\nUse `DictCursor` to get result with dict\n\n```python\nasync def dict_cursor():\n async with conn.cursor(cursor=DictCursor) as cursor:\n await cursor.execute(\"SELECT 1\")\n ret = await cursor.fetchall()\n assert ret == [{\"1\": 1}]\n```\n\nInsert data with dict\n\n```python\nfrom asynch.cursors import DictCursor\n\nasync def insert_dict():\n async with conn.cursor(cursor=DictCursor) as cursor:\n ret = await cursor.execute(\n \"\"\"INSERT INTO test.asynch(id,decimal,date,datetime,float,uuid,string,ipv4,ipv6) VALUES\"\"\",\n [\n {\n \"id\": 1,\n \"decimal\": 1,\n \"date\": \"2020-08-08\",\n \"datetime\": \"2020-08-08 00:00:00\",\n \"float\": 1,\n \"uuid\": \"59e182c4-545d-4f30-8b32-cefea2d0d5ba\",\n \"string\": \"1\",\n \"ipv4\": \"0.0.0.0\",\n \"ipv6\": \"::\",\n }\n ],\n )\n assert ret == 1\n```\n\nInsert data with tuple\n\n```python\nasync def insert_tuple():\n async with conn.cursor(cursor=DictCursor) as cursor:\n ret = await cursor.execute(\n \"\"\"INSERT INTO test.asynch(id,decimal,date,datetime,float,uuid,string,ipv4,ipv6) VALUES\"\"\",\n [\n (\n 1,\n 1,\n \"2020-08-08\",\n \"2020-08-08 00:00:00\",\n 1,\n \"59e182c4-545d-4f30-8b32-cefea2d0d5ba\",\n \"1\",\n \"0.0.0.0\",\n \"::\",\n )\n ],\n )\n assert ret == 1\n```\n\nUse connection pool\n\n```python\nasync def use_pool():\n pool = await asynch.create_pool()\n async with pool.acquire() as conn:\n async with conn.cursor() as cursor:\n await cursor.execute(\"SELECT 1\")\n ret = await cursor.fetchone()\n assert ret == (1,)\n pool.close()\n await pool.wait_closed()\n```\n\n## ThanksTo\n\n- [clickhouse-driver](https://github.com/mymarilyn/clickhouse-driver), ClickHouse Python Driver with native interface support.\n\n## License\n\nThis project is licensed under the [Apache-2.0](https://github.com/long2ice/asynch/blob/master/LICENSE) License.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A asyncio driver for ClickHouse with native tcp protocol",
"version": "0.2.4",
"project_urls": {
"Documentation": "https://github.com/long2ice/asynch",
"Homepage": "https://github.com/long2ice/asynch",
"Repository": "https://github.com/long2ice/asynch.git"
},
"split_keywords": [
"clickhouse",
"asyncio",
"driver"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d0662da97a5618d2a7537e67de2c4d54e638cb896802bd4aa88190b887b5c2b9",
"md5": "1949e53674361a1f4b4230aca076e74c",
"sha256": "d95add1ff7fb3067b1ef6db68b24d78eb0e953e6cc27637ab0cdee44e3e16960"
},
"downloads": -1,
"filename": "asynch_lxneng-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1949e53674361a1f4b4230aca076e74c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 73277,
"upload_time": "2023-10-20T07:22:13",
"upload_time_iso_8601": "2023-10-20T07:22:13.714808Z",
"url": "https://files.pythonhosted.org/packages/d0/66/2da97a5618d2a7537e67de2c4d54e638cb896802bd4aa88190b887b5c2b9/asynch_lxneng-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d4a1c78c62b463017e79ec0d17ae0de6e463ff8475fce7159596d690ac27d329",
"md5": "43867e29b23549008f73d7cd27d27ca2",
"sha256": "fc259e6dee29e5f32e79e9e39db89f01eea5c31a229752495d31b763ecf63445"
},
"downloads": -1,
"filename": "asynch_lxneng-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "43867e29b23549008f73d7cd27d27ca2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 53351,
"upload_time": "2023-10-20T07:22:16",
"upload_time_iso_8601": "2023-10-20T07:22:16.124347Z",
"url": "https://files.pythonhosted.org/packages/d4/a1/c78c62b463017e79ec0d17ae0de6e463ff8475fce7159596d690ac27d329/asynch_lxneng-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-20 07:22:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "long2ice",
"github_project": "asynch",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "asynch-lxneng"
}