asynch


Nameasynch JSON
Version 0.2.3 PyPI version JSON
download
home_pagehttps://github.com/long2ice/asynch
SummaryA asyncio driver for ClickHouse with native tcp protocol
upload_time2023-12-08 02:27:27
maintainer
docs_urlNone
authorlong2ice
requires_python>=3.7,<4.0
licenseApache-2.0
keywords clickhouse asyncio driver
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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",
    "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/62/dd/2482fb189836b63bad11b475756e9a3f75f0b9a89172351a12f994d00456/asynch-0.2.3.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\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A asyncio driver for ClickHouse with native tcp protocol",
    "version": "0.2.3",
    "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": "359f08d0f6d1933fac571fe40f041d6b27f249861682681e8af8f3611f3807ca",
                "md5": "272d4be9ce4afe1ea8019d60ccc7c1ff",
                "sha256": "c7869e60059fb92885d75e168c8bad2e1dfa8f20bd3ae8358191759b84236604"
            },
            "downloads": -1,
            "filename": "asynch-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "272d4be9ce4afe1ea8019d60ccc7c1ff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 73175,
            "upload_time": "2023-12-08T02:27:25",
            "upload_time_iso_8601": "2023-12-08T02:27:25.950919Z",
            "url": "https://files.pythonhosted.org/packages/35/9f/08d0f6d1933fac571fe40f041d6b27f249861682681e8af8f3611f3807ca/asynch-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "62dd2482fb189836b63bad11b475756e9a3f75f0b9a89172351a12f994d00456",
                "md5": "c10623b28dd423ca23ab791c9719a113",
                "sha256": "c8cdd88663f46cff8d3c7e1b7d8806a50fd2c385ed43f41ea5a0078ef46329e3"
            },
            "downloads": -1,
            "filename": "asynch-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "c10623b28dd423ca23ab791c9719a113",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 52082,
            "upload_time": "2023-12-08T02:27:27",
            "upload_time_iso_8601": "2023-12-08T02:27:27.947470Z",
            "url": "https://files.pythonhosted.org/packages/62/dd/2482fb189836b63bad11b475756e9a3f75f0b9a89172351a12f994d00456/asynch-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-08 02:27:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "long2ice",
    "github_project": "asynch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "asynch"
}
        
Elapsed time: 0.20373s