-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
375 additions
and
118 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
name: build-python-client | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- .github/workflows/lint-python.yml | ||
- client/**.py | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.13" | ||
- uses: astral-sh/setup-uv@v3 | ||
with: | ||
version: "0.4.29" | ||
- name: Install dependencies | ||
run: uv sync | ||
working-directory: ./client | ||
- name: Build wheel file | ||
run: ./build.sh | ||
working-directory: ./client |
This file contains 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
gen | ||
gduck/proto | ||
build | ||
dist | ||
*.egg-info | ||
__pycache__ | ||
.venv | ||
.mypy_cache |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,2 +1,14 @@ | ||
## Python client | ||
# gduck Python client | ||
|
||
Client implementation to utilize remove gduck server. | ||
|
||
## Usage | ||
|
||
```python | ||
from gduck import Connection | ||
|
||
conn = Connection("localhost:50051") | ||
|
||
with conn.transaction(database_file="database.duckdb", mode="read_write") as trans: | ||
counts = trans.query_value("SELECT COUNT(*) FROM videos WHERE comments > ?", 10) | ||
``` |
This file contains 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,5 @@ | ||
#!/bin/bash -eu | ||
|
||
./codegen.sh | ||
|
||
uv build --wheel |
This file contains 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 |
---|---|---|
@@ -1,6 +1,26 @@ | ||
#!/bin/bash -eu | ||
|
||
SCRIPT_DIR=$(cd $(dirname $0); pwd) | ||
PARENT_DIR=$(dirname $SCRIPT_DIR) | ||
PROJECT_DIR=$(dirname $SCRIPT_DIR) | ||
PROTO_DIR="${PROJECT_DIR}/proto" | ||
GEN_DIR="${SCRIPT_DIR}/gduck/proto" | ||
|
||
docker build -f ${SCRIPT_DIR}/Dockerfile --output=type=local,dest=$SCRIPT_DIR/gen $PARENT_DIR | ||
cleanup() { | ||
rm -rf ${GEN_DIR} | ||
mkdir -p ${GEN_DIR} | ||
} | ||
|
||
codegen() { | ||
uv run python -m grpc_tools.protoc \ | ||
-I ${PROTO_DIR} \ | ||
--python_out=${GEN_DIR} \ | ||
--grpc_python_out=${GEN_DIR} \ | ||
${PROTO_DIR}/*.proto | ||
} | ||
|
||
if [ "${1:-}" = "--clean" ]; then | ||
cleanup | ||
else | ||
cleanup | ||
codegen | ||
fi |
This file contains 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,10 @@ | ||
# flake8: noqa: F401,F402,F403 | ||
import sys | ||
from pathlib import Path | ||
|
||
PROTO_PATH = (Path(__file__).parent / "proto").absolute() | ||
sys.path.append(str(PROTO_PATH)) | ||
|
||
from .client import * | ||
from .request import * | ||
from .types import * |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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,24 @@ | ||
from typing import Generator | ||
|
||
import pytest | ||
from gduck.client import Addr, Connection | ||
from testcontainers.core.container import DockerContainer | ||
from testcontainers.core.waiting_utils import wait_for | ||
|
||
IMAGE_NAME = "gduck:latest" | ||
CONTAINER_PORT = 50051 | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def gduck_container(image_name: str = IMAGE_NAME) -> Generator[DockerContainer, None, None]: | ||
with DockerContainer(image_name).with_exposed_ports(CONTAINER_PORT) as dc: | ||
wait_for(lambda: dc.get_wrapped_container() is not None and dc.get_wrapped_container().health == "healthy") | ||
print("container becomes healthy") | ||
yield dc | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def gduck_connection(gduck_container: DockerContainer) -> Connection: | ||
host = gduck_container.get_container_host_ip() | ||
port = gduck_container.get_exposed_port(CONTAINER_PORT) | ||
return Connection(addr=Addr(host=host, port=port)) |
This file contains 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,7 @@ | ||
from gduck.client import Connection | ||
|
||
|
||
def test_query_value(gduck_connection: Connection) -> None: | ||
with gduck_connection.transaction(":memory:", "read_write") as trans: | ||
result = trans.query_value("SELECT 1;") | ||
assert result == 1 |
Oops, something went wrong.