Name | cratedb-async JSON |
Version |
0.0.3
JSON |
| download |
home_page | None |
Summary | None |
upload_time | 2025-01-21 12:01:07 |
maintainer | None |
docs_url | None |
author | surister |
requires_python | <4.0,>=3.12 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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
```python
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
```python
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
```python
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "cratedb-async",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": null,
"author": "surister",
"author_email": "surister98@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5e/e9/6f7a7f373e1061a829d4ec235b4bfb8b34b24a684d2dd9c3180dfdec8ac3/cratedb_async-0.0.3.tar.gz",
"platform": null,
"description": "# CrateDB Async driver based on httpx.\n\nThis CrateDB driver does not follow the DB-API, but its own API design.\n\n## Usage\n\nIt can be used with any async library,\n\n#### Asyncio\n```python\n\nimport asyncio\n\nfrom cratedb_async.client import CrateClient\n\n\nasync def main():\n crate = CrateClient('http://192.168.88.251:4200')\n response = await crate.query('SELECT * FROM sys.summits')\n print(response.as_table())\n\nasyncio.run(main())\n\n# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+\n# | classification | coordinates | country | first_ascent | height | mountain | prominence | range | region |\n# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+\n# | I/B-07.V-B | [6.86444, 45.8325] | FR/IT | 1786 | 4808 | Mont Blanc | 4695 | U-Savoy/Aosta | Mont Blanc massif |\n# | I/B-09.III-A | [7.86694, 45.93694] | CH | 1855 | 4634 | Monte Rosa | 2165 | Valais | Monte Rosa Alps |\n# | I/B-09.V-A | [7.85889, 46.09389] | CH | 1858 | 4545 | Dom | 1046 | Valais | Mischabel |\n# | I/B-09.III-A | [7.83556, 45.92222] | CH/IT | 1861 | 4527 | Liskamm | 376 | Valais/Aosta | Monte Rosa Alps |\n# | I/B-09.II-D | [7.71583, 46.10139] | CH | 1861 | 4506 | Weisshorn | 1235 | Valais | Weisshorn-Matterhorn |\n# | I/B-09.II-A | [7.65861, 45.97639] | CH/IT | 1865 | 4478 | Matterhorn | 1042 | Valais/Aosta | Weisshorn-Matterhorn |\n# | I/B-09.II-C | [7.61194, 46.03417] | CH | 1862 | 4357 | Dent Blanche | 915 | Valais | Weisshorn-Matterhorn |\n# | I/B-09.I-B | [7.29917, 45.9375] | CH | 1859 | 4314 | Grand Combin | 1517 | Valais | Grand Combin Alps |\n# | I/B-12.II-A | [8.12611, 46.53722] | CH | 1829 | 4274 | Finsteraarhorn | 2280 | Bern/Valais | Bernese Alps |\n# | I/B-09.II-D | [7.69028, 46.065] | CH | 1864 | 4221 | Zinalrothorn | 490 | Valais | Weisshorn-Matterhorn |\n# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+\n```\n\n\n#### Trio\n\n```python\nimport trio\n\nfrom cratedb_async.client import CrateClient\n\n\nasync def main():\n crate = CrateClient('http://192.168.88.251:4200')\n response = await crate.query('SELECT * FROM sys.summits')\n print(response.as_table())\n\ntrio.run(main)\n\n# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+\n# | classification | coordinates | country | first_ascent | height | mountain | prominence | range | region |\n# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+\n# | I/B-07.V-B | [6.86444, 45.8325] | FR/IT | 1786 | 4808 | Mont Blanc | 4695 | U-Savoy/Aosta | Mont Blanc massif |\n# | I/B-09.III-A | [7.86694, 45.93694] | CH | 1855 | 4634 | Monte Rosa | 2165 | Valais | Monte Rosa Alps |\n# | I/B-09.V-A | [7.85889, 46.09389] | CH | 1858 | 4545 | Dom | 1046 | Valais | Mischabel |\n# | I/B-09.III-A | [7.83556, 45.92222] | CH/IT | 1861 | 4527 | Liskamm | 376 | Valais/Aosta | Monte Rosa Alps |\n# | I/B-09.II-D | [7.71583, 46.10139] | CH | 1861 | 4506 | Weisshorn | 1235 | Valais | Weisshorn-Matterhorn |\n# | I/B-09.II-A | [7.65861, 45.97639] | CH/IT | 1865 | 4478 | Matterhorn | 1042 | Valais/Aosta | Weisshorn-Matterhorn |\n# | I/B-09.II-C | [7.61194, 46.03417] | CH | 1862 | 4357 | Dent Blanche | 915 | Valais | Weisshorn-Matterhorn |\n# | I/B-09.I-B | [7.29917, 45.9375] | CH | 1859 | 4314 | Grand Combin | 1517 | Valais | Grand Combin Alps |\n# | I/B-12.II-A | [8.12611, 46.53722] | CH | 1829 | 4274 | Finsteraarhorn | 2280 | Bern/Valais | Bernese Alps |\n# | I/B-09.II-D | [7.69028, 46.065] | CH | 1864 | 4221 | Zinalrothorn | 490 | Valais | Weisshorn-Matterhorn |\n# +----------------+---------------------+---------+--------------+--------+----------------+------------+---------------+----------------------+\n\n```\n\n#### Bulk insert\n\n```python\nimport asyncio\n\nfrom cratedb_async.client import CrateClient\n\n\nasync def main():\n crate = CrateClient('http://192.168.88.251:4200')\n rows = [\n ('one', 2, ['three', ]),\n ('three', 4, ['five', ])\n ]\n table_name = 'my_tbl'\n \n create_table_resp = await crate.query(f'create table {table_name} (one text, two integer, three array(TEXT))')\n print(create_table_resp)\n # SQLResponse(error=None, columns=[], row_count=1, duration=177.55101)\n\n response = await crate.bulk_insert(table_name, rows)\n print(response)\n # SQLResponse(error=None, columns=[], row_count=0, duration=6.341763)\n\n await crate.query(f'refresh table {table_name}')\n\n select_response = await crate.query(f'select * from {table_name}')\n print(select_response.as_table())\n # SQLResponse(error=None, columns=[], row_count=1, duration=8.724443)\n\nasyncio.run(main())\n```\n\n\n\n## Style guide\nThis project uses Google Python Style guide with minor tweaks, enforced by pyling, read more in\n* Google documentation: https://google.github.io/styleguide/pyguide.html\n* Docstring documentation: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html\n\n### Tweaks\n* Max line is 100\n* Indentation is four spaces.\n\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.0.3",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "106b70bb1710c8f06711051c207718f3f631a06271c3789af733e290c066f8af",
"md5": "75822187a06787b0d63c398773cbb11d",
"sha256": "83eb51995729af84f37e963593a66a00fb57180b34576b78348066372105a036"
},
"downloads": -1,
"filename": "cratedb_async-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "75822187a06787b0d63c398773cbb11d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 5132,
"upload_time": "2025-01-21T12:01:06",
"upload_time_iso_8601": "2025-01-21T12:01:06.555294Z",
"url": "https://files.pythonhosted.org/packages/10/6b/70bb1710c8f06711051c207718f3f631a06271c3789af733e290c066f8af/cratedb_async-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5ee96f7a7f373e1061a829d4ec235b4bfb8b34b24a684d2dd9c3180dfdec8ac3",
"md5": "07c3771337e636b573377e7dd9c9ffa6",
"sha256": "66c811fd5568c121ba100ba5ef1cf2edb78c9ba3ed2009a7baf2bb94897d1577"
},
"downloads": -1,
"filename": "cratedb_async-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "07c3771337e636b573377e7dd9c9ffa6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 4079,
"upload_time": "2025-01-21T12:01:07",
"upload_time_iso_8601": "2025-01-21T12:01:07.791516Z",
"url": "https://files.pythonhosted.org/packages/5e/e9/6f7a7f373e1061a829d4ec235b4bfb8b34b24a684d2dd9c3180dfdec8ac3/cratedb_async-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-21 12:01:07",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "cratedb-async"
}