particledb 0.2.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 (77) hide show
  1. particledb-0.2.0/LICENSE +21 -0
  2. particledb-0.2.0/PKG-INFO +211 -0
  3. particledb-0.2.0/README.md +169 -0
  4. particledb-0.2.0/particledb/__init__.py +138 -0
  5. particledb-0.2.0/particledb/__main__.py +50 -0
  6. particledb-0.2.0/particledb/_arrow.py +1122 -0
  7. particledb-0.2.0/particledb/_bulkdata.py +203 -0
  8. particledb-0.2.0/particledb/_collect.py +285 -0
  9. particledb-0.2.0/particledb/_dsn.py +18 -0
  10. particledb-0.2.0/particledb/_frames.py +258 -0
  11. particledb-0.2.0/particledb/_protocol.py +904 -0
  12. particledb-0.2.0/particledb/_tls.py +110 -0
  13. particledb-0.2.0/particledb/ai.py +709 -0
  14. particledb-0.2.0/particledb/aio/__init__.py +51 -0
  15. particledb-0.2.0/particledb/aio/_connection.py +421 -0
  16. particledb-0.2.0/particledb/aio/_cursor.py +462 -0
  17. particledb-0.2.0/particledb/aio/_pool.py +203 -0
  18. particledb-0.2.0/particledb/aio/_wire.py +889 -0
  19. particledb-0.2.0/particledb/arrow_ipc.py +412 -0
  20. particledb-0.2.0/particledb/client.py +890 -0
  21. particledb-0.2.0/particledb/connection.py +1894 -0
  22. particledb-0.2.0/particledb/dbapi/__init__.py +72 -0
  23. particledb-0.2.0/particledb/dbapi/_adapt.py +109 -0
  24. particledb-0.2.0/particledb/dbapi/_connection.py +582 -0
  25. particledb-0.2.0/particledb/dbapi/_cursor.py +581 -0
  26. particledb-0.2.0/particledb/dbapi/_literal.py +182 -0
  27. particledb-0.2.0/particledb/dbapi/_result.py +278 -0
  28. particledb-0.2.0/particledb/dbapi/_sql.py +373 -0
  29. particledb-0.2.0/particledb/dbapi/_types.py +252 -0
  30. particledb-0.2.0/particledb/dbapi/errors.py +219 -0
  31. particledb-0.2.0/particledb/dbapi/rows.py +81 -0
  32. particledb-0.2.0/particledb/errors.py +140 -0
  33. particledb-0.2.0/particledb/grpc_client.py +583 -0
  34. particledb-0.2.0/particledb/kv.py +200 -0
  35. particledb-0.2.0/particledb/ops.py +582 -0
  36. particledb-0.2.0/particledb/particles.py +222 -0
  37. particledb-0.2.0/particledb/pdb_wire.py +727 -0
  38. particledb-0.2.0/particledb/rag.py +206 -0
  39. particledb-0.2.0/particledb/sqlalchemy/__init__.py +10 -0
  40. particledb-0.2.0/particledb/sqlalchemy/base.py +477 -0
  41. particledb-0.2.0/particledb/sqlalchemy/provision.py +89 -0
  42. particledb-0.2.0/particledb/sqlalchemy/reflection.py +487 -0
  43. particledb-0.2.0/particledb/sqlalchemy/requirements.py +276 -0
  44. particledb-0.2.0/particledb/vector.py +169 -0
  45. particledb-0.2.0/particledb.egg-info/PKG-INFO +211 -0
  46. particledb-0.2.0/particledb.egg-info/SOURCES.txt +75 -0
  47. particledb-0.2.0/particledb.egg-info/dependency_links.txt +1 -0
  48. particledb-0.2.0/particledb.egg-info/entry_points.txt +3 -0
  49. particledb-0.2.0/particledb.egg-info/requires.txt +25 -0
  50. particledb-0.2.0/particledb.egg-info/top_level.txt +1 -0
  51. particledb-0.2.0/pyproject.toml +52 -0
  52. particledb-0.2.0/setup.cfg +4 -0
  53. particledb-0.2.0/tests/test_aio_live.py +367 -0
  54. particledb-0.2.0/tests/test_ambiguous_failures.py +177 -0
  55. particledb-0.2.0/tests/test_arrow_decoder.py +232 -0
  56. particledb-0.2.0/tests/test_auth_live.py +17 -0
  57. particledb-0.2.0/tests/test_client_rest.py +193 -0
  58. particledb-0.2.0/tests/test_connection.py +758 -0
  59. particledb-0.2.0/tests/test_dbapi_differential_live.py +293 -0
  60. particledb-0.2.0/tests/test_dbapi_live.py +636 -0
  61. particledb-0.2.0/tests/test_dbapi_unit.py +284 -0
  62. particledb-0.2.0/tests/test_default_negotiation_live.py +141 -0
  63. particledb-0.2.0/tests/test_frames_live.py +238 -0
  64. particledb-0.2.0/tests/test_helpers_live.py +28 -0
  65. particledb-0.2.0/tests/test_native_batch_errors.py +103 -0
  66. particledb-0.2.0/tests/test_native_live.py +247 -0
  67. particledb-0.2.0/tests/test_native_params.py +232 -0
  68. particledb-0.2.0/tests/test_native_regress_live.py +110 -0
  69. particledb-0.2.0/tests/test_ops_namespace.py +97 -0
  70. particledb-0.2.0/tests/test_particles.py +317 -0
  71. particledb-0.2.0/tests/test_pdb_wire.py +316 -0
  72. particledb-0.2.0/tests/test_peak_memory.py +51 -0
  73. particledb-0.2.0/tests/test_protocol.py +270 -0
  74. particledb-0.2.0/tests/test_tls.py +88 -0
  75. particledb-0.2.0/tests/test_unix_socket.py +123 -0
  76. particledb-0.2.0/tests/test_v2_live.py +182 -0
  77. particledb-0.2.0/tests/test_write_timeout.py +57 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ParticleDB, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.4
