langgraph-checkpoint-postgres 1.0.5__tar.gz → 1.0.6__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.
- {langgraph_checkpoint_postgres-1.0.5 → langgraph_checkpoint_postgres-1.0.6}/PKG-INFO +2 -2
- {langgraph_checkpoint_postgres-1.0.5 → langgraph_checkpoint_postgres-1.0.6}/langgraph/checkpoint/postgres/aio.py +95 -1
- {langgraph_checkpoint_postgres-1.0.5 → langgraph_checkpoint_postgres-1.0.6}/pyproject.toml +2 -2
- {langgraph_checkpoint_postgres-1.0.5 → langgraph_checkpoint_postgres-1.0.6}/README.md +0 -0
- {langgraph_checkpoint_postgres-1.0.5 → langgraph_checkpoint_postgres-1.0.6}/langgraph/checkpoint/postgres/__init__.py +0 -0
- {langgraph_checkpoint_postgres-1.0.5 → langgraph_checkpoint_postgres-1.0.6}/langgraph/checkpoint/postgres/base.py +0 -0
- {langgraph_checkpoint_postgres-1.0.5 → langgraph_checkpoint_postgres-1.0.6}/langgraph/checkpoint/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: langgraph-checkpoint-postgres
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.6
|
|
4
4
|
Summary: Library with a Postgres implementation of LangGraph checkpoint saver.
|
|
5
5
|
Home-page: https://www.github.com/langchain-ai/langgraph
|
|
6
6
|
License: MIT
|
|
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Requires-Dist: langgraph-checkpoint (>=1.0.
|
|
14
|
+
Requires-Dist: langgraph-checkpoint (>=1.0.8,<2.0.0)
|
|
15
15
|
Requires-Dist: orjson (>=3.10.1)
|
|
16
16
|
Requires-Dist: psycopg (>=3.0.0,<4.0.0)
|
|
17
17
|
Requires-Dist: psycopg-pool (>=3.0.0,<4.0.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
from contextlib import asynccontextmanager
|
|
3
|
-
from typing import Any, AsyncIterator, Optional, Union
|
|
3
|
+
from typing import Any, AsyncIterator, Iterator, List, Optional, Union
|
|
4
4
|
|
|
5
5
|
from langchain_core.runnables import RunnableConfig
|
|
6
6
|
from psycopg import AsyncConnection, AsyncCursor, AsyncPipeline
|
|
@@ -51,6 +51,7 @@ class AsyncPostgresSaver(BasePostgresSaver):
|
|
|
51
51
|
self.conn = conn
|
|
52
52
|
self.pipe = pipe
|
|
53
53
|
self.lock = asyncio.Lock()
|
|
54
|
+
self.loop = asyncio.get_running_loop()
|
|
54
55
|
|
|
55
56
|
@classmethod
|
|
56
57
|
@asynccontextmanager
|
|
@@ -329,3 +330,96 @@ class AsyncPostgresSaver(BasePostgresSaver):
|
|
|
329
330
|
binary=True, row_factory=dict_row
|
|
330
331
|
) as cur:
|
|
331
332
|
yield cur
|
|
333
|
+
|
|
334
|
+
def list(
|
|
335
|
+
self,
|
|
336
|
+
config: Optional[RunnableConfig],
|
|
337
|
+
*,
|
|
338
|
+
filter: Optional[dict[str, Any]] = None,
|
|
339
|
+
before: Optional[RunnableConfig] = None,
|
|
340
|
+
limit: Optional[int] = None,
|
|
341
|
+
) -> Iterator[CheckpointTuple]:
|
|
342
|
+
"""List checkpoints from the database.
|
|
343
|
+
|
|
344
|
+
This method retrieves a list of checkpoint tuples from the Postgres database based
|
|
345
|
+
on the provided config. The checkpoints are ordered by checkpoint ID in descending order (newest first).
|
|
346
|
+
|
|
347
|
+
Args:
|
|
348
|
+
config (Optional[RunnableConfig]): Base configuration for filtering checkpoints.
|
|
349
|
+
filter (Optional[Dict[str, Any]]): Additional filtering criteria for metadata.
|
|
350
|
+
before (Optional[RunnableConfig]): If provided, only checkpoints before the specified checkpoint ID are returned. Defaults to None.
|
|
351
|
+
limit (Optional[int]): Maximum number of checkpoints to return.
|
|
352
|
+
|
|
353
|
+
Yields:
|
|
354
|
+
Iterator[CheckpointTuple]: An iterator of matching checkpoint tuples.
|
|
355
|
+
"""
|
|
356
|
+
aiter_ = self.alist(config, filter=filter, before=before, limit=limit)
|
|
357
|
+
while True:
|
|
358
|
+
try:
|
|
359
|
+
yield asyncio.run_coroutine_threadsafe(
|
|
360
|
+
anext(aiter_), self.loop
|
|
361
|
+
).result()
|
|
362
|
+
except StopAsyncIteration:
|
|
363
|
+
break
|
|
364
|
+
|
|
365
|
+
def get_tuple(self, config: RunnableConfig) -> Optional[CheckpointTuple]:
|
|
366
|
+
"""Get a checkpoint tuple from the database.
|
|
367
|
+
|
|
368
|
+
This method retrieves a checkpoint tuple from the Postgres database based on the
|
|
369
|
+
provided config. If the config contains a "checkpoint_id" key, the checkpoint with
|
|
370
|
+
the matching thread ID and "checkpoint_id" is retrieved. Otherwise, the latest checkpoint
|
|
371
|
+
for the given thread ID is retrieved.
|
|
372
|
+
|
|
373
|
+
Args:
|
|
374
|
+
config (RunnableConfig): The config to use for retrieving the checkpoint.
|
|
375
|
+
|
|
376
|
+
Returns:
|
|
377
|
+
Optional[CheckpointTuple]: The retrieved checkpoint tuple, or None if no matching checkpoint was found.
|
|
378
|
+
"""
|
|
379
|
+
return asyncio.run_coroutine_threadsafe(
|
|
380
|
+
self.aget_tuple(config), self.loop
|
|
381
|
+
).result()
|
|
382
|
+
|
|
383
|
+
def put(
|
|
384
|
+
self,
|
|
385
|
+
config: RunnableConfig,
|
|
386
|
+
checkpoint: Checkpoint,
|
|
387
|
+
metadata: CheckpointMetadata,
|
|
388
|
+
new_versions: ChannelVersions,
|
|
389
|
+
) -> RunnableConfig:
|
|
390
|
+
"""Save a checkpoint to the database.
|
|
391
|
+
|
|
392
|
+
This method saves a checkpoint to the Postgres database. The checkpoint is associated
|
|
393
|
+
with the provided config and its parent config (if any).
|
|
394
|
+
|
|
395
|
+
Args:
|
|
396
|
+
config (RunnableConfig): The config to associate with the checkpoint.
|
|
397
|
+
checkpoint (Checkpoint): The checkpoint to save.
|
|
398
|
+
metadata (CheckpointMetadata): Additional metadata to save with the checkpoint.
|
|
399
|
+
new_versions (ChannelVersions): New channel versions as of this write.
|
|
400
|
+
|
|
401
|
+
Returns:
|
|
402
|
+
RunnableConfig: Updated configuration after storing the checkpoint.
|
|
403
|
+
"""
|
|
404
|
+
return asyncio.run_coroutine_threadsafe(
|
|
405
|
+
self.aput(config, checkpoint, metadata, new_versions), self.loop
|
|
406
|
+
).result()
|
|
407
|
+
|
|
408
|
+
def put_writes(
|
|
409
|
+
self,
|
|
410
|
+
config: RunnableConfig,
|
|
411
|
+
writes: List[tuple[str, Any]],
|
|
412
|
+
task_id: str,
|
|
413
|
+
) -> None:
|
|
414
|
+
"""Store intermediate writes linked to a checkpoint.
|
|
415
|
+
|
|
416
|
+
This method saves intermediate writes associated with a checkpoint to the database.
|
|
417
|
+
|
|
418
|
+
Args:
|
|
419
|
+
config (RunnableConfig): Configuration of the related checkpoint.
|
|
420
|
+
writes (Sequence[Tuple[str, Any]]): List of writes to store, each as (channel, value) pair.
|
|
421
|
+
task_id (str): Identifier for the task creating the writes.
|
|
422
|
+
"""
|
|
423
|
+
return asyncio.run_coroutine_threadsafe(
|
|
424
|
+
self.aput_writes(config, writes, task_id), self.loop
|
|
425
|
+
).result()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "langgraph-checkpoint-postgres"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.6"
|
|
4
4
|
description = "Library with a Postgres implementation of LangGraph checkpoint saver."
|
|
5
5
|
authors = []
|
|
6
6
|
license = "MIT"
|
|
@@ -10,7 +10,7 @@ packages = [{ include = "langgraph" }]
|
|
|
10
10
|
|
|
11
11
|
[tool.poetry.dependencies]
|
|
12
12
|
python = "^3.9.0,<4.0"
|
|
13
|
-
langgraph-checkpoint = "^1.0.
|
|
13
|
+
langgraph-checkpoint = "^1.0.8"
|
|
14
14
|
orjson = ">=3.10.1"
|
|
15
15
|
psycopg = "^3.0.0"
|
|
16
16
|
psycopg-pool = "^3.0.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|