Skip to main content

No project description provided

Project description

CrateDB Async driver based on httpx.

This CrateDB driver does not follow the DB-API, but its own API 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

Tweaks

  • Max line is 100
  • Indentation is four spaces.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cratedb_async-0.0.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cratedb_async-0.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file cratedb_async-0.0.2.tar.gz.

File metadata

  • Download URL: cratedb_async-0.0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cratedb_async-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8bb8993c2cec60a2d1a2bdad610c7eee5d57c3766174fe1d18e8c8e22d668d52
MD5 c3e70ae3efc4e57558c1351700bc6d29
BLAKE2b-256 c30f186901996028f5c8652b3b0592e511d4006ac2a4181f14d756d740485cac

See more details on using hashes here.

Provenance

The following attestation bundles were made for cratedb_async-0.0.2.tar.gz:

Publisher: python-publish.yml on surister/cratedb-async

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cratedb_async-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: cratedb_async-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cratedb_async-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5eac1392d473923c3cf3d6cf67daab138954e93d7dfdb33064f6d93755ee71c9
MD5 186759617c794705df79d7a3e9d1b8cc
BLAKE2b-256 f2e411986a1af3137bf7b2554e08429daeaf05a2cb053cec6257e765e84ddfab

See more details on using hashes here.

Provenance

The following attestation bundles were made for cratedb_async-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on surister/cratedb-async

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page