latch-postgres 0.1.19__py3-none-any.whl → 0.1.21__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.
- latch_postgres/postgres.py +18 -47
- latch_postgres-0.1.21.dist-info/METADATA +18 -0
- latch_postgres-0.1.21.dist-info/RECORD +8 -0
- {latch_postgres-0.1.19.dist-info → latch_postgres-0.1.21.dist-info}/WHEEL +1 -1
- latch_postgres-0.1.19.dist-info/METADATA +0 -24
- latch_postgres-0.1.19.dist-info/RECORD +0 -8
- {latch_postgres-0.1.19.dist-info → latch_postgres-0.1.21.dist-info/licenses}/LICENSE +0 -0
latch_postgres/postgres.py
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import functools
|
|
3
3
|
import random
|
|
4
|
+
from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Iterable
|
|
4
5
|
from contextlib import asynccontextmanager
|
|
5
6
|
from dataclasses import dataclass
|
|
6
7
|
from datetime import timedelta
|
|
7
8
|
from textwrap import dedent
|
|
8
|
-
from typing import
|
|
9
|
-
Any,
|
|
10
|
-
AsyncGenerator,
|
|
11
|
-
Awaitable,
|
|
12
|
-
Callable,
|
|
13
|
-
Concatenate,
|
|
14
|
-
Iterable,
|
|
15
|
-
ParamSpec,
|
|
16
|
-
TypeVar,
|
|
17
|
-
cast,
|
|
18
|
-
)
|
|
9
|
+
from typing import Any, Concatenate, ParamSpec, TypeVar, cast
|
|
19
10
|
|
|
20
11
|
import psycopg.sql as sql
|
|
21
12
|
from latch_config.config import PostgresConnectionConfig
|
|
@@ -37,9 +28,6 @@ from psycopg.errors import (
|
|
|
37
28
|
DeadlockDetected,
|
|
38
29
|
DiskFull,
|
|
39
30
|
DuplicateFile,
|
|
40
|
-
)
|
|
41
|
-
from psycopg.errors import Error as PGError
|
|
42
|
-
from psycopg.errors import (
|
|
43
31
|
IdleSessionTimeout,
|
|
44
32
|
InsufficientResources,
|
|
45
33
|
IoError,
|
|
@@ -55,6 +43,7 @@ from psycopg.errors import (
|
|
|
55
43
|
TooManyConnections,
|
|
56
44
|
UndefinedFile,
|
|
57
45
|
)
|
|
46
|
+
from psycopg.errors import Error as PGError
|
|
58
47
|
from psycopg.rows import AsyncRowFactory, Row, dict_row, kwargs_row
|
|
59
48
|
from psycopg.types.composite import CompositeInfo, register_composite
|
|
60
49
|
from psycopg.types.enum import EnumInfo, register_enum
|
|
@@ -63,6 +52,8 @@ from typing_extensions import Self
|
|
|
63
52
|
|
|
64
53
|
from latch_postgres.retries import CABackoff
|
|
65
54
|
|
|
55
|
+
YT = TypeVar("YT")
|
|
56
|
+
ST = TypeVar("ST")
|
|
66
57
|
T = TypeVar("T")
|
|
67
58
|
|
|
68
59
|
tracer = get_tracer(__name__)
|
|
@@ -158,15 +149,9 @@ class LatchAsyncConnection(AsyncConnection[Row]):
|
|
|
158
149
|
trace_attributes: Attributes
|
|
159
150
|
|
|
160
151
|
def cursor(
|
|
161
|
-
self,
|
|
162
|
-
row_factory: AsyncRowFactory[Any],
|
|
163
|
-
*,
|
|
164
|
-
binary: bool = True,
|
|
152
|
+
self, row_factory: AsyncRowFactory[Any], *, binary: bool = True
|
|
165
153
|
) -> AsyncCursor[Any]:
|
|
166
|
-
res = super().cursor(
|
|
167
|
-
row_factory=row_factory,
|
|
168
|
-
binary=binary,
|
|
169
|
-
)
|
|
154
|
+
res = super().cursor(row_factory=row_factory, binary=binary)
|
|
170
155
|
assert isinstance(res, TracedAsyncCursor)
|
|
171
156
|
res.trace_attributes = self.trace_attributes
|
|
172
157
|
return res
|
|
@@ -291,18 +276,12 @@ class TracedAsyncConnectionPool(AsyncConnectionPool):
|
|
|
291
276
|
)
|
|
292
277
|
|
|
293
278
|
async def run_setup(cmd: sql.SQL):
|
|
294
|
-
with tracer.start_as_current_span(
|
|
295
|
-
"setup command",
|
|
296
|
-
):
|
|
279
|
+
with tracer.start_as_current_span("setup command"):
|
|
297
280
|
await conn.query_opt(dict, cmd)
|
|
298
281
|
|
|
299
282
|
async def run_composite_setup():
|
|
300
|
-
with tracer.start_as_current_span(
|
|
301
|
-
"composite
|
|
302
|
-
):
|
|
303
|
-
with tracer.start_as_current_span(
|
|
304
|
-
"register composite types",
|
|
305
|
-
):
|
|
283
|
+
with tracer.start_as_current_span("composite type setup"):
|
|
284
|
+
with tracer.start_as_current_span("register composite types"):
|
|
306
285
|
for db_type, f in self.composite_type_map.items():
|
|
307
286
|
type_info = await CompositeInfo.fetch(conn, db_type)
|
|
308
287
|
if type_info is None:
|
|
@@ -312,12 +291,8 @@ class TracedAsyncConnectionPool(AsyncConnectionPool):
|
|
|
312
291
|
register_composite(type_info, conn, f)
|
|
313
292
|
|
|
314
293
|
async def run_enum_setup():
|
|
315
|
-
with tracer.start_as_current_span(
|
|
316
|
-
"
|
|
317
|
-
):
|
|
318
|
-
with tracer.start_as_current_span(
|
|
319
|
-
"fetch type info",
|
|
320
|
-
):
|
|
294
|
+
with tracer.start_as_current_span("enum setup"):
|
|
295
|
+
with tracer.start_as_current_span("fetch type info"):
|
|
321
296
|
# query from
|
|
322
297
|
# https://github.com/psycopg/psycopg/blob/fd1659118e96a48f22b4e67ff17c2cdab8bd0e84/psycopg/psycopg/_typeinfo.py#L148
|
|
323
298
|
raw_responses = await conn.queryn(
|
|
@@ -406,9 +381,7 @@ class TracedAsyncConnectionPool(AsyncConnectionPool):
|
|
|
406
381
|
|
|
407
382
|
async def getconn(self, timeout: float | None = None) -> AsyncConnection[object]:
|
|
408
383
|
with tracer.start_as_current_span(
|
|
409
|
-
"postgres.connect",
|
|
410
|
-
kind=SpanKind.CLIENT,
|
|
411
|
-
attributes=self._trace_attributes,
|
|
384
|
+
"postgres.connect", kind=SpanKind.CLIENT, attributes=self._trace_attributes
|
|
412
385
|
):
|
|
413
386
|
return await super().getconn(timeout)
|
|
414
387
|
|
|
@@ -443,9 +416,7 @@ def mixin_dict(a: dict[str, object], b: dict[str, object]):
|
|
|
443
416
|
def pg_error_to_dict(x: PGError, *, short: bool = False):
|
|
444
417
|
diagnostic_obj = {
|
|
445
418
|
"severity": x.diag.severity,
|
|
446
|
-
"message": {
|
|
447
|
-
"detail": x.diag.message_detail,
|
|
448
|
-
},
|
|
419
|
+
"message": {"detail": x.diag.message_detail},
|
|
449
420
|
}
|
|
450
421
|
|
|
451
422
|
if not short:
|
|
@@ -486,10 +457,10 @@ def pg_error_to_dict(x: PGError, *, short: bool = False):
|
|
|
486
457
|
|
|
487
458
|
|
|
488
459
|
def with_conn_retry(
|
|
489
|
-
f: Callable[Concatenate[LatchAsyncConnection[Any], P],
|
|
460
|
+
f: Callable[Concatenate[LatchAsyncConnection[Any], P], Coroutine[YT, ST, T]],
|
|
490
461
|
pool: AsyncConnectionPool,
|
|
491
462
|
db_config: PostgresConnectionConfig,
|
|
492
|
-
) -> Callable[P,
|
|
463
|
+
) -> Callable[P, Coroutine[YT, ST, T]]:
|
|
493
464
|
@functools.wraps(f)
|
|
494
465
|
async def inner(*args: P.args, **kwargs: P.kwargs):
|
|
495
466
|
with tracer.start_as_current_span("database session") as s:
|
|
@@ -616,8 +587,8 @@ def with_conn_retry(
|
|
|
616
587
|
def get_with_conn_retry(
|
|
617
588
|
pool: AsyncConnectionPool, db_config: PostgresConnectionConfig
|
|
618
589
|
) -> Callable[
|
|
619
|
-
[Callable[Concatenate[LatchAsyncConnection[Any], P],
|
|
620
|
-
Callable[P,
|
|
590
|
+
[Callable[Concatenate[LatchAsyncConnection[Any], P], Coroutine[YT, ST, T]]],
|
|
591
|
+
Callable[P, Coroutine[YT, ST, T]],
|
|
621
592
|
]:
|
|
622
593
|
return functools.partial(with_conn_retry, pool=pool, db_config=db_config)
|
|
623
594
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: latch-postgres
|
|
3
|
+
Version: 0.1.21
|
|
4
|
+
Summary: Postges wrapper for latch python backend services
|
|
5
|
+
Author-email: maximsmol <max@latch.bio>
|
|
6
|
+
License: CC0-1.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: latch-config<1.0.0,>=0.1.6
|
|
10
|
+
Requires-Dist: latch-data-validation<1.0.0,>=0.1.10
|
|
11
|
+
Requires-Dist: latch-o11y<2.0.0,>=1.0.0
|
|
12
|
+
Requires-Dist: opentelemetry-api<2.0.0,>=1.15.0
|
|
13
|
+
Requires-Dist: opentelemetry-sdk<2.0.0,>=1.15.0
|
|
14
|
+
Requires-Dist: psycopg[binary,pool]<4.0.0,>=3.1.8
|
|
15
|
+
Requires-Dist: typing-extensions<5.0.0,>=4.4.0
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# python-postgres
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
latch_postgres/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
latch_postgres/postgres.py,sha256=-TpNtSGe-EKy-hKOhajkriqbYkKvYV3LegDqx3towJ8,24522
|
|
3
|
+
latch_postgres/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
latch_postgres/retries.py,sha256=r5yH00fd_6EJNYFXAq3dAljJBphScpoeST-_oMvyj8Q,1308
|
|
5
|
+
latch_postgres-0.1.21.dist-info/METADATA,sha256=12J7_YVLtpW3MbfvEYAxbP2VAK36ZSjHD7a5vTli-jY,607
|
|
6
|
+
latch_postgres-0.1.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
latch_postgres-0.1.21.dist-info/licenses/LICENSE,sha256=wh3JZu6ITG7ceN-1g404ekupj5JXAw4pnQ_Qr4sJfew,7052
|
|
8
|
+
latch_postgres-0.1.21.dist-info/RECORD,,
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: latch-postgres
|
|
3
|
-
Version: 0.1.19
|
|
4
|
-
Summary: Postges wrapper for latch python backend services
|
|
5
|
-
License: CC0 1.0
|
|
6
|
-
Author: Max Smolin
|
|
7
|
-
Author-email: max@latch.bio
|
|
8
|
-
Requires-Python: >=3.11,<4.0
|
|
9
|
-
Classifier: License :: Other/Proprietary License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
-
Requires-Dist: latch-config (>=0.1.6,<0.2.0)
|
|
15
|
-
Requires-Dist: latch-data-validation (>=0.1.10,<0.2.0)
|
|
16
|
-
Requires-Dist: latch-o11y (>=0.1.4,<0.2.0)
|
|
17
|
-
Requires-Dist: opentelemetry-api (>=1.15.0,<2.0.0)
|
|
18
|
-
Requires-Dist: opentelemetry-sdk (>=1.15.0,<2.0.0)
|
|
19
|
-
Requires-Dist: psycopg[binary,pool] (>=3.1.8,<4.0.0)
|
|
20
|
-
Requires-Dist: typing-extensions (>=4.4.0,<5.0.0)
|
|
21
|
-
Description-Content-Type: text/markdown
|
|
22
|
-
|
|
23
|
-
# python-postgres
|
|
24
|
-
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
latch_postgres/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
latch_postgres/postgres.py,sha256=tGUhVLq5J4tyNrKt4xiRf-RlkqFNrUZ9Jl7WEHLqIPQ,24845
|
|
3
|
-
latch_postgres/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
latch_postgres/retries.py,sha256=r5yH00fd_6EJNYFXAq3dAljJBphScpoeST-_oMvyj8Q,1308
|
|
5
|
-
latch_postgres-0.1.19.dist-info/LICENSE,sha256=wh3JZu6ITG7ceN-1g404ekupj5JXAw4pnQ_Qr4sJfew,7052
|
|
6
|
-
latch_postgres-0.1.19.dist-info/METADATA,sha256=fFn_TvOGV1kApPUiG9ow5gMgWQrMl3jVI2ZbNpQD_M0,869
|
|
7
|
-
latch_postgres-0.1.19.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
|
8
|
-
latch_postgres-0.1.19.dist-info/RECORD,,
|
|
File without changes
|