# InMemorySaver

> **Class** in `langgraph.checkpoint`

📖 [View in docs](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver)

An in-memory checkpoint saver.

This checkpoint saver stores checkpoints in memory using a `defaultdict`.

## Signature

```python
InMemorySaver(
    self,
    *,
    serde: SerializerProtocol | None = None,
    factory: type[defaultdict] = defaultdict,
)
```

## Description

**Note:**

Only use `InMemorySaver` for debugging or testing purposes.
For production use cases we recommend installing [langgraph-checkpoint-postgres](https://pypi.org/project/langgraph-checkpoint-postgres/) and using `PostgresSaver` / `AsyncPostgresSaver`.

If you are using LangSmith Deployment, no checkpointer needs to be specified. The correct managed checkpointer will be used automatically.

**Example:**

```python
import asyncio

from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph

builder = StateGraph(int)
builder.add_node("add_one", lambda x: x + 1)
builder.set_entry_point("add_one")
builder.set_finish_point("add_one")

memory = InMemorySaver()
graph = builder.compile(checkpointer=memory)
coro = graph.ainvoke(1, {"configurable": {"thread_id": "thread-1"}})
asyncio.run(coro)  # Output: 2
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `serde` | `SerializerProtocol \| None` | No | The serializer to use for serializing and deserializing checkpoints. (default: `None`) |

## Extends

- `BaseCheckpointSaver[str]`
- `AbstractContextManager`
- `AbstractAsyncContextManager`

## Constructors

```python
__init__(
    self,
    *,
    serde: SerializerProtocol | None = None,
    factory: type[defaultdict] = defaultdict,
) -> None
```

| Name | Type |
|------|------|
| `serde` | `SerializerProtocol \| None` |
| `factory` | `type[defaultdict]` |


## Properties

- `storage`
- `writes`
- `blobs`
- `stack`

## Methods

- [`get_delta_channel_history()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/get_delta_channel_history)
- [`aget_delta_channel_history()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/aget_delta_channel_history)
- [`get_tuple()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/get_tuple)
- [`list()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/list)
- [`put()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/put)
- [`put_writes()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/put_writes)
- [`delete_thread()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/delete_thread)
- [`aget_tuple()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/aget_tuple)
- [`alist()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/alist)
- [`aput()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/aput)
- [`aput_writes()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/aput_writes)
- [`adelete_thread()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/adelete_thread)
- [`get_next_version()`](https://reference.langchain.com/python/langgraph.checkpoint/memory/InMemorySaver/get_next_version)

---

[View source on GitHub](https://github.com/langchain-ai/langgraph/blob/398d6cc59d4cf81ab23c09f037e9f521c3fedcd6/libs/checkpoint/langgraph/checkpoint/memory/__init__.py#L33)