korpg 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. korpg-0.1.0/.github/workflows/ci.yml +119 -0
  2. korpg-0.1.0/.github/workflows/release.yml +228 -0
  3. korpg-0.1.0/.gitignore +9 -0
  4. korpg-0.1.0/AGENTS.md +49 -0
  5. korpg-0.1.0/CHANGELOG.md +15 -0
  6. korpg-0.1.0/CLAUDE.md +1 -0
  7. korpg-0.1.0/Cargo.lock +380 -0
  8. korpg-0.1.0/Cargo.toml +29 -0
  9. korpg-0.1.0/LICENSE +21 -0
  10. korpg-0.1.0/PKG-INFO +97 -0
  11. korpg-0.1.0/README.md +68 -0
  12. korpg-0.1.0/benches/README.md +66 -0
  13. korpg-0.1.0/benches/bench.py +180 -0
  14. korpg-0.1.0/korpg/__init__.py +29 -0
  15. korpg-0.1.0/korpg/_connection.py +500 -0
  16. korpg-0.1.0/korpg/_core.pyi +108 -0
  17. korpg-0.1.0/korpg/_dsn.py +77 -0
  18. korpg-0.1.0/korpg/_errors.py +82 -0
  19. korpg-0.1.0/korpg/_protocol.py +136 -0
  20. korpg-0.1.0/korpg/py.typed +0 -0
  21. korpg-0.1.0/pyproject.toml +67 -0
  22. korpg-0.1.0/rustfmt.toml +3 -0
  23. korpg-0.1.0/src/auth.rs +159 -0
  24. korpg-0.1.0/src/backend.rs +381 -0
  25. korpg-0.1.0/src/codecs.rs +636 -0
  26. korpg-0.1.0/src/error.rs +21 -0
  27. korpg-0.1.0/src/framing.rs +154 -0
  28. korpg-0.1.0/src/frontend.rs +247 -0
  29. korpg-0.1.0/src/lib.rs +756 -0
  30. korpg-0.1.0/tests/pg/init.sql +19 -0
  31. korpg-0.1.0/tests/pg/pg_hba.conf +9 -0
  32. korpg-0.1.0/tests/pg/start.sh +81 -0
  33. korpg-0.1.0/tests/test_arrays.py +131 -0
  34. korpg-0.1.0/tests/test_cache.py +153 -0
  35. korpg-0.1.0/tests/test_connect.py +132 -0
  36. korpg-0.1.0/tests/test_core.py +314 -0
  37. korpg-0.1.0/tests/test_dsn.py +72 -0
  38. korpg-0.1.0/tests/test_errors.py +66 -0
  39. korpg-0.1.0/tests/test_params.py +187 -0
  40. korpg-0.1.0/tests/test_query.py +218 -0
  41. korpg-0.1.0/tests/test_robust.py +230 -0
  42. korpg-0.1.0/tests/test_script.py +122 -0
  43. korpg-0.1.0/tests/test_smoke.py +11 -0
  44. korpg-0.1.0/tests/test_types.py +108 -0
  45. korpg-0.1.0/uv.lock +439 -0