2
+ Name: particledb
3
+ Version: 0.2.0
4
+ Summary: Python SDK for ParticleDB: native wire, DB-API 2.0, asyncio, SQLAlchemy, DataFrames, KV, vector search and RAG
5
+ Author: ParticleDB Authors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://particledb.ai
8
+ Project-URL: Documentation, https://particledb.ai/sdks/python/
9
+ Keywords: particledb,database,sql,vector,rag,kv
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Database
18
+ Classifier: Topic :: Database :: Front-Ends
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Provides-Extra: grpc
23
+ Requires-Dist: grpcio>=1.84.1; extra == "grpc"
24
+ Requires-Dist: protobuf>=6.33.6; extra == "grpc"
25
+ Provides-Extra: arrow
26
+ Requires-Dist: pyarrow>=12; extra == "arrow"
27
+ Provides-Extra: pandas
28
+ Requires-Dist: pandas>=1.5; extra == "pandas"
29
+ Requires-Dist: pyarrow>=12; extra == "pandas"
30
+ Provides-Extra: polars
31
+ Requires-Dist: polars>=0.20; extra == "polars"
32
+ Provides-Extra: sqlalchemy
33
+ Requires-Dist: SQLAlchemy>=2.0; extra == "sqlalchemy"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest; extra == "dev"
36
+ Requires-Dist: pyarrow>=12; extra == "dev"
37
+ Requires-Dist: pandas>=1.5; extra == "dev"
38
+ Requires-Dist: polars>=0.20; extra == "dev"
39
+ Requires-Dist: SQLAlchemy>=2.0; extra == "dev"
40
+ Requires-Dist: psycopg[binary]>=3.1; extra == "dev"
41
+ Dynamic: license-file
42
+
43
+ # ParticleDB for Python
44
+
45
+ ```python
46
+ import particledb
47
+
48
+ with particledb.connect() as db:
49
+ db.kv_set(b"session:123", b"active")
50
+ assert db.kv_get(b"session:123") == b"active"
51
+ ```
52
+
53
+ ## Start a local server
54
+
55
+ A server started without options requires authentication but has no password
56
+ set, so start it in one of these two ways. For local development on a trusted
57
+ machine, turn authentication off and keep every listener on loopback:
58
+
59
+ ```sh
60
+ particledb start --no-auth --data-dir ./pdb-dev \
61
+ --http-addr 127.0.0.1:7173 --pg-addr 127.0.0.1:5432
62
+ ```
63
+
64
+ To require a password, create the login role from the command line. The
65
+ password file holds only the password; keep it readable by you alone.
66
+ SCRAM authenticates without TLS; use TLS for remote access.
67
+
68
+ ```sh
69
+ particledb start --data-dir ./pdb-dev \
70
+ --http-addr 127.0.0.1:7173 --pg-addr 127.0.0.1:5432 \
71
+ --auth-method scram-sha-256 --pg-username app --pg-password-file ./pdb-password
72
+ ```
73
+
74
+ The SDK connects to `localhost:7173` by default. With authentication on,
75
+ pass the same user and password:
76
+
77
+ ```python
78
+ import os
79
+ import particledb
80
+
81
+ with particledb.connect(user="app", password=os.environ["PARTICLEDB_PASSWORD"]) as db:
82
+ assert db.scalar("SELECT 42") == 42
83
+ ```
84
+
85
+ The default address is `localhost:7173`. Core queries, transactions and
86
+ streaming use the standard library. Python 3.11 or newer is required.
87
+
88
+ ## Install the release build
89
+
90
+ This release is not published to PyPI yet. Build a wheel with
91
+ `python -m build` from this directory and install the resulting
92
+ `particledb-0.2.0-py3-none-any.whl` in your application. Optional extras
93
+ are `arrow`, `pandas`, `polars`, `sqlalchemy` and `grpc`. See
94
+ [Python SDK documentation](https://particledb.ai/sdks/python/) for the matching server.
95
+
96
+ ## Remote connections
97
+
98
+ ```python
99
+ import os
100
+ import particledb
101
+
102
+ with particledb.connect(
103
+ host="db.example.com",
104
+ user="app",
105
+ password=os.environ["PARTICLEDB_PASSWORD"],
106
+ sslmode="verify-full",
107
+ sslrootcert="ca.pem",
108
+ ) as db:
109
+ print(db.scalar("SELECT 42"))
110
+ ```
111
+
112
+ `verify-full` checks the certificate and hostname. Omit `sslrootcert` to use
113
+ system roots. TLS uses TCP and refuses plaintext fallback. `sslcert` and
114
+ `sslkey` accept PEM client certificate and key paths. `require` encrypts
115
+ without hostname verification; use `verify-full` for verified remote access.
116
+
117
+ ## Queries and transactions
118
+
119
+ ```python
120
+ with particledb.connect() as db:
121
+ db.execute("CREATE TABLE items (id BIGINT PRIMARY KEY, name TEXT)")
122
+ db.execute("INSERT INTO items VALUES ($1, $2)", [1, "first"])
123
+ assert db.query("SELECT name FROM items WHERE id = $1", [1]) == [{"name": "first"}]
124
+ with db.transaction() as tx:
125
+ tx.execute("UPDATE items SET name = $1 WHERE id = $2", ["updated", 1])
126
+ ```
127
+
128
+ Parameters are bound separately from SQL. The transaction context commits
129
+ on successful exit and rolls back on an exception. SQL failures include
130
+ SQLSTATE; transport failures do not replay a request that may have run.
131
+ Synchronous `write_timeout` defaults to 30 seconds and bounds socket writes
132
+ and waits for another writer. A write timeout closes the connection because
133
+ the request outcome may be unknown. Set it to `None` for an unlimited wait.
134
+ `statement_timeout` separately bounds response waits and server cancellation.
135
+
136
+ Malformed connection URLs raise `ValueError` in the native API and
137
+ `InterfaceError` in DB-API and asyncio. Error messages omit the connection
138
+ string and do not chain the original URL parser exception.
139
+
140
+ Use `stream(sql, parameters)` for bounded row iteration and close an iterator
141
+ early when abandoning a result.
142
+
143
+ Values decode to Python `int`, `float`, `bool`, `str`, `bytes`, `Decimal`,
144
+ `date`, `time`, `datetime`, `UUID`, lists and dictionaries. SQL NULL is `None`.
145
+ Decimals preserve their scale. Aware datetimes represent instants; naive
146
+ datetimes represent timestamps without a time zone.
147
+
148
+ ## DB-API and asyncio
149
+
150
+ ```python
151
+ from particledb import dbapi
152
+
153
+ with dbapi.connect() as db:
154
+ with db.cursor() as cursor:
155
+ cursor.execute("SELECT %s AS answer", (42,))
156
+ assert cursor.fetchone() == (42,)
157
+ ```
158
+
159
+ The DB-API defaults to `%s` parameters. Its connection context manages a
160
+ transaction. Use `autocommit=True` for one transaction per statement.
161
+ Cursors provide `fetchone`, `fetchmany`, `fetchall`, `description` and
162
+ `executemany`. A named cursor streams in bounded memory.
163
+
164
+ ```python
165
+ from particledb import aio
166
+
167
+ async def read_answer():
168
+ async with await aio.connect() as db:
169
+ async with db.cursor() as cursor:
170
+ await cursor.execute("SELECT %s AS answer", (42,))
171
+ return await cursor.fetchone()
172
+ ```
173
+
174
+ The async API follows the DB-API shapes with awaited I/O and async context
175
+ managers. Cancellation is sent to the server. A connection is reused only
176
+ when the server confirms the statement's outcome; otherwise it is closed.
177
+ Do not share an open transaction between unrelated tasks.
178
+
179
+ ## DataFrames and SQLAlchemy
180
+
181
+ Install the corresponding optional extra. DB-API cursors provide
182
+ `fetch_arrow`, `fetch_df`, `fetch_polars` and `fetch_numpy`.
183
+ `bulk_insert(table, rows)` accepts supported tuples, mappings, generators
184
+ and DataFrames. Use a transaction for an all-or-nothing application operation.
185
+
186
+ ```python
187
+ from sqlalchemy import create_engine, text
188
+
189
+ engine = create_engine("particledb+native://localhost:7173")
190
+ with engine.connect() as db:
191
+ assert db.execute(text("SELECT :answer"), {"answer": 42}).scalar() == 42
192
+ engine.dispose()
193
+ ```
194
+
195
+ The dialect supports parameterized SQLAlchemy Core statements, transactions,
196
+ reflection and streaming. See [SUPPORT.md](SUPPORT.md) for tested behavior,
197
+ server limitations and the separate compliance suite.
198
+
199
+ ## Validate
200
+
201
+ ```sh
202
+ PDB_NATIVE_PORT=PORT PDB_TLS_PORT=TLS_PORT PDB_TLS_CA=ca.pem \
203
+ PDB_PG_DSN=postgresql://user@localhost:PG_PORT/sdk_python \
204
+ python -m pytest -q -ra
205
+ ```
206
+
207
+ Use disposable databases. Live tests require the named listeners. SQLAlchemy
208
+ compliance runs separately against a fresh server directory; it is not part
209
+ of a plain `pytest` invocation. See [Python SDK documentation](https://particledb.ai/sdks/python/).
210
+
211
+ MIT licensed. See [LICENSE](LICENSE).
@@ -0,0 +1,169 @@
1
+ # ParticleDB for Python
2
+
3
+ ```python
4
+ import particledb
5
+
6
+ with particledb.connect() as db:
7
+ db.kv_set(b"session:123", b"active")
8
+ assert db.kv_get(b"session:123") == b"active"
9
+ ```
10
+
11
+ ## Start a local server
12
+
13
+ A server started without options requires authentication but has no password
14
+ set, so start it in one of these two ways. For local development on a trusted
15
+ machine, turn authentication off and keep every listener on loopback:
16
+
17
+ ```sh
18
+ particledb start --no-auth --data-dir ./pdb-dev \
19
+ --http-addr 127.0.0.1:7173 --pg-addr 127.0.0.1:5432
20
+ ```
21
+
22
+ To require a password, create the login role from the command line. The
23
+ password file holds only the password; keep it readable by you alone.
24
+ SCRAM authenticates without TLS; use TLS for remote access.
25
+
26
+ ```sh
27
+ particledb start --data-dir ./pdb-dev \
28
+ --http-addr 127.0.0.1:7173 --pg-addr 127.0.0.1:5432 \
29
+ --auth-method scram-sha-256 --pg-username app --pg-password-file ./pdb-password
30
+ ```
31
+
32
+ The SDK connects to `localhost:7173` by default. With authentication on,
33
+ pass the same user and password:
34
+
35
+ ```python
36
+ import os
37
+ import particledb
38
+
39
+ with particledb.connect(user="app", password=os.environ["PARTICLEDB_PASSWORD"]) as db:
40
+ assert db.scalar("SELECT 42") == 42
41
+ ```
42
+
43
+ The default address is `localhost:7173`. Core queries, transactions and
44
+ streaming use the standard library. Python 3.11 or newer is required.
45
+
46
+ ## Install the release build
47
+
48
+ This release is not published to PyPI yet. Build a wheel with
49
+ `python -m build` from this directory and install the resulting
50
+ `particledb-0.2.0-py3-none-any.whl` in your application. Optional extras
51
+ are `arrow`, `pandas`, `polars`, `sqlalchemy` and `grpc`. See
52
+ [Python SDK documentation](https://particledb.ai/sdks/python/) for the matching server.
53
+
54
+ ## Remote connections
55
+
56
+ ```python
57
+ import os
58
+ import particledb
59
+
60
+ with particledb.connect(
61
+ host="db.example.com",
62
+ user="app",
63
+ password=os.environ["PARTICLEDB_PASSWORD"],
64
+ sslmode="verify-full",
65
+ sslrootcert="ca.pem",
66
+ ) as db:
67
+ print(db.scalar("SELECT 42"))
68
+ ```
69
+
70
+ `verify-full` checks the certificate and hostname. Omit `sslrootcert` to use
71
+ system roots. TLS uses TCP and refuses plaintext fallback. `sslcert` and
72
+ `sslkey` accept PEM client certificate and key paths. `require` encrypts
73
+ without hostname verification; use `verify-full` for verified remote access.
74
+
75
+ ## Queries and transactions
76
+
77
+ ```python
78
+ with particledb.connect() as db:
79
+ db.execute("CREATE TABLE items (id BIGINT PRIMARY KEY, name TEXT)")
80
+ db.execute("INSERT INTO items VALUES ($1, $2)", [1, "first"])
81
+ assert db.query("SELECT name FROM items WHERE id = $1", [1]) == [{"name": "first"}]
82
+ with db.transaction() as tx:
83
+ tx.execute("UPDATE items SET name = $1 WHERE id = $2", ["updated", 1])
84
+ ```
85
+
86
+ Parameters are bound separately from SQL. The transaction context commits
87
+ on successful exit and rolls back on an exception. SQL failures include
88
+ SQLSTATE; transport failures do not replay a request that may have run.
89
+ Synchronous `write_timeout` defaults to 30 seconds and bounds socket writes
90
+ and waits for another writer. A write timeout closes the connection because
91
+ the request outcome may be unknown. Set it to `None` for an unlimited wait.
92
+ `statement_timeout` separately bounds response waits and server cancellation.
93
+
94
+ Malformed connection URLs raise `ValueError` in the native API and
95
+ `InterfaceError` in DB-API and asyncio. Error messages omit the connection
96
+ string and do not chain the original URL parser exception.
97
+
98
+ Use `stream(sql, parameters)` for bounded row iteration and close an iterator
99
+ early when abandoning a result.
100
+
101
+ Values decode to Python `int`, `float`, `bool`, `str`, `bytes`, `Decimal`,
102
+ `date`, `time`, `datetime`, `UUID`, lists and dictionaries. SQL NULL is `None`.
103
+ Decimals preserve their scale. Aware datetimes represent instants; naive
104
+ datetimes represent timestamps without a time zone.
105
+
106
+ ## DB-API and asyncio
107
+
108
+ ```python
109
+ from particledb import dbapi
110
+
111
+ with dbapi.connect() as db:
112
+ with db.cursor() as cursor:
113
+ cursor.execute("SELECT %s AS answer", (42,))
114
+ assert cursor.fetchone() == (42,)
115
+ ```
116
+
117
+ The DB-API defaults to `%s` parameters. Its connection context manages a
118
+ transaction. Use `autocommit=True` for one transaction per statement.
119
+ Cursors provide `fetchone`, `fetchmany`, `fetchall`, `description` and
120
+ `executemany`. A named cursor streams in bounded memory.
121
+
122
+ ```python
123
+ from particledb import aio
124
+
125
+ async def read_answer():
126
+ async with await aio.connect() as db:
127
+ async with db.cursor() as cursor:
128
+ await cursor.execute("SELECT %s AS answer", (42,))
129
+ return await cursor.fetchone()
130
+ ```
131
+
132
+ The async API follows the DB-API shapes with awaited I/O and async context
133
+ managers. Cancellation is sent to the server. A connection is reused only
134
+ when the server confirms the statement's outcome; otherwise it is closed.
135
+ Do not share an open transaction between unrelated tasks.
136
+
137
+ ## DataFrames and SQLAlchemy
138
+
139
+ Install the corresponding optional extra. DB-API cursors provide
140
+ `fetch_arrow`, `fetch_df`, `fetch_polars` and `fetch_numpy`.
141
+ `bulk_insert(table, rows)` accepts supported tuples, mappings, generators
142
+ and DataFrames. Use a transaction for an all-or-nothing application operation.
143
+
144
+ ```python
145
+ from sqlalchemy import create_engine, text
146
+
147
+ engine = create_engine("particledb+native://localhost:7173")
148
+ with engine.connect() as db:
149
+ assert db.execute(text("SELECT :answer"), {"answer": 42}).scalar() == 42
150
+ engine.dispose()
151
+ ```
152
+
153
+ The dialect supports parameterized SQLAlchemy Core statements, transactions,
154
+ reflection and streaming. See [SUPPORT.md](SUPPORT.md) for tested behavior,
155
+ server limitations and the separate compliance suite.
156
+
157
+ ## Validate
158
+
159
+ ```sh
160
+ PDB_NATIVE_PORT=PORT PDB_TLS_PORT=TLS_PORT PDB_TLS_CA=ca.pem \
161
+ PDB_PG_DSN=postgresql://user@localhost:PG_PORT/sdk_python \
162
+ python -m pytest -q -ra
163
+ ```
164
+
165
+ Use disposable databases. Live tests require the named listeners. SQLAlchemy
166
+ compliance runs separately against a fresh server directory; it is not part
167
+ of a plain `pytest` invocation. See [Python SDK documentation](https://particledb.ai/sdks/python/).
168
+
169
+ MIT licensed. See [LICENSE](LICENSE).
@@ -0,0 +1,138 @@
1
+ """ParticleDB Python SDK.
2
+
3
+ The default is the PDB native wire in its most efficient mode: protocol 2
4
+ (multiplexed), typed server-side prepared statements, Arrow results decoded
5
+ without any third-party package (pyarrow is optional: ``query_arrow()`` tables).
6
+
7
+ Basic usage::
8
+
9
+ import particledb
10
+
11
+ conn = particledb.connect() # localhost, native v2
12
+ conn.execute("CREATE TABLE users (id BIGINT PRIMARY KEY, name TEXT)")
13
+ conn.execute("INSERT INTO users VALUES ($1, $2)", [1, "alice"])
14
+ rows = conn.query("SELECT * FROM users WHERE id = $1", [1])
15
+ for row in conn.stream("SELECT * FROM big_table"): # bounded memory
16
+ ...
17
+
18
+ db = particledb.ParticleDB() # pooled facade, same wire
19
+ db.execute_many("INSERT INTO users VALUES ($1, $2)",
20
+ [(i, f"u{i}") for i in range(2, 10_000)])
21
+ with db.transaction() as tx:
22
+ tx.execute("UPDATE users SET name = $1 WHERE id = $2", ["bob", 1])
23
+
24
+ A :class:`Connection` is thread-safe: many threads may run statements on it
25
+ at once, each on its own stream. With gRPC (``pip install particledb[grpc]``)::
26
+
27
+ from particledb import GrpcClient
28
+ """
29
+
30
+ from particledb.client import (
31
+ ParticleDB,
32
+ ParticleDBBatchError,
33
+ ParticleDBError,
34
+ QueryResult,
35
+ _WireAdapter,
36
+ )
37
+ from particledb.kv import KV
38
+ from particledb.vector import Vector
39
+ from particledb.rag import RAG
40
+ from particledb.ai import AI
41
+ from particledb.ops import Ops
42
+ from particledb.pdb_wire import BatchExecuteError, PdbWireClient, Session, TransactionRolledBackError
43
+ from particledb.connection import (
44
+ DEFAULT_PORT,
45
+ Connection,
46
+ Notice,
47
+ Pending,
48
+ PreparedStatement,
49
+ Result,
50
+ RowStream,
51
+ connect,
52
+ )
53
+ from particledb._protocol import Float4, Int2, Int4, Json, Jsonb
54
+ from particledb.errors import (
55
+ BatchError,
56
+ ConnectionError as WireConnectionError,
57
+ ProtocolError,
58
+ QueryCanceledError,
59
+ QueryError,
60
+ )
61
+
62
+ # Particles authoring decorators (the developer front door): write ordinary
63
+ # Python, mark it with a SQL concept, deploy with `pdb particles deploy`.
64
+ # See docs/architecture/PARTICLES_DEPLOY_AND_DISCOVERY.md.
65
+ # NOTE: `type` is imported under an alias so it does not shadow the builtin
66
+ # `type(...)` used just below for the error-class aliases; it is re-exported as
67
+ # `type` at the end of this module (after those uses).
68
+ from particledb.particles import (
69
+ scalar,
70
+ aggregate,
71
+ window,
72
+ cast,
73
+ type as _particle_type,
74
+ )
75
+
76
+ # Error class aliases for compatibility
77
+ PdbError = ParticleDBError
78
+ PdbConnectionError = type("PdbConnectionError", (ParticleDBError,), {})
79
+ PdbQueryError = type("PdbQueryError", (ParticleDBError,), {})
80
+ DiskFullError = type("DiskFullError", (ParticleDBError,), {})
81
+
82
+ __all__ = [
83
+ "connect",
84
+ "Connection",
85
+ "Result",
86
+ "RowStream",
87
+ "PreparedStatement",
88
+ "Pending",
89
+ "Notice",
90
+ "DEFAULT_PORT",
91
+ "Int2",
92
+ "Int4",
93
+ "Float4",
94
+ "Json",
95
+ "Jsonb",
96
+ "QueryError",
97
+ "QueryCanceledError",
98
+ "WireConnectionError",
99
+ "ProtocolError",
100
+ "BatchError",
101
+ "ParticleDB",
102
+ "ParticleDBError",
103
+ "ParticleDBBatchError",
104
+ "BatchExecuteError",
105
+ "TransactionRolledBackError",
106
+ "PdbError",
107
+ "PdbConnectionError",
108
+ "PdbQueryError",
109
+ "DiskFullError",
110
+ "QueryResult",
111
+ "KV",
112
+ "Vector",
113
+ "RAG",
114
+ "AI",
115
+ "Ops",
116
+ "PdbWireClient",
117
+ "Session",
118
+ # Particles authoring decorators.
119
+ "scalar",
120
+ "aggregate",
121
+ "window",
122
+ "type",
123
+ "cast",
124
+ ]
125
+
126
+ # Re-export the `@type` Particle decorator now that the module-scope builtin
127
+ # `type(...)` uses above are done. Import as `type as udt` if you prefer to
128
+ # avoid the builtin name in your own code.
129
+ type = _particle_type # noqa: A001 - deliberate SQL-vocabulary name
130
+
131
+ __version__ = "0.2.0"
132
+
133
+ # Lazy import for gRPC client - avoids hard dependency on grpcio
134
+ def __getattr__(name):
135
+ if name == "GrpcClient":
136
+ from particledb.grpc_client import GrpcClient
137
+ return GrpcClient
138
+ raise AttributeError(f"module 'particledb' has no attribute {name!r}")
@@ -0,0 +1,50 @@
1
+ """``python -m particledb particles verify <path>`` — check a Particles module
2
+ locally, with no server: discovery, type mapping, shapes and options, the same
3
+ rules the server applies when the module is deployed.
4
+
5
+ Exit status 0 when every Particle passes, 1 otherwise. ``--json`` prints the
6
+ manifest the deploy would send.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import sys
12
+
13
+ from particledb import _collect
14
+
15
+ USAGE = "usage: python -m particledb particles verify <module-file|package-dir|dotted.module> [--json]"
16
+
17
+
18
+ def main(argv: list) -> int:
19
+ args = [a for a in argv[1:] if a != "--json"]
20
+ as_json = "--json" in argv
21
+ if len(args) != 3 or args[0] != "particles" or args[1] != "verify":
22
+ print(USAGE, file=sys.stderr)
23
+ return 2
24
+ target = args[2]
25
+ try:
26
+ manifest = _collect.collect(target)
27
+ problems = _collect.verify(target)
28
+ except _collect.CollectError as e:
29
+ print("error: %s" % e, file=sys.stderr)
30
+ return 1
31
+ except Exception as e: # noqa: BLE001 - surface import-time failures plainly
32
+ print("error: while importing %s: %s: %s" % (target, type(e).__name__, e), file=sys.stderr)
33
+ return 1
34
+ if as_json:
35
+ print(json.dumps(manifest, indent=2))
36
+ else:
37
+ for p in manifest["particles"]:
38
+ args_sql = ", ".join(x["sql_type"] for x in p["params"])
39
+ print("ok @%-9s %s(%s) -> %s [%s%s%s]" % (
40
+ p["kind"], p["name"], args_sql, p["returns"]["sql_type"], p["volatility"],
41
+ (", streaming" if p.get("streaming") else "")
42
+ + (", called_on_null" if p["null_policy"] == "called_on_null" else ""),
43
+ ", parallel unsafe" if not p["parallel_safe"] else ""))
44
+ for msg in problems:
45
+ print("FAIL %s" % msg, file=sys.stderr)
46
+ return 1 if problems else 0
47
+
48
+
49
+ if __name__ == "__main__":
50
+ sys.exit(main(sys.argv))