Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mymarilyn/aioch
aioch - is a library for accessing a ClickHouse database over native interface from the asyncio
https://github.com/mymarilyn/aioch
asyncio clickhouse database driver native yandex
Last synced: 5 days ago
JSON representation
aioch - is a library for accessing a ClickHouse database over native interface from the asyncio
- Host: GitHub
- URL: https://github.com/mymarilyn/aioch
- Owner: mymarilyn
- License: other
- Created: 2017-09-18T19:56:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-23T15:30:31.000Z (almost 3 years ago)
- Last Synced: 2025-01-07T03:43:52.862Z (12 days ago)
- Topics: asyncio, clickhouse, database, driver, native, yandex
- Language: Python
- Size: 14.6 KB
- Stars: 163
- Watchers: 4
- Forks: 20
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-clickhouse - mymarilyn/aioch - aioch is a library for accessing a ClickHouse database over native interface from the asyncio. (Language bindings / Python)
README
# aioch
**aioch** is a library for accessing a ClickHouse database over native interface from the asyncio.
It wraps features of [clickhouse-driver](https://github.com/mymarilyn/clickhouse-driver) for asynchronous usage.[![Coverage Status](https://coveralls.io/repos/github/mymarilyn/aioch/badge.svg?branch=master)](https://coveralls.io/github/mymarilyn/aioch?branch=master)
[![Build Status](https://travis-ci.org/mymarilyn/aioch.svg?branch=master)](https://travis-ci.org/mymarilyn/aioch)## Installation
The package can be installed using `pip`:
```bash
pip install aioch
```To install from source:
```bash
git clone https://github.com/mymarilyn/aioch
cd aioch
python setup.py install
```## Usage
```python
from datetime import datetimeimport asyncio
from aioch import Clientasync def exec_progress():
client = Client('localhost')progress = await client.execute_with_progress('LONG AND COMPLICATED QUERY')
timeout = 20
started_at = datetime.now()async for num_rows, total_rows in progress:
done = num_rows / total_rows if total_rows else total_rows
now = datetime.now()
# Cancel query if it takes more than 20 seconds to process 50% of rows.
if (now - started_at).total_seconds() > timeout and done < 0.5:
await client.cancel()
break
else:
rv = await progress.get_result()
print(rv)async def exec_no_progress():
client = Client('localhost')
rv = await client.execute('LONG AND COMPLICATED QUERY')
print(rv)loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait([exec_progress(), exec_no_progress()]))
```For more information see **clickhouse-driver** usage examples.
## Parameters
* `executor` - instance of custom Executor, if not supplied default executor will be used
* `loop` - asyncio compatible event loopOther parameters are passing to wrapped clickhouse-driver's Client.
## License
aioch is distributed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).