asynch-lxneng


Nameasynch-lxneng JSON
Version 0.2.5 PyPI version JSON
download
home_pagehttps://github.com/long2ice/asynch
SummaryA asyncio driver for ClickHouse with native tcp protocol
upload_time2024-05-27 02:16:53
maintainerNone
docs_urlNone
authorlong2ice
requires_python<4.0,>=3.7
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-lxneng",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": null,
    "keywords": "ClickHouse, asyncio, driver",
    "author": "long2ice",
    "author_email": "long2ice@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b8/28/91c00323b58091fdec8729ae8c7a284a8a896ce16e851160b302ad08a5d9/asynch_lxneng-0.2.5.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.5",
    "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": "994863b37473567234e1e116539854387de7f766368f09f6c7ba7be029e33a92",
                "md5": "ca8b05977b842e55303e23c71e32b254",
                "sha256": "e5f02d9f8ddee123c97de5d36a7c1fccd1b0023fb64871ca162288c66bb9a04d"
            },
            "downloads": -1,
            "filename": "asynch_lxneng-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ca8b05977b842e55303e23c71e32b254",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 73719,
            "upload_time": "2024-05-27T02:16:51",
            "upload_time_iso_8601": "2024-05-27T02:16:51.099418Z",
            "url": "https://files.pythonhosted.org/packages/99/48/63b37473567234e1e116539854387de7f766368f09f6c7ba7be029e33a92/asynch_lxneng-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b82891c00323b58091fdec8729ae8c7a284a8a896ce16e851160b302ad08a5d9",
                "md5": "0217b10633429140bf86fad62d71900f",
                "sha256": "27729f39a83c51cf94c9e81e0a95b8e2c17e9eb7acbfad16b8ed317f48c255a1"
            },
            "downloads": -1,
            "filename": "asynch_lxneng-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "0217b10633429140bf86fad62d71900f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 52991,
            "upload_time": "2024-05-27T02:16:53",
            "upload_time_iso_8601": "2024-05-27T02:16:53.800474Z",
            "url": "https://files.pythonhosted.org/packages/b8/28/91c00323b58091fdec8729ae8c7a284a8a896ce16e851160b302ad08a5d9/asynch_lxneng-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-27 02:16:53",
    "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"
}
        
Elapsed time: 1.00949s