Skip to main content

langgraph-checkpoint-dynamodb

Implementation of a LangGraph CheckpointSaver that uses a AWS's DynamoDB

Inspiration

Based on: https://github.com/researchwiseai/langgraphjs-checkpoint-dynamodb

Required DynamoDB Tables

To be able to use this checkpointer, two DynamoDB table's are needed, one to store checkpoints and the other to store writes. Below are some examples of how you can create the required tables.

Terraform

# Variables for table names
variable "checkpoints_table_name" {
  type = string
}

variable "writes_table_name" {
  type = string
}

# Checkpoints Table
resource "aws_dynamodb_table" "checkpoints_table" {
  name         = var.checkpoints_table_name
  billing_mode = "PAY_PER_REQUEST"

  hash_key  = "thread_id"
  range_key = "checkpoint_id"

  attribute {
    name = "thread_id"
    type = "S"
  }

  attribute {
    name = "checkpoint_id"
    type = "S"
  }
}

# Writes Table
resource "aws_dynamodb_table" "writes_table" {
  name         = var.writes_table_name
  billing_mode = "PAY_PER_REQUEST"

  hash_key  = "thread_id_checkpoint_id_checkpoint_ns"
  range_key = "task_id_idx"

  attribute {
    name = "thread_id_checkpoint_id_checkpoint_ns"
    type = "S"
  }

  attribute {
    name = "task_id_idx"
    type = "S"
  }
}

AWS CDK

from aws_cdk import (
    Stack,
    aws_dynamodb as dynamodb,
)
from constructs import Construct

class DynamoDbStack(Stack):
    def __init__(self, scope: Construct, id: str, **kwargs):
        super().__init__(scope, id, **kwargs)

        checkpoints_table_name = 'YourCheckpointsTableName'
        writes_table_name = 'YourWritesTableName'

        # Checkpoints Table
        dynamodb.Table(
            self,
            'CheckpointsTable',
            table_name=checkpoints_table_name,
            billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
            partition_key=dynamodb.Attribute(
                name='thread_id',
                type=dynamodb.AttributeType.STRING,
            ),
            sort_key=dynamodb.Attribute(
                name='checkpoint_id',
                type=dynamodb.AttributeType.STRING,
            ),
        )

        # Writes Table
        dynamodb.Table(
            self,
            'WritesTable',
            table_name=writes_table_name,
            billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
            partition_key=dynamodb.Attribute(
                name='thread_id_checkpoint_id_checkpoint_ns',
                type=dynamodb.AttributeType.STRING,
            ),
            sort_key=dynamodb.Attribute(
                name='task_id_idx',
                type=dynamodb.AttributeType.STRING,
            ),
        )

Using the Checkpoint Saver

Default

To use the DynamoDB checkpoint saver, you only need to specify the names of the checkpoints and writes tables. In this scenario the DynamoDB client will be instantiated with the default configuration, great for running on AWS Lambda.

from langgraph_checkpoint_dynamodb import DynamoDBSaver
...
checkpoints_table_name = 'YourCheckpointsTableName'
writes_table_name = 'YourWritesTableName'

memory = DynamoDBSaver(
    checkpoints_table_name=checkpoints_table_name,
    writes_table_name=writes_table_name,
)

graph = workflow.compile(checkpointer=memory)

Providing Client Configuration

If you need to provide custom configuration to the DynamoDB client, you can pass in an object with the configuration options. Below is an example of how you can provide custom configuration.

memory = DynamoDBSaver(
    checkpoints_table_name=checkpoints_table_name,
    writes_table_name=writes_table_name,
    client_config={
        'region': 'us-west-2',
        'accessKeyId': 'your-access-key-id',
        'secretAccessKey': 'your-secret-access-key',
    }
)

Metadata

Release files for langgraph-checkpoint-dynamodb 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langgraph-checkpoint-dynamodb 0.1.0
File Size Uploaded
langgraph_checkpoint_dynamodb-0.1.0.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langgraph-checkpoint-dynamodb 0.1.0
File Interpreter ABI Platform
langgraph_checkpoint_dynamodb-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / langgraph_checkpoint_dynamodb-0.1.0.tar.gz

Download URL langgraph_checkpoint_dynamodb-0.1.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7135d6ee58b1388421a0ef17c6659f031d1d42e1a33b3a5907b8deebe781e1d7
BLAKE2b-256 checksum
How to use checksums
0758400d36651e29726a9d552b8d09d73baf70a48f70d86dab64894a28d927ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 13, 2024.

Transparency log

Release files / langgraph_checkpoint_dynamodb-0.1.0-py3-none-any.whl

Download URL langgraph_checkpoint_dynamodb-0.1.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5992954728862b2a4b2f9947c989cedc9e945c526b9f6ecf42eb21f787fc6ce2
BLAKE2b-256 checksum
How to use checksums
c9f354da77f0242523c1908481bcd99134cb413cdab63b933c7c214c5cb1fbea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 13, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page