particledb 0.2.0__py3-none-any.whl
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.
- particledb/__init__.py +138 -0
- particledb/__main__.py +50 -0
- particledb/_arrow.py +1122 -0
- particledb/_bulkdata.py +203 -0
- particledb/_collect.py +285 -0
- particledb/_dsn.py +18 -0
- particledb/_frames.py +258 -0
- particledb/_protocol.py +904 -0
- particledb/_tls.py +110 -0
- particledb/ai.py +709 -0
- particledb/aio/__init__.py +51 -0
- particledb/aio/_connection.py +421 -0
- particledb/aio/_cursor.py +462 -0
- particledb/aio/_pool.py +203 -0
- particledb/aio/_wire.py +889 -0
- particledb/arrow_ipc.py +412 -0
- particledb/client.py +890 -0
- particledb/connection.py +1894 -0
- particledb/dbapi/__init__.py +72 -0
- particledb/dbapi/_adapt.py +109 -0
- particledb/dbapi/_connection.py +582 -0
- particledb/dbapi/_cursor.py +581 -0
- particledb/dbapi/_literal.py +182 -0
- particledb/dbapi/_result.py +278 -0
- particledb/dbapi/_sql.py +373 -0
- particledb/dbapi/_types.py +252 -0
- particledb/dbapi/errors.py +219 -0
- particledb/dbapi/rows.py +81 -0
- particledb/errors.py +140 -0
- particledb/grpc_client.py +583 -0
- particledb/kv.py +200 -0
- particledb/ops.py +582 -0
- particledb/particles.py +222 -0
- particledb/pdb_wire.py +727 -0
- particledb/rag.py +206 -0
- particledb/sqlalchemy/__init__.py +10 -0
- particledb/sqlalchemy/base.py +477 -0
- particledb/sqlalchemy/provision.py +89 -0
- particledb/sqlalchemy/reflection.py +487 -0
- particledb/sqlalchemy/requirements.py +276 -0
- particledb/vector.py +169 -0
- particledb-0.2.0.dist-info/METADATA +211 -0
- particledb-0.2.0.dist-info/RECORD +47 -0
- particledb-0.2.0.dist-info/WHEEL +5 -0
- particledb-0.2.0.dist-info/entry_points.txt +3 -0
- particledb-0.2.0.dist-info/licenses/LICENSE +21 -0
- particledb-0.2.0.dist-info/top_level.txt +1 -0
particledb/__init__.py
ADDED
|
@@ -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}")
|
particledb/__main__.py
ADDED
|
@@ -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))
|