---
dimensions:
  type:
    primary: reference
    detail: core
  level: beginner
standard_title: Persistent Storage KV
language: en
title: Persistent Storage
description: This document introduces the persistent storage functionality in Dify
  plugins, detailing how to use the KV database in plugins to store, retrieve, and
  delete data. This feature enables plugins to persistently store data within the
  same Workspace, meeting the needs for data preservation across sessions.
---

When examining Tools and Endpoints in plugins individually, it's not difficult to see that in most cases, they can only complete single-round interactions: request, return data, and the task ends.

If there is data that needs to be stored long-term, such as implementing persistent memory, the plugin needs to have persistent storage capabilities. **The persistent storage mechanism allows plugins to have the ability to persistently store data within the same Workspace**. Currently, a KV database is provided to meet storage needs, and more flexible and powerful storage interfaces may be introduced in the future based on actual usage.

### Storing Keys

#### **Entry Point**

```python
    self.session.storage
```

#### **Interface**

```python
    def set(self, key: str, val: bytes) -> None:
        pass
```

Note that what is passed in is bytes, so you can actually store files in it.

### Getting Keys

#### **Entry Point**

```python
    self.session.storage
```

#### **Interface**

```python
    def get(self, key: str) -> bytes:
        pass
```

### Deleting Keys

#### **Entry Point**

```python
    self.session.storage
```

#### **Interface**

```python
    def delete(self, key: str) -> None:
        pass
```

{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}

---

[Edit this page](https://github.com/langgenius/dify-docs/edit/main/plugin-dev-en/0411-persistent-storage-kv.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)

