CrateDB Async driver based on httpx.
Asynchronous driver for CrateDB, it uses the HTTP protocol and follows its own design.
Usage
It can be used with any async library:
Asyncio
import asyncio
from cratedb_async.client import CrateClient
async def main():
crate = CrateClient('http://192.168.88.251:4200')
response = await crate.query('SELECT * FROM sys.summits')
print(response.as_table())
asyncio.run(main())
# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+
# | classification | coordinates | country | first_ascent | height | mountain | prominence | range | region |
# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+
# | I/B-07.V-B | [6.86444, 45.8325] | FR/IT | 1786 | 4808 | Mont Blanc | 4695 | U-Savoy/Aosta | Mont Blanc massif |
# | I/B-09.III-A | [7.86694, 45.93694] | CH | 1855 | 4634 | Monte Rosa | 2165 | Valais | Monte Rosa Alps |
# | I/B-09.V-A | [7.85889, 46.09389] | CH | 1858 | 4545 | Dom | 1046 | Valais | Mischabel |
# | I/B-09.III-A | [7.83556, 45.92222] | CH/IT | 1861 | 4527 | Liskamm | 376 | Valais/Aosta | Monte Rosa Alps |
# | I/B-09.II-D | [7.71583, 46.10139] | CH | 1861 | 4506 | Weisshorn | 1235 | Valais | Weisshorn-Matterhorn |
# | I/B-09.II-A | [7.65861, 45.97639] | CH/IT | 1865 | 4478 | Matterhorn | 1042 | Valais/Aosta | Weisshorn-Matterhorn |
# | I/B-09.II-C | [7.61194, 46.03417] | CH | 1862 | 4357 | Dent Blanche | 915 | Valais | Weisshorn-Matterhorn |
# | I/B-09.I-B | [7.29917, 45.9375] | CH | 1859 | 4314 | Grand Combin | 1517 | Valais | Grand Combin Alps |
# | I/B-12.II-A | [8.12611, 46.53722] | CH | 1829 | 4274 | Finsteraarhorn | 2280 | Bern/Valais | Bernese Alps |
# | I/B-09.II-D | [7.69028, 46.065] | CH | 1864 | 4221 | Zinalrothorn | 490 | Valais | Weisshorn-Matterhorn |
# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+
Trio
import trio
from cratedb_async.client import CrateClient
async def main():
crate = CrateClient('http://192.168.88.251:4200')
response = await crate.query('SELECT * FROM sys.summits')
print(response.as_table())
trio.run(main)
# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+
# | classification | coordinates | country | first_ascent | height | mountain | prominence | range | region |
# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+
# | I/B-07.V-B | [6.86444, 45.8325] | FR/IT | 1786 | 4808 | Mont Blanc | 4695 | U-Savoy/Aosta | Mont Blanc massif |
# | I/B-09.III-A | [7.86694, 45.93694] | CH | 1855 | 4634 | Monte Rosa | 2165 | Valais | Monte Rosa Alps |
# | I/B-09.V-A | [7.85889, 46.09389] | CH | 1858 | 4545 | Dom | 1046 | Valais | Mischabel |
# | I/B-09.III-A | [7.83556, 45.92222] | CH/IT | 1861 | 4527 | Liskamm | 376 | Valais/Aosta | Monte Rosa Alps |
# | I/B-09.II-D | [7.71583, 46.10139] | CH | 1861 | 4506 | Weisshorn | 1235 | Valais | Weisshorn-Matterhorn |
# | I/B-09.II-A | [7.65861, 45.97639] | CH/IT | 1865 | 4478 | Matterhorn | 1042 | Valais/Aosta | Weisshorn-Matterhorn |
# | I/B-09.II-C | [7.61194, 46.03417] | CH | 1862 | 4357 | Dent Blanche | 915 | Valais | Weisshorn-Matterhorn |
# | I/B-09.I-B | [7.29917, 45.9375] | CH | 1859 | 4314 | Grand Combin | 1517 | Valais | Grand Combin Alps |
# | I/B-12.II-A | [8.12611, 46.53722] | CH | 1829 | 4274 | Finsteraarhorn | 2280 | Bern/Valais | Bernese Alps |
# | I/B-09.II-D | [7.69028, 46.065] | CH | 1864 | 4221 | Zinalrothorn | 490 | Valais | Weisshorn-Matterhorn |
# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+
Bulk insert
import asyncio
from cratedb_async.client import CrateClient
async def main():
crate = CrateClient('http://192.168.88.251:4200')
rows = [
('one', 2, ['three', ]),
('three', 4, ['five', ])
]
table_name = 'my_tbl'
create_table_resp = await crate.query(f'create table {table_name} (one text, two integer, three array(TEXT))')
print(create_table_resp)
# SQLResponse(error=None, columns=[], row_count=1, duration=177.55101)
response = await crate.bulk_insert(table_name, rows)
print(response)
# SQLResponse(error=None, columns=[], row_count=0, duration=6.341763)
await crate.query(f'refresh table {table_name}')
select_response = await crate.query(f'select * from {table_name}')
print(select_response.as_table())
# SQLResponse(error=None, columns=[], row_count=1, duration=8.724443)
asyncio.run(main())
Style guide
This project uses Google Python Style guide with minor tweaks, enforced by pyling, read more in
- Google documentation: https://google.github.io/styleguide/pyguide.html
- Docstring documentation: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
Tweaks
- Max line is 100
- Indentation is four spaces.
Release files for cratedb-async 0.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cratedb_async-0.0.11.tar.gz | 24.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cratedb_async-0.0.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.0 kB
Release files / cratedb_async-0.0.11.tar.gz
| Download URL | cratedb_async-0.0.11.tar.gz |
|---|---|
| Size | 24.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a53060c477fd03c6ab1a3a207a0e4eb075f3c0fb6aa21c0bae76b9286559b49a
|
|
BLAKE2b-256 checksum How to use checksums |
704594ca8fa89331e10bfc371d53c952f8b0a60e964b39bb9d971d7757bb64ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cratedb_async-0.0.11-py3-none-any.whl
| Download URL | cratedb_async-0.0.11-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
75e4e37092fab1c3f80f454624cc52e4540dfdb209d380159ff97f90e9c7f134
|
|
BLAKE2b-256 checksum How to use checksums |
8a1c0fec656ec99fcb8253314e67e9c4116bf045568e5e74906b089ef9453342
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|