Async http clickhouse client for python 3.6+
Project description
aiochclient
Async http(s) clickhouse client for python 3.6+ with types converting and streaming support
Quick start
aiochclient needs aiohttp.ClientSession for connecting:
from aiochclient import ChClient
from aiohttp import ClientSession
async def main():
async with ClientSession() as s:
client = ChClient(s)
assert await client.is_alive() # returns True if connection is Ok
Query example:
await client.execute("CREATE TABLE t (a UInt8, b Tuple(Date, Nullable(Float32))) ENGINE = Memory")
await client.execute("INSERT INTO t VALUES (1, ('2018-09-07', NULL)),(2, ('2018-09-08', 3.14))")
Rows fetching:
For fetching all rows at once use fetch method:
all_rows = await client.fetch("SELECT * FROM t")
For fetching first row from result use fetchone method:
assert (await client.fetchone("SELECT * FROM t WHERE a=1")) == (1, (dt.date(2018, 9, 7), None))
You can also use fetchval method, which returns
first value of the first row from query result:
assert await client.fetchval("EXISTS TABLE t")
Async iteration on query results steam:
async for row in client.cursor(
"SELECT number, number*2 FROM system.numbers LIMIT 10000"
):
assert row[0] * 2 == row[1]
ChClient returns rows as tuples.
Types converting
aiochclient automatically converts values to needed type from Clickhouse response.
| Clickhouse type | Python type |
|---|---|
UInt8 |
int |
UInt16 |
int |
UInt32 |
int |
UInt64 |
int |
Int8 |
int |
Int16 |
int |
Int32 |
int |
Int64 |
int |
Float32 |
float |
Float64 |
float |
String |
str |
FixedString |
str |
Enum8 |
str |
Enum16 |
str |
Date |
dt.date |
DateTime |
da.datetime |
Tuple(T1, T2, ...) |
tuple(T1, T2, ...) |
Array(T) |
list(T) |
Nullable(T) |
None or T |
Nothing |
None |
Connection pool size
If you use aiochclient in web apps, you can limit connection pool size with
aiohttp.TCPConnector.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiochclient-0.0.1.tar.gz.
File metadata
- Download URL: aiochclient-0.0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b8738e1899562b6c904a720dd78e668a50573e1b7967b8ceb088d642911936f
|
|
| MD5 |
2e984f27c7a57d1baf19c317c23b1e50
|
|
| BLAKE2b-256 |
125daa7daca668972361ebd398f9506032005c9ac75c1e3cc0d24118247f87f5
|
File details
Details for the file aiochclient-0.0.1-py3-none-any.whl.
File metadata
- Download URL: aiochclient-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
124027cf48c0f7198435eadb3ae0566a8042e2d88131fe8a3959a8994574d1f4
|
|
| MD5 |
6c8b09da3afc61163205863a3c553711
|
|
| BLAKE2b-256 |
532ba9ad220c0d4e9778e8b6e5adbf58562007013d0ac8b0997289fa86eb28d1
|