---
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?title=Documentation%20Issue%3A%20persistent-storage&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fplugin-dev-en%2F0411-persistent-storage-kv.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E)