@@ -0,0 +1,119 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ # A new push to a pull request stops the run of the one before.
12
+ concurrency:
13
+ group: ci-${{ github.ref }}
14
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
15
+
16
+ jobs:
17
+ lint:
18
+ name: Lint, types and Rust tests
19
+ runs-on: ubuntu-latest
20
+ timeout-minutes: 20
21
+ steps:
22
+ - uses: actions/checkout@v7
23
+
24
+ - name: Install Rust
25
+ uses: dtolnay/rust-toolchain@stable
26
+ with:
27
+ components: rustfmt, clippy
28
+
29
+ - uses: Swatinem/rust-cache@v2
30
+
31
+ - name: Install uv
32
+ uses: astral-sh/setup-uv@v10.3.3
33
+
34
+ - name: Rust formatting
35
+ run: cargo fmt --check
36
+
37
+ - name: Clippy
38
+ run: cargo clippy --all-targets -- -D warnings
39
+
40
+ - name: Rust tests
41
+ run: cargo test
42
+
43
+ - name: Install
44
+ run: uv sync
45
+
46
+ - name: Ruff
47
+ run: uv run --no-sync ruff check --output-format=github .
48
+
49
+ - name: Python formatting
50
+ run: uv run --no-sync ruff format --check .
51
+
52
+ - name: Pyright
53
+ run: uv run --no-sync pyright
54
+
55
+ test:
56
+ name: Python ${{ matrix.python }}
57
+ runs-on: ubuntu-latest
58
+ timeout-minutes: 30
59
+ strategy:
60
+ fail-fast: false
61
+ matrix:
62
+ python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]
63
+ steps:
64
+ - uses: actions/checkout@v7
65
+
66
+ - name: Start PostgreSQL
67
+ run: bash tests/pg/start.sh
68
+
69
+ - name: Install Rust
70
+ uses: dtolnay/rust-toolchain@stable
71
+
72
+ - uses: Swatinem/rust-cache@v2
73
+
74
+ - name: Install uv
75
+ uses: astral-sh/setup-uv@v10.3.3
76
+
77
+ - name: Install
78
+ run: uv sync --python ${{ matrix.python }}
79
+
80
+ - name: Build
81
+ run: uv run --no-sync maturin develop --release
82
+
83
+ # On 3.14t, -W error::RuntimeWarning fails the run if any module
84
+ # turns the GIL back on, which would undo the point.
85
+ - name: Tests
86
+ run: uv run --no-sync pytest ${{ endsWith(matrix.python, 't') && '-W error::RuntimeWarning' || '' }}
87
+
88
+ postgres-versions:
89
+ name: PostgreSQL ${{ matrix.postgres }}
90
+ runs-on: ubuntu-latest
91
+ timeout-minutes: 30
92
+ strategy:
93
+ fail-fast: false
94
+ matrix:
95
+ postgres: ["15", "16", "17", "18"]
96
+ env:
97
+ KORPG_TEST_PG_VERSION: ${{ matrix.postgres }}
98
+ steps:
99
+ - uses: actions/checkout@v7
100
+
101
+ - name: Start PostgreSQL
102
+ run: bash tests/pg/start.sh
103
+
104
+ - name: Install Rust
105
+ uses: dtolnay/rust-toolchain@stable
106
+
107
+ - uses: Swatinem/rust-cache@v2
108
+
109
+ - name: Install uv
110
+ uses: astral-sh/setup-uv@v10.3.3
111
+
112
+ - name: Install
113
+ run: uv sync --python 3.14
114
+
115
+ - name: Build
116
+ run: uv run --no-sync maturin develop --release
117
+
118
+ - name: Tests
119
+ run: uv run --no-sync pytest
@@ -0,0 +1,228 @@
1
+ # On a `v*` tag: check the tag matches the version in Cargo.toml, build
2
+ # wheels for every platform, install each one in a fresh venv and smoke-test
3
+ # it, then publish to PyPI.
4
+ # Run by hand (workflow_dispatch) to build and test without publishing.
5
+ name: Release
6
+
7
+ on:
8
+ push:
9
+ tags:
10
+ - "v*"
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ env:
17
+ SMOKE_CODE: "import korpg._core"
18
+
19
+ jobs:
20
+ check-version:
21
+ runs-on: ubuntu-latest
22
+ timeout-minutes: 10
23
+ steps:
24
+ - uses: actions/checkout@v7
25
+ with:
26
+ persist-credentials: false
27
+ - name: Check the tag matches the version
28
+ if: startsWith(github.ref, 'refs/tags/')
29
+ run: |
30
+ # The version is dynamic in pyproject.toml: maturin reads it from Cargo.toml.
31
+ version=$(python3 -c "import tomllib;print(tomllib.load(open('Cargo.toml','rb'))['package']['version'])")
32
+ test "v$version" = "${GITHUB_REF_NAME}" || { echo "tag ${GITHUB_REF_NAME} != v$version"; exit 1; }
33
+
34
+ linux:
35
+ needs: check-version
36
+ runs-on: ${{ matrix.runner }}
37
+ timeout-minutes: 30
38
+ strategy:
39
+ matrix:
40
+ include:
41
+ - { runner: ubuntu-22.04, target: x86_64 }
42
+ - { runner: ubuntu-24.04-arm, target: aarch64 }
43
+ steps:
44
+ - uses: actions/checkout@v7
45
+ with:
46
+ persist-credentials: false
47
+ - name: Build wheels
48
+ uses: PyO3/maturin-action@v1
49
+ with:
50
+ target: ${{ matrix.target }}
51
+ args: --release --out dist
52
+ manylinux: auto
53
+ - name: Smoke test wheel
54
+ run: |
55
+ python3 -m venv test-env
56
+ test-env/bin/pip install --quiet dist/*.whl
57
+ test-env/bin/python -I -c "$SMOKE_CODE"
58
+ - uses: actions/upload-artifact@v7
59
+ with:
60
+ name: wheels-linux-${{ matrix.target }}
61
+ path: dist
62
+
63
+ musllinux:
64
+ needs: check-version
65
+ runs-on: ${{ matrix.runner }}
66
+ timeout-minutes: 30
67
+ strategy:
68
+ matrix:
69
+ include:
70
+ - { runner: ubuntu-22.04, target: x86_64 }
71
+ - { runner: ubuntu-24.04-arm, target: aarch64 }
72
+ steps:
73
+ - uses: actions/checkout@v7
74
+ with:
75
+ persist-credentials: false
76
+ - name: Build wheels
77
+ uses: PyO3/maturin-action@v1
78
+ with:
79
+ target: ${{ matrix.target }}
80
+ args: --release --out dist
81
+ manylinux: musllinux_1_2
82
+ - name: Smoke test wheel in an Alpine container (the runner is glibc)
83
+ run: |
84
+ docker run --rm -e SMOKE_CODE -v "$PWD/dist:/dist:ro" python:3.13-alpine \
85
+ sh -c 'python -m venv /env && /env/bin/pip install --quiet /dist/*.whl && /env/bin/python -I -c "$SMOKE_CODE"'
86
+ - uses: actions/upload-artifact@v7
87
+ with:
88
+ name: wheels-musllinux-${{ matrix.target }}
89
+ path: dist
90
+
91
+ macos:
92
+ needs: check-version
93
+ runs-on: ${{ matrix.runner }}
94
+ timeout-minutes: 30
95
+ strategy:
96
+ matrix:
97
+ include:
98
+ - { runner: macos-15-intel, target: x86_64 }
99
+ - { runner: macos-latest, target: aarch64 }
100
+ steps:
101
+ - uses: actions/checkout@v7
102
+ with:
103
+ persist-credentials: false
104
+ - name: Build wheels
105
+ uses: PyO3/maturin-action@v1
106
+ with:
107
+ target: ${{ matrix.target }}
108
+ args: --release --out dist
109
+ - name: Smoke test wheel
110
+ run: |
111
+ python3 -m venv test-env
112
+ test-env/bin/pip install --quiet dist/*.whl
113
+ test-env/bin/python -I -c "$SMOKE_CODE"
114
+ - uses: actions/upload-artifact@v7
115
+ with:
116
+ name: wheels-macos-${{ matrix.target }}
117
+ path: dist
118
+
119
+ windows:
120
+ needs: check-version
121
+ runs-on: windows-latest
122
+ timeout-minutes: 30
123
+ steps:
124
+ - uses: actions/checkout@v7
125
+ with:
126
+ persist-credentials: false
127
+ - name: Build wheels
128
+ uses: PyO3/maturin-action@v1
129
+ with:
130
+ target: x64
131
+ args: --release --out dist
132
+ - name: Smoke test wheel
133
+ shell: bash
134
+ run: |
135
+ python -m venv test-env
136
+ test-env/Scripts/pip install --quiet dist/*.whl
137
+ test-env/Scripts/python -I -c "$SMOKE_CODE"
138
+ - uses: actions/upload-artifact@v7
139
+ with:
140
+ name: wheels-windows
141
+ path: dist
142
+
143
+ sdist:
144
+ needs: check-version
145
+ runs-on: ubuntu-latest
146
+ timeout-minutes: 30
147
+ steps:
148
+ - uses: actions/checkout@v7
149
+ with:
150
+ persist-credentials: false
151
+ - name: Build sdist
152
+ uses: PyO3/maturin-action@v1
153
+ with:
154
+ command: sdist
155
+ args: --out dist
156
+ # Installing an sdist compiles it, so this needs Rust.
157
+ - name: Install Rust
158
+ uses: dtolnay/rust-toolchain@stable
159
+ - name: Smoke test sdist
160
+ run: |
161
+ python3 -m venv test-env
162
+ test-env/bin/pip install --quiet dist/*.tar.gz
163
+ test-env/bin/python -I -c "$SMOKE_CODE"
164
+ - uses: actions/upload-artifact@v7
165
+ with:
166
+ name: wheels-sdist
167
+ path: dist
168
+
169
+ free-threaded:
170
+ # Wheels for free-threaded Python (3.14t): the abi3 wheels above don't
171
+ # cover it.
172
+ needs: check-version
173
+ runs-on: ${{ matrix.runner }}
174
+ timeout-minutes: 30
175
+ strategy:
176
+ matrix:
177
+ include:
178
+ - { runner: ubuntu-22.04, target: x86_64 }
179
+ - { runner: ubuntu-24.04-arm, target: aarch64 }
180
+ - { runner: macos-15-intel, target: x86_64 }
181
+ - { runner: macos-latest, target: aarch64 }
182
+ - { runner: windows-latest, target: x64 }
183
+ steps:
184
+ - uses: actions/checkout@v7
185
+ with:
186
+ persist-credentials: false
187
+ - uses: actions/setup-python@v7
188
+ id: python
189
+ with:
190
+ python-version: 3.14t
191
+ - name: Build wheels
192
+ uses: PyO3/maturin-action@v1
193
+ with:
194
+ target: ${{ matrix.target }}
195
+ # On Linux the build runs in a manylinux container, which has its own 3.14t.
196
+ args: --release --out dist -i ${{ runner.os == 'Linux' && 'python3.14t' || steps.python.outputs.python-path }}
197
+ manylinux: ${{ runner.os == 'Linux' && 'auto' || '' }}
198
+ - name: Smoke test wheel
199
+ shell: bash
200
+ run: |
201
+ "${{ steps.python.outputs.python-path }}" -m venv test-env
202
+ bin=test-env/bin; [ -d test-env/Scripts ] && bin=test-env/Scripts
203
+ $bin/python -m pip install --quiet dist/*.whl
204
+ $bin/python -I -c "$SMOKE_CODE"
205
+ - uses: actions/upload-artifact@v7
206
+ with:
207
+ name: wheels-free-threaded-${{ runner.os }}-${{ matrix.target }}
208
+ path: dist
209
+
210
+ publish:
211
+ name: Publish to PyPI
212
+ runs-on: ubuntu-latest
213
+ timeout-minutes: 10
214
+ if: startsWith(github.ref, 'refs/tags/')
215
+ needs: [check-version, linux, musllinux, macos, windows, sdist, free-threaded]
216
+ environment: pypi
217
+ permissions:
218
+ id-token: write # PyPI trusted publishing
219
+ steps:
220
+ - uses: actions/download-artifact@v8
221
+ with:
222
+ path: dist
223
+ pattern: wheels-*
224
+ merge-multiple: true
225
+ - name: Publish to PyPI
226
+ uses: pypa/gh-action-pypi-publish@release/v1
227
+ with:
228
+ packages-dir: dist
korpg-0.1.0/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ target/
2
+ __pycache__/
3
+ *.so
4
+ .venv/
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+
8
+ # Test certificates made by tests/pg/start.sh
9
+ tests/pg/.certs/
korpg-0.1.0/AGENTS.md ADDED
@@ -0,0 +1,49 @@
1
+ # Working on korpg
2
+
3
+ Instructions for AI coding agents working on this repository.
4
+
5
+ korpg is an async Postgres driver for Python. Its core is Rust, built with
6
+ PyO3 and maturin. The Rust code does no I/O: it frames and decodes protocol
7
+ messages and decodes rows. asyncio owns the socket and TLS.
8
+
9
+ ## Setup and checks
10
+
11
+ ```sh
12
+ uv sync # Python, the tools, and korpg built from source
13
+ uv run maturin develop --release # after changing Rust code, before running Python
14
+ ```
15
+
16
+ Before saying a change is done, run what CI runs:
17
+
18
+ ```sh
19
+ cargo fmt && cargo clippy --all-targets -- -D warnings && cargo test
20
+ uv run ruff check . && uv run ruff format .
21
+ uv run pyright
22
+ uv run pytest
23
+ ```
24
+
25
+ Tests need a Postgres server, named by the `KORPG_TEST_DSN` environment
26
+ variable. To start one:
27
+
28
+ ```sh
29
+ docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:18
30
+ ```
31
+
32
+ ## Rules
33
+
34
+ - **Python 3.10 to 3.14, and free-threaded 3.14t.** Write `X | Y` only in
35
+ annotations, with `from __future__ import annotations` at the top of
36
+ the module. Use `Union[X, Y]` and `Optional[X]` elsewhere.
37
+ - **msgspec and pydantic are optional.** Import them lazily, only where
38
+ a model of that kind is used, never at the top of a module.
39
+ - **Rust**: only `src/lib.rs` uses PyO3. The rest of the Rust stays plain
40
+ Rust, and does no I/O.
41
+ - **Performance is the point.** Measure a change against asyncpg before
42
+ you claim it is faster. Do not add an allocation or a call per row
43
+ without measuring it.
44
+ - **Before 1.0, break the API directly**: no deprecation shims. Every
45
+ change goes in `CHANGELOG.md` under `## Unreleased`, with how to update.
46
+ - **New behavior needs a test.**
47
+ - **Docstrings are documentation.** Write them for users, in plain English.
48
+ - **Code, comments, docs and commit messages are in English.** Commits
49
+ follow Conventional Commits (`feat:`, `fix:`, `docs:`, `perf:`...).
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - `korpg.connect()` opens a connection, with TLS modes (`verify-full` by default), `ssl=` for your own context, and a timeout.
6
+ - Authentication: trust, cleartext, MD5 and SCRAM-SHA-256. Cleartext and MD5 need TLS unless `allow_insecure_auth=True`.
7
+ - `fetch`, `fetchrow` and `execute` with `$1` parameters. Rows are tuples, or `row_type=` a dataclass or msgspec Struct.
8
+ - Decodes bool, bytea, int2/4/8, float4/8, text, varchar, bpchar, name, uuid, timestamp, timestamptz and NULL. Other types come back as bytes.
9
+ - Errors: `PostgresError` with the SQLSTATE, and `UniqueViolation` for 23505.
10
+ - Test server script `tests/pg/start.sh`.
11
+ - Decodes `date`, `time`, `numeric` (as `Decimal`), `json` and `jsonb` (as `str`), `interval` (as `timedelta`) and one-dimensional arrays.
12
+ - Parameters accept `date`, `time`, `Decimal`, `timedelta` and lists (sent as arrays, empty lists included).
13
+ - `PostgresError` gets `detail`, `hint`, `schema_name`, `table_name`, `column_name`, `constraint_name` and `data_type` fields.
14
+ - `Connection.execute_script()` runs SQL text with several statements, without parameters.
15
+ - `Connection.is_closed()` reports whether the connection is closed.
korpg-0.1.0/CLAUDE.md ADDED
@@ -0,0 +1 @@
1
+ @AGENTS.md