-
Notifications
You must be signed in to change notification settings - Fork 1
Driver: Improve section about Python #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amotl
wants to merge
10
commits into
main
Choose a base branch
from
python
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
045ba93
Connect/Python: Add `micropython-cratedb`
amotl 8f2af5d
Connect/Python: Add `conecta`
amotl c3f63f4
Connect/Python: Add `connectorx`
amotl 9b4aa91
Connect/Python: Add `turbodbc`
amotl 0f79520
Connect/Python: Improve guidance to dataframe libraries
amotl 5685bed
Connect/Python: Add CI badges and link to examples
amotl 6d967f5
Connect/Python: Naming things: s/driver/client/
amotl 2add79f
Connect/Python: Add `records`
amotl 5c49454
Connect/Python: Reorganize section. Each item gets a dedicated page.
amotl bf66b0d
Connect/Python: Implement suggestions by CodeRabbit
amotl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,7 +179,7 @@ application | |
| java | ||
| javascript | ||
| php | ||
| python | ||
| python/index | ||
| ruby | ||
| natural | ||
| All drivers <drivers> | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| (aiopg)= | ||
|
|
||
| # aiopg | ||
|
|
||
| aiopg is a python library for accessing a PostgreSQL database from the asyncio | ||
| (PEP-3156/tulip) framework. It wraps asynchronous features of the Psycopg | ||
| database driver. | ||
| For more information, see the [aiopg documentation]. | ||
|
|
||
| ```python | ||
| import asyncio | ||
| import aiopg | ||
|
|
||
| async def run(): | ||
| async with aiopg.create_pool(host="<name-of-your-cluster>.cratedb.net", port=5432, user="admin", password="<PASSWORD>", sslmode="require") as pool: | ||
| async with pool.acquire() as conn: | ||
| async with conn.cursor() as cursor: | ||
| await cursor.execute("SELECT * FROM sys.summits") | ||
| result = await cursor.fetchone() | ||
| print(result) | ||
|
|
||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(run()) | ||
| ``` | ||
|
|
||
|
|
||
| [aiopg documentation]: https://aiopg.readthedocs.io/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| (asyncpg)= | ||
|
|
||
| # asyncpg | ||
|
|
||
| asyncpg is a database interface library designed specifically for PostgreSQL | ||
| and Python/asyncio. asyncpg is an efficient, clean implementation of the | ||
| PostgreSQL server binary protocol for use with Python's asyncio framework. | ||
| For more information, see the [asyncpg documentation]. | ||
|
|
||
| ```python | ||
| import asyncio | ||
| import asyncpg | ||
|
|
||
| async def run(): | ||
| conn = await asyncpg.connect(host="<name-of-your-cluster>.cratedb.net", port=5432, user="admin", password="<PASSWORD>", ssl=True) | ||
| try: | ||
| result = await conn.fetch("SELECT * FROM sys.summits") | ||
| finally: | ||
| await conn.close() | ||
| print(result) | ||
|
|
||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(run()) | ||
| ``` | ||
|
|
||
|
|
||
| [asyncpg documentation]: https://magicstack.github.io/asyncpg/current/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| (conecta-intro)= | ||
|
|
||
| # Conecta | ||
|
|
||
| :::{div} .float-right .text-right | ||
| [](https://github.com/surister/conecta/actions/workflows/test_core.yml) | ||
| [](https://github.com/surister/conecta/actions/workflows/test_python.yml) | ||
| ::: | ||
| :::{div} .clearfix | ||
| ::: | ||
|
|
||
| {ref}`conecta` is a library designed to load data from SQL databases into | ||
| Arrow with maximum speed and memory efficiency by leveraging zero-copy and | ||
| true concurrency in Python. | ||
|
|
||
| ```python | ||
| from pprint import pprint | ||
| from conecta import read_sql | ||
|
|
||
| table = read_sql( | ||
| "postgres://crate:crate@localhost:5432/doc", | ||
| queries=["SELECT country, region, mountain, height, latitude(coordinates), longitude(coordinates) FROM sys.summits ORDER BY height DESC LIMIT 3"], | ||
| ) | ||
|
|
||
| # Display in Python format. | ||
| pprint(table.to_pylist()) | ||
|
|
||
| # Optionally convert to pandas dataframe. | ||
| print(table.to_pandas()) | ||
|
|
||
| # Optionally convert to Polars dataframe. | ||
| import polars as pl | ||
| print(pl.from_arrow(table)) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| (connectorx)= | ||
|
|
||
| # ConnectorX | ||
|
|
||
| :::{div} .float-right .text-right | ||
| [](https://github.com/crate/cratedb-examples/actions/workflows/lang-python-connectorx.yml) | ||
| ::: | ||
| :::{div} .clearfix | ||
| ::: | ||
|
|
||
| [ConnectorX] enables you to load data from databases into Python in the | ||
| fastest and most memory-efficient way. | ||
|
|
||
| ```python | ||
| import connectorx as cx | ||
|
|
||
| cx.read_sql( | ||
| "postgresql://username:password@server:port/database", | ||
| "SELECT * FROM lineitem", | ||
| partition_on="l_orderkey", | ||
| partition_num=10, | ||
| ) | ||
| ``` | ||
|
|
||
| - [Connect to CrateDB using ConnectorX] | ||
|
|
||
|
|
||
| [ConnectorX]: https://sfu-db.github.io/connector-x/ | ||
| [Connect to CrateDB using ConnectorX]: https://github.com/crate/cratedb-examples/tree/main/by-language/python-connectorx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| (crate-python)= | ||
| # crate-python | ||
|
|
||
| :::{div} .float-right .text-right | ||
| [](https://github.com/crate/cratedb-examples/actions/workflows/lang-python-dbapi.yml) | ||
| ::: | ||
| :::{div} .clearfix | ||
| ::: | ||
|
|
||
| The `crate` Python package offers a database client implementation compatible | ||
| with the Python Database API 2.0 specification, and also includes the CrateDB | ||
| SQLAlchemy dialect. See the full documentation {ref}`here <crate-python:index>`. | ||
| The package can be installed using `pip install crate`. | ||
|
|
||
| ```python | ||
| from crate import client | ||
|
|
||
| conn = client.connect("https://<name-of-your-cluster>.cratedb.net:4200", username="admin", password="<PASSWORD>", verify_ssl_cert=True) | ||
|
|
||
| with conn: | ||
| cursor = conn.cursor() | ||
| cursor.execute("SELECT * FROM sys.summits") | ||
| result = cursor.fetchone() | ||
| print(result) | ||
| ``` | ||
|
|
||
| - [Connect to CrateDB using the Python DB API] | ||
|
|
||
|
|
||
| [Connect to CrateDB using the Python DB API]: https://github.com/crate/cratedb-examples/tree/main/by-language/python-dbapi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide a runnable example for each item, e.g. by adding inline dependencies (PEP 723) implemented by
uv, or by just adding a simplepip install ...incantation to the docs, followed up by an incantation how to invoke the program.This has been conducted for all the other clients, so the Python area should not be left behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also what's inside this patch before closing it.