Skip to content

Commit 129d3e2

Browse files
committed
ConnectorX: Hello, World!
1 parent 70158f0 commit 129d3e2

File tree

9 files changed

+185
-0
lines changed

9 files changed

+185
-0
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ updates:
7878
schedule:
7979
interval: "daily"
8080

81+
- directory: "/by-language/python-connectorx"
82+
package-ecosystem: "pip"
83+
schedule:
84+
interval: "daily"
85+
8186
- directory: "/by-language/python-dbapi"
8287
package-ecosystem: "pip"
8388
schedule:
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Python ConnectorX
2+
3+
on:
4+
pull_request:
5+
branches: ~
6+
paths:
7+
- '.github/workflows/lang-python-connectorx.yml'
8+
- 'by-language/python-connectorx/**'
9+
- '/requirements.txt'
10+
push:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/lang-python-connectorx.yml'
14+
- 'by-language/python-connectorx/**'
15+
- '/requirements.txt'
16+
17+
# Allow job to be triggered manually.
18+
workflow_dispatch:
19+
20+
# Run job each night after CrateDB nightly has been published.
21+
schedule:
22+
- cron: '0 3 * * *'
23+
24+
# Cancel in-progress jobs when pushing to the same branch.
25+
concurrency:
26+
cancel-in-progress: true
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
29+
jobs:
30+
test:
31+
name: "
32+
Python: ${{ matrix.python-version }}
33+
CrateDB: ${{ matrix.cratedb-version }}
34+
on ${{ matrix.os }}"
35+
runs-on: ${{ matrix.os }}
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
os: [ 'ubuntu-22.04' ]
40+
python-version: [
41+
'3.10',
42+
'3.13',
43+
]
44+
cratedb-version: [ 'nightly' ]
45+
46+
services:
47+
cratedb:
48+
image: crate/crate:${{ matrix.cratedb-version }}
49+
ports:
50+
- 4200:4200
51+
- 5432:5432
52+
env:
53+
CRATE_HEAP_SIZE: 4g
54+
55+
steps:
56+
57+
- name: Acquire sources
58+
uses: actions/checkout@v4
59+
60+
- name: Set up Python
61+
uses: actions/setup-python@v5
62+
with:
63+
python-version: ${{ matrix.python-version }}
64+
architecture: x64
65+
cache: 'pip'
66+
cache-dependency-path: |
67+
requirements.txt
68+
by-language/python-connectorx/requirements*.txt
69+
70+
- name: Install uv
71+
uses: astral-sh/setup-uv@v5
72+
73+
- name: Install utilities
74+
run: |
75+
uv pip install --system -r requirements.txt
76+
77+
- name: Validate by-language/python-connectorx
78+
run: |
79+
ngr test --accept-no-venv by-language/python-connectorx
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Connect to CrateDB and CrateDB Cloud using ConnectorX
2+
3+
## About
4+
5+
[ConnectorX] enables you to load data from databases into Python in the
6+
fastest and most memory efficient way.
7+
8+
## Usage
9+
10+
You can optionally accelerate the data loading using parallelism by
11+
specifying a partition column.
12+
```python
13+
import connectorx as cx
14+
15+
cx.read_sql(
16+
"postgresql://username:password@server:port/database",
17+
"SELECT * FROM lineitem",
18+
partition_on="l_orderkey",
19+
partition_num=10,
20+
)
21+
```
22+
Please find more [usage examples] on the [ConnectorX documentation].
23+
24+
## Status
25+
26+
The example program `demo.py` in this folder demonstrates basic use
27+
by reading from the built-in `sys.summits` table.
28+
29+
Please note many special data types have not been verified to work
30+
with CrateDB yet, or have been identified to not work yet. We are
31+
enumerating them within the [backlog] file.
32+
33+
34+
[backlog]: ./backlog.md
35+
[ConnectorX]: https://pypi.org/project/connectorx/
36+
[ConnectorX documentation]: https://sfu-db.github.io/connector-x/
37+
[usage examples]: https://sfu-db.github.io/connector-x/api.html#examples
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT * FROM sys.summits ORDER BY height DESC LIMIT 10
2+
pyo3_runtime.PanicException: not implemented: point
3+
https://github.com/sfu-db/connector-x/issues/723

by-language/python-connectorx/demo.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Example program connecting to CrateDB [1] using ConnectorX [2],
3+
using its PostgreSQL interface [3].
4+
5+
[1] https://cratedb.com/database
6+
[2] https://sfu-db.github.io/connector-x/
7+
[3] https://sfu-db.github.io/connector-x/databases/postgres.html
8+
"""
9+
10+
# /// script
11+
# requires-python = ">=3.10"
12+
# dependencies = [
13+
# "connectorx<0.5",
14+
# "pandas>2,<3",
15+
# ]
16+
# ///
17+
18+
from pprint import pprint
19+
import connectorx as cx
20+
21+
22+
def main():
23+
data = cx.read_sql(
24+
"postgresql://crate@localhost/",
25+
"SELECT country, height, mountain, range, region FROM sys.summits ORDER BY height DESC LIMIT 10",
26+
protocol="cursor",
27+
)
28+
pprint(data)
29+
30+
31+
if __name__ == "__main__":
32+
main()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[tool.pytest.ini_options]
2+
minversion = "2.0"
3+
addopts = """
4+
-rfEX -p pytester --strict-markers --verbosity=3
5+
--capture=no
6+
"""
7+
log_level = "DEBUG"
8+
log_cli_level = "DEBUG"
9+
testpaths = ["*.py"]
10+
xfail_strict = true
11+
markers = [
12+
]
13+
14+
[tool.ruff]
15+
line-length = 100
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest<9
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connectorx<0.5
2+
pandas>2,<3

by-language/python-connectorx/test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import shlex
2+
import subprocess
3+
4+
5+
def run(command: str):
6+
subprocess.check_call(shlex.split(command))
7+
8+
9+
def test_demo():
10+
cmd = "time python3 demo.py"
11+
run(cmd)

0 commit comments

Comments
 (0)