arcadedb-driver-grpc 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.
- arcadedb_driver_grpc-0.1.0/.gitignore +14 -0
- arcadedb_driver_grpc-0.1.0/LICENSE +201 -0
- arcadedb_driver_grpc-0.1.0/PKG-INFO +412 -0
- arcadedb_driver_grpc-0.1.0/README.md +397 -0
- arcadedb_driver_grpc-0.1.0/pyproject.toml +41 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/__init__.py +113 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/_generated/__init__.py +20 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/_generated/arcadedb_server_pb2.py +231 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/_generated/arcadedb_server_pb2.pyi +2635 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/_generated/arcadedb_server_pb2_grpc.py +1090 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/_generated/arcadedb_server_pb2_grpc.pyi +307 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/aio.py +547 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/auth.py +246 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/errors.py +24 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/py.typed +0 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/stream.py +210 -0
- arcadedb_driver_grpc-0.1.0/src/arcadedb_driver_grpc/transaction.py +227 -0
- arcadedb_driver_grpc-0.1.0/tests/__init__.py +0 -0
- arcadedb_driver_grpc-0.1.0/tests/conftest.py +154 -0
- arcadedb_driver_grpc-0.1.0/tests/test_aio.py +578 -0
- arcadedb_driver_grpc-0.1.0/tests/test_auth.py +71 -0
- arcadedb_driver_grpc-0.1.0/tests/test_client.py +71 -0
- arcadedb_driver_grpc-0.1.0/tests/test_generated_import.py +28 -0
- arcadedb_driver_grpc-0.1.0/tests/test_public_surface.py +47 -0
- arcadedb_driver_grpc-0.1.0/tests/test_stream.py +290 -0
- arcadedb_driver_grpc-0.1.0/tests/test_transaction.py +231 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
*.tsbuildinfo
|
|
4
|
+
.DS_Store
|
|
5
|
+
coverage/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
__pycache__/
|
|
8
|
+
.venv/
|
|
9
|
+
.mypy_cache/
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
|
|
12
|
+
# Scratch workspace for subagent-driven plan execution (ledger, briefs, review packages).
|
|
13
|
+
# Never part of a commit; see docs/superpowers/plans/.
|
|
14
|
+
.superpowers/
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: arcadedb-driver-grpc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python gRPC client for ArcadeDB's data plane, generated from ArcadeDB's protobuf contract.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ArcadeData/arcadedb-drivers/tree/main/python/packages/driver-grpc#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/ArcadeData/arcadedb-drivers/issues
|
|
7
|
+
Project-URL: Repository, https://github.com/ArcadeData/arcadedb-drivers
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: arcadedb,database,graph-database,grpc,multi-model
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: grpcio>=1.83.1
|
|
13
|
+
Requires-Dist: protobuf>=7.35.1
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# arcadedb-driver-grpc
|
|
17
|
+
|
|
18
|
+
A Python gRPC client for [ArcadeDB](https://arcadedb.com)'s data plane, generated from ArcadeDB's
|
|
19
|
+
protobuf contract (`contracts/arcadedb-server-*.proto`), with a hand-written facade on top for
|
|
20
|
+
authentication, the two streaming RPCs, and explicit transactions.
|
|
21
|
+
|
|
22
|
+
If you want an HTTP client instead - including one that works from environments gRPC cannot reach
|
|
23
|
+
- see [`arcadedb-driver`](../driver/README.md).
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
- Python `>=3.10`.
|
|
28
|
+
- An ArcadeDB server with the gRPC plugin enabled, at or near the version in the compatibility
|
|
29
|
+
table below.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install arcadedb-driver-grpc
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
or, in a [uv](https://docs.astral.sh/uv/) project:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv add arcadedb-driver-grpc
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from arcadedb_driver_grpc import create_client, messages
|
|
47
|
+
|
|
48
|
+
with create_client("localhost:50051", insecure=True) as client:
|
|
49
|
+
response = client.raw.ExecuteQuery(
|
|
50
|
+
messages.ExecuteQueryRequest(database="mydb", query="SELECT FROM Person WHERE age > 21", language="sql")
|
|
51
|
+
)
|
|
52
|
+
for result in response.results:
|
|
53
|
+
for record in result.records:
|
|
54
|
+
print(record.rid, dict(record.properties))
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`target` is gRPC's native `host:port` form - `"localhost:50051"`, not a URL. There is no scheme to
|
|
58
|
+
parse and nothing to default: pass `credentials=grpc.ssl_channel_credentials()` for TLS, or
|
|
59
|
+
`insecure=True` to say explicitly that you want a plaintext channel.
|
|
60
|
+
|
|
61
|
+
`raw` is the generated stub for `com.arcadedb.grpc.ArcadeDbService` - every RPC the `.proto`
|
|
62
|
+
contract declares is reachable through it. `create_client` adds three wrappers on top for the RPCs
|
|
63
|
+
the generated stub alone handles badly: `stream_query`, `insert_stream`, and `transaction`.
|
|
64
|
+
Everything else - the unary CRUD calls, `BulkInsert`, `InsertBidirectional`, `GraphBatchLoad` - is
|
|
65
|
+
used directly through `raw`, exactly as in the example above.
|
|
66
|
+
|
|
67
|
+
The async facade mirrors the sync one method-for-method:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import asyncio
|
|
71
|
+
|
|
72
|
+
from arcadedb_driver_grpc.aio import create_client
|
|
73
|
+
from arcadedb_driver_grpc import messages
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
async def main() -> None:
|
|
77
|
+
async with create_client("localhost:50051", insecure=True) as client:
|
|
78
|
+
response = await client.raw.ExecuteQuery(
|
|
79
|
+
messages.ExecuteQueryRequest(database="mydb", query="SELECT FROM Person WHERE age > 21", language="sql")
|
|
80
|
+
)
|
|
81
|
+
for result in response.results:
|
|
82
|
+
for record in result.records:
|
|
83
|
+
print(record.rid, dict(record.properties))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
asyncio.run(main())
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The two `create_client`s are deliberately two functions rather than one function with a sync/async
|
|
90
|
+
switch: `arcadedb_driver_grpc.create_client` returns `ArcadeDBGrpcClient`, `arcadedb_driver_grpc.aio.create_client`
|
|
91
|
+
returns `AsyncArcadeDBGrpcClient`, and importing from `.aio` is the signal for which one you get.
|
|
92
|
+
|
|
93
|
+
## Authentication, and why `client.raw` is authenticated too
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from arcadedb_driver_grpc import bearer_auth, create_client, password_auth
|
|
97
|
+
|
|
98
|
+
bearer_auth("AU-...") # authorization: Bearer <token>
|
|
99
|
+
password_auth("root", "playwithdata", "mydb") # x-arcade-user / x-arcade-password / x-arcade-database
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Both helpers return an `Auth` value that `create_client` turns into a **channel** interceptor, not
|
|
103
|
+
per-call metadata. That is not a stylistic choice: the top-level client wraps only three things -
|
|
104
|
+
`stream_query`, `insert_stream`, and the three transaction RPCs (`BeginTransaction`,
|
|
105
|
+
`CommitTransaction`, `RollbackTransaction`) that `transaction` manages internally. The six CRUD
|
|
106
|
+
RPCs (`ExecuteQuery`, `ExecuteCommand`, `CreateRecord`, `UpdateRecord`, `DeleteRecord`,
|
|
107
|
+
`LookupByRid`) get a wrapper only once a transaction is open, through `TransactionHandle` /
|
|
108
|
+
`AsyncTransactionHandle` - outside a transaction they reach the server through `raw` directly - and
|
|
109
|
+
`BulkInsert`, `InsertBidirectional`, and `GraphBatchLoad` have no wrapper anywhere, ever. Attaching
|
|
110
|
+
auth as per-call metadata on just the top-level wrappers would leave every one of those other calls
|
|
111
|
+
silently anonymous. Attaching it to the channel instead makes that impossible -
|
|
112
|
+
`client.raw.ExecuteCommand(...)` carries the same headers `client.stream_query(...)` does.
|
|
113
|
+
|
|
114
|
+
**The async side needs four interceptor objects, not one.** `create_client` and
|
|
115
|
+
`aio.create_client` both authenticate via a channel interceptor, but the async facade
|
|
116
|
+
cannot use a single object implementing all four of grpc's client-interceptor protocols
|
|
117
|
+
the way the sync side's `_SyncAuthInterceptor` does. `grpc.aio.Channel.__init__` sorts
|
|
118
|
+
every interceptor it is given into one of four buckets with an `isinstance(...)`/`elif`
|
|
119
|
+
chain and stops at the first match, so a combined object - an instance of all four
|
|
120
|
+
protocol classes at once - lands in only the first bucket (unary-unary) and is never
|
|
121
|
+
invoked for the other three call shapes. `sync_interceptors` is unaffected: the sync
|
|
122
|
+
side's `grpc.intercept_channel` checks all four independently. `async_interceptors`
|
|
123
|
+
therefore returns four separate interceptor objects, one per RPC shape, so that
|
|
124
|
+
`stream_query` (unary-stream), `insert_stream` (stream-unary) and `InsertBidirectional`
|
|
125
|
+
(stream-stream) get authenticated exactly as `ExecuteCommand` (unary-unary) does. A
|
|
126
|
+
single combined object was this module's original shape and passed the whole unit
|
|
127
|
+
suite, because the in-process fake server that suite drives had only ever been
|
|
128
|
+
exercised through a unary-unary call under auth; the gap surfaced only once the async
|
|
129
|
+
facade's transaction and streaming paths were run against a real server (see
|
|
130
|
+
`e2e/test_grpc_aio.py`), where `stream_query` came back `UNAUTHENTICATED` moments after
|
|
131
|
+
`ExecuteCommand`, over the same authenticated client, succeeded.
|
|
132
|
+
|
|
133
|
+
### The insecure-channel guard
|
|
134
|
+
|
|
135
|
+
`password_auth` sends the password in plaintext gRPC metadata, so `create_client` **refuses** to
|
|
136
|
+
pair it with a channel that has no transport credentials, unless you pass `insecure=True`:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
import grpc
|
|
140
|
+
|
|
141
|
+
create_client("localhost:50051", auth=password_auth("root", "playwithdata"))
|
|
142
|
+
# raises InsecureChannelError: refusing to send a plaintext password over an insecure
|
|
143
|
+
# channel to "localhost:50051" ...
|
|
144
|
+
|
|
145
|
+
create_client("localhost:50051", auth=password_auth("root", "playwithdata"), insecure=True)
|
|
146
|
+
# fine - you opted in
|
|
147
|
+
|
|
148
|
+
create_client("localhost:50051", auth=password_auth("root", "playwithdata"), credentials=grpc.ssl_channel_credentials())
|
|
149
|
+
# also fine - the channel is encrypted, so there is nothing to opt into
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The check keys on whether channel `credentials` were supplied, not on parsing `target` for a
|
|
153
|
+
scheme - there is no scheme in gRPC's `host:port` form to parse in the first place, unlike the
|
|
154
|
+
TypeScript sibling, which has to defend against `new URL("localhost:50051").protocol` evaluating
|
|
155
|
+
to `"localhost:"` rather than `"http:"`. A bearer token is not a password and never trips this
|
|
156
|
+
guard, since `bearer_auth` does not set `Auth.sends_plaintext_password`.
|
|
157
|
+
|
|
158
|
+
## Streaming queries: `stream_query`
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
for record in client.stream_query(
|
|
162
|
+
messages.StreamQueryRequest(
|
|
163
|
+
database="mydb",
|
|
164
|
+
query="SELECT FROM Person",
|
|
165
|
+
language="sql",
|
|
166
|
+
retrieval_mode=messages.StreamQueryRequest.RetrievalMode.CURSOR,
|
|
167
|
+
batch_size=500,
|
|
168
|
+
)
|
|
169
|
+
):
|
|
170
|
+
print(record.rid, dict(record.properties))
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
or, on the async facade, `async for record in client.stream_query(...)`.
|
|
174
|
+
|
|
175
|
+
`stream_query` flattens the server's stream of `QueryResult` batches into one `GrpcRecord` at a
|
|
176
|
+
time, so calling code never unwraps `QueryResult.records` itself. That is the *only* thing it
|
|
177
|
+
does: it picks no default for `retrieval_mode` or `batch_size`. The three retrieval modes the
|
|
178
|
+
`.proto` contract defines differ materially in memory and consistency behaviour, and only the
|
|
179
|
+
caller can judge which one a given query needs:
|
|
180
|
+
|
|
181
|
+
- `CURSOR` (proto default `0`) - runs the query once and streams results as you iterate.
|
|
182
|
+
- `MATERIALIZE_ALL` - loads the entire result set on the server first, then emits it in batches.
|
|
183
|
+
- `PAGED` - re-issues the query with `LIMIT`/`SKIP` per batch.
|
|
184
|
+
|
|
185
|
+
Leaving `retrieval_mode` and `batch_size` unset sends the wire zero values for both (`CURSOR`,
|
|
186
|
+
`batch_size=0`, meaning "server chooses") - that is protobuf's own default, not a choice this
|
|
187
|
+
wrapper makes on your behalf.
|
|
188
|
+
|
|
189
|
+
## Streaming inserts: `insert_stream`
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from arcadedb_driver_grpc import InsertStreamRequest, messages
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def rows() -> list[list[messages.GrpcRecord]]:
|
|
196
|
+
return [
|
|
197
|
+
[messages.GrpcRecord(type="Person", properties={"name": messages.GrpcValue(string_value="Alice")})],
|
|
198
|
+
[messages.GrpcRecord(type="Person", properties={"name": messages.GrpcValue(string_value="Bob")})],
|
|
199
|
+
]
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
summary = client.insert_stream(
|
|
203
|
+
InsertStreamRequest(
|
|
204
|
+
database="mydb",
|
|
205
|
+
options=messages.InsertOptions(target_class="Person"),
|
|
206
|
+
chunks=rows(),
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
print(summary.inserted, summary.failed)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`chunks` is an iterable of row batches - one element becomes exactly one wire `InsertChunk`. The
|
|
213
|
+
sync facade accepts a synchronous `Iterable`; the async facade (`arcadedb_driver_grpc.aio`) accepts
|
|
214
|
+
either a synchronous `Iterable` *or* an `AsyncIterable`, so an async caller who already has a plain
|
|
215
|
+
list is not forced to wrap it in an async generator first.
|
|
216
|
+
|
|
217
|
+
The caller decides how rows are batched and when to produce the next batch. `insert_stream` owns
|
|
218
|
+
only the envelope bookkeeping around those batches, which is easy to get wrong by hand:
|
|
219
|
+
|
|
220
|
+
- one `session_id` (a fresh UUID, generated once), stable for the whole stream
|
|
221
|
+
- `chunk_seq` starting at 1 and incrementing by 1 per chunk
|
|
222
|
+
- `database` set on the first chunk only, per the `.proto` contract (`InsertChunk.database` is
|
|
223
|
+
documented `// REQUIRED` there for exactly that chunk)
|
|
224
|
+
- `last=True` on the final chunk only
|
|
225
|
+
|
|
226
|
+
**The `options.database` mirror.** `insert_stream` also sets `options.database` to the same value
|
|
227
|
+
as the first chunk's `database`. This is a compatibility workaround, established empirically
|
|
228
|
+
against a real server: on ArcadeDB 26.9.1 and every earlier release, the server builds its
|
|
229
|
+
`InsertContext` from `InsertOptions.database` **alone** and never reads `InsertChunk.database` at
|
|
230
|
+
all, despite the `.proto` documenting the latter as required. Without this mirror, every stream
|
|
231
|
+
against such a server fails at the deferred commit with `Invalid database name: name is required`
|
|
232
|
+
- even though `database` was sent exactly as the contract specifies. A server carrying the fix for
|
|
233
|
+
[ArcadeData/arcadedb#6597](https://github.com/ArcadeData/arcadedb/issues/6597) prefers a non-empty
|
|
234
|
+
`InsertChunk.database` and falls back to `InsertOptions.database`, so setting both to the same
|
|
235
|
+
value is correct on either side of that fix and safe to keep sending once it ships.
|
|
236
|
+
|
|
237
|
+
**An empty stream is not an error.** A caller whose row source produces zero batches (a filter
|
|
238
|
+
that matched nothing, say) gets a single wire chunk with zero rows and `last=True`, and whatever
|
|
239
|
+
`InsertSummary` the server answers for it - not an exception and not an invented result. A filter
|
|
240
|
+
matching nothing is a legitimate outcome, and turning it into an error would be the wrong failure
|
|
241
|
+
mode for the common case of "there was nothing to insert this time."
|
|
242
|
+
|
|
243
|
+
`insert_stream` is **not** available on a `TransactionHandle` - see below.
|
|
244
|
+
|
|
245
|
+
## Transactions: `transaction`
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
with client.transaction("mydb") as tx:
|
|
249
|
+
tx.execute_command(messages.ExecuteCommandRequest(command="INSERT INTO Account SET balance = 100", language="sql"))
|
|
250
|
+
response = tx.execute_query(
|
|
251
|
+
messages.ExecuteQueryRequest(query="SELECT sum(balance) as total FROM Account", language="sql")
|
|
252
|
+
)
|
|
253
|
+
total = response.results[0].records[0]
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
or, async:
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
async with client.transaction("mydb") as tx:
|
|
260
|
+
await tx.execute_command(
|
|
261
|
+
messages.ExecuteCommandRequest(command="INSERT INTO Account SET balance = 100", language="sql")
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
`transaction(database)` returns a context manager whose `__enter__`/`__aenter__` begins a
|
|
266
|
+
server-side transaction (`BeginTransaction`) and hands back a `TransactionHandle` /
|
|
267
|
+
`AsyncTransactionHandle` - a second object, distinct from the client itself. Every call made
|
|
268
|
+
through that handle (`execute_query`, `execute_command`, `create_record`, `update_record`,
|
|
269
|
+
`delete_record`, `lookup_by_rid`, `stream_query`) carries the transaction's id; a call made
|
|
270
|
+
through the outer `client` while the transaction is open does **not** take part in it, the same
|
|
271
|
+
distinction `arcadedb-driver`'s `Transaction` documents for its second database handle.
|
|
272
|
+
|
|
273
|
+
This is spelled as a context manager - `with client.transaction("db") as tx:` - rather than a
|
|
274
|
+
callback taking a function, specifically so a caller moving between `arcadedb-driver` (HTTP) and
|
|
275
|
+
this package does not have to relearn the shape; the TypeScript sibling instead spells this
|
|
276
|
+
`grpc.transaction(database, async (tx) => { ... })`, because Connect-ES has no equivalent
|
|
277
|
+
convention to match.
|
|
278
|
+
|
|
279
|
+
**The binding override.** `TransactionHandle._bind` forces `database` and `transaction` onto every
|
|
280
|
+
request the handle sends, overriding whatever the caller supplied - including a transaction id or
|
|
281
|
+
database name set on the request object before it reached the handle. This override *is* the
|
|
282
|
+
safety mechanism, not an incidental detail: it is what makes transaction hijack, silent data loss,
|
|
283
|
+
and leaked transactions (filed against ad hoc transaction code as ArcadeData/arcadedb#5040 through
|
|
284
|
+
#5042) unrepeatable through this handle. A request that arrived naming another database, or
|
|
285
|
+
carrying another transaction's id, leaves the handle naming this transaction's database and id
|
|
286
|
+
instead.
|
|
287
|
+
|
|
288
|
+
The binding happens on a **copy**: the request object you passed in comes back unchanged. That
|
|
289
|
+
matters because the alternative reintroduces #5040 by aliasing - a request bound in place would
|
|
290
|
+
keep the handle's `database` and a now-committed transaction's id after the block ended, and
|
|
291
|
+
reusing it (through `client.raw`, or in a later transaction before `_bind` ran) would send that
|
|
292
|
+
dead id to the server.
|
|
293
|
+
|
|
294
|
+
**The commit-flag check.** On a clean exit, `transaction` calls `CommitTransaction` and checks the
|
|
295
|
+
response's `committed` field - not `success`. A transaction id the server no longer recognises
|
|
296
|
+
(for example, one already reaped past `arcadedb.server.httpTxExpireTimeout`) answers
|
|
297
|
+
`success=true, committed=false`, with no error status at all. Trusting `success` alone would report
|
|
298
|
+
the commit as having gone through while silently losing every write the transaction made; checking
|
|
299
|
+
`committed` instead raises `RuntimeError` (including the server's own message) so that failure
|
|
300
|
+
cannot pass unnoticed. The same check exists on both facades. `BeginTransaction`'s response is
|
|
301
|
+
checked the same way: a missing or blank `transaction_id` raises immediately, before the block
|
|
302
|
+
runs, rather than handing back a handle that would silently auto-commit every call outside any
|
|
303
|
+
real transaction.
|
|
304
|
+
|
|
305
|
+
On any other exit - the block raises - the transaction rolls back and the block's own exception
|
|
306
|
+
propagates; a rollback failure attaches as `__cause__` rather than replacing it. If the commit
|
|
307
|
+
call itself raises, a best-effort rollback is attempted first (its own failure discarded) so the
|
|
308
|
+
server-side transaction is not left open until it is reaped, and then the commit's error
|
|
309
|
+
propagates.
|
|
310
|
+
|
|
311
|
+
**`insert_stream` and `bulk_insert` are not on `TransactionHandle`.** On this server,
|
|
312
|
+
`ArcadeDbGrpcService#insertStream` and `#bulkInsert` never read a request's `TransactionContext` -
|
|
313
|
+
each builds its own `InsertContext`, resolves its own database, and commits independently,
|
|
314
|
+
regardless of any `BeginTransaction`/`CommitTransaction`/`RollbackTransaction` issued around it.
|
|
315
|
+
Adding them to `TransactionHandle` would silently misrepresent this: their writes would not
|
|
316
|
+
actually be part of the transaction, would commit even if the transaction's body raised, and would
|
|
317
|
+
survive a rollback. Both remain reachable outside a transaction - `client.insert_stream(...)` and
|
|
318
|
+
`client.raw.BulkInsert(...)` - but never through `tx`. See
|
|
319
|
+
[ArcadeData/arcadedb#6607](https://github.com/ArcadeData/arcadedb/issues/6607), filed against this
|
|
320
|
+
gap; this restriction is removable once that lands server-side.
|
|
321
|
+
|
|
322
|
+
## Errors: `grpc.RpcError`, not a package-specific error
|
|
323
|
+
|
|
324
|
+
A failed call raises `grpc.RpcError` (sync) or `grpc.aio.AioRpcError` (async) directly - this
|
|
325
|
+
package does not wrap it in a package-specific exception:
|
|
326
|
+
|
|
327
|
+
```python
|
|
328
|
+
import grpc
|
|
329
|
+
|
|
330
|
+
try:
|
|
331
|
+
client.raw.ExecuteQuery(messages.ExecuteQueryRequest(database="mydb", query="SELECT FROM NoSuchType"))
|
|
332
|
+
except grpc.RpcError as err:
|
|
333
|
+
print(err.code(), err.details())
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
This is the same asymmetry `python/CLAUDE.md` documents for the TypeScript sibling's
|
|
337
|
+
`ConnectError` versus `@arcadedb/driver`'s `ArcadeDBError`, and is deliberate rather than an
|
|
338
|
+
oversight to fix later. `arcadedb-driver` (the HTTP client) needs its own error type because the
|
|
339
|
+
HTTP contract answers `200` with a body that may itself describe a failure - there is an envelope
|
|
340
|
+
to unwrap, and `_internal/unwrap.py` is what unwraps it. gRPC has no equivalent shape: a failed
|
|
341
|
+
call is a failed call at the transport level, carried as a status code and a details string, and
|
|
342
|
+
there is nothing this package's own type could add by standing between the caller and
|
|
343
|
+
`grpc.RpcError`.
|
|
344
|
+
|
|
345
|
+
## Async-specific hazards
|
|
346
|
+
|
|
347
|
+
Two behaviours below were settled deliberately during implementation rather than fixed as bugs.
|
|
348
|
+
Both are documented at length in the code itself; this section summarizes them.
|
|
349
|
+
|
|
350
|
+
**Cancelling a transaction body DOES roll back; cancelling it twice does not.** The obvious
|
|
351
|
+
reading - that `asyncio.CancelledError` inherits from `BaseException` rather than `Exception` and
|
|
352
|
+
so slips past `__aexit__` - is wrong, and this README said it for a while. `__aexit__`'s guard is
|
|
353
|
+
`if exc is not None`, not an `isinstance(exc, Exception)` test, so a cancelled body takes the
|
|
354
|
+
rollback branch like any other failure; and after a single `task.cancel()` the `CancelledError` has
|
|
355
|
+
already been delivered and the task's `_must_cancel` flag cleared, so the `await` inside the
|
|
356
|
+
rollback does not immediately re-raise. `test_cancelling_the_body_still_rolls_back` asserts the
|
|
357
|
+
server saw exactly `BeginTransaction`, `RollbackTransaction`.
|
|
358
|
+
|
|
359
|
+
The real limitation is narrower. A **second** cancellation, landing while that rollback is still in
|
|
360
|
+
flight, is raised at the `await` and escapes `__aexit__` uncaught - replacing whatever the body
|
|
361
|
+
raised, and leaving the transaction open on the server until
|
|
362
|
+
`arcadedb.server.httpTxExpireTimeout` reaps it, the leaked-transaction shape
|
|
363
|
+
(ArcadeData/arcadedb#5042) this package otherwise exists to prevent. `_safe_rollback`, on the
|
|
364
|
+
commit-failure path, has the same gap in a smaller form: its `contextlib.suppress(Exception)`
|
|
365
|
+
genuinely does not cover `CancelledError`, so a cancellation there replaces the commit error the
|
|
366
|
+
caller was meant to see.
|
|
367
|
+
|
|
368
|
+
This is accepted rather than silently overlooked: a real fix (a shielded rollback via
|
|
369
|
+
`asyncio.shield`, say) trades a reaped transaction for a task that can hang against an unresponsive
|
|
370
|
+
server, which is a design decision for this repository's owner, not something to settle
|
|
371
|
+
unilaterally. A caller who needs the rollback to be certain even under repeated cancellation should
|
|
372
|
+
issue it themselves rather than rely on this context manager.
|
|
373
|
+
|
|
374
|
+
**`insert_stream`'s close-forwarding is best-effort.** When the async facade abandons an
|
|
375
|
+
in-progress `chunks` source early - the RPC aborts mid-stream, or nothing pulls the rest - it tries
|
|
376
|
+
to forward that closure to the caller's source, so a generator wrapping a file handle or a
|
|
377
|
+
database cursor gets its `finally` block run. It forwards to the **iterator** it is actually
|
|
378
|
+
driving (`iter(chunks)` / `chunks.__aiter__()`), not to the `Iterable`/`AsyncIterable` it was
|
|
379
|
+
handed: for a bare generator the two are the same object, but for a class whose `__aiter__` is an
|
|
380
|
+
async generator function they are not, and closing the wrong one forwards the close to nothing.
|
|
381
|
+
That forwarding then calls `close()`/`aclose()` via `getattr`, because an arbitrary `Iterable` or
|
|
382
|
+
`AsyncIterable` is not required to have either - only generators are. A caller-supplied iterator
|
|
383
|
+
with its own cleanup protocol that is *not* a generator (no `close`/`aclose` method) gets no
|
|
384
|
+
forwarded close at all; this package cannot invent a protocol the object does not already
|
|
385
|
+
implement.
|
|
386
|
+
|
|
387
|
+
## Contract version and compatibility
|
|
388
|
+
|
|
389
|
+
This package was generated from `contracts/arcadedb-server-26.9.1.proto`, recorded in
|
|
390
|
+
`pyproject.toml` as `tool.arcadedb.server-version`:
|
|
391
|
+
|
|
392
|
+
```toml
|
|
393
|
+
[tool.arcadedb]
|
|
394
|
+
server-version = "26.9.1"
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
| `arcadedb-driver-grpc` | ArcadeDB server |
|
|
398
|
+
| --- | --- |
|
|
399
|
+
| 0.1.0 | 26.9.1 |
|
|
400
|
+
|
|
401
|
+
This table is a historical record tied to a package version, not something derived
|
|
402
|
+
automatically: `scripts/adopt-contract-version.sh` deliberately does not touch it when it retires
|
|
403
|
+
an old contract and adopts a new one. Adding a row is a human decision made at release time, not a
|
|
404
|
+
side effect of a contract bump.
|
|
405
|
+
|
|
406
|
+
The client speaks ArcadeDB's gRPC data plane as described by that contract. Pointing it at a
|
|
407
|
+
server on a materially different release may work for the RPCs both versions share, but is not
|
|
408
|
+
tested or supported.
|
|
409
|
+
|
|
410
|
+
## License
|
|
411
|
+
|
|
412
|
+
Apache-2.0.
|