Skip to main content

Quickstart: State Management

In this quickstart, you'll run a stateful order application on Diagrid Cloud. You will learn how to:

  • Provision a Diagrid project with a managed KV store using the Diagrid CLI.
  • Save and retrieve state items using the Dapr State API.
  • Inspect stored data in the Diagrid Web Console.
Order app connected to a Diagrid KV storeDiagridOrder appApp IDorder-appKV store
Order app connected to a Diagrid KV storeThe app saves and reads state through its App ID. Diagrid stores it in the KV store.

1. Prerequisites​

Before you proceed, ensure you have the following prerequisites installed.

2. Log in to Diagrid​

Authenticate to Diagrid using the following command:

diagrid login

This command opens a new browser window where you'll be shown a confirmation code that should match the code in your terminal. Confirm the code, and if you're not logged into Diagrid, you'll be redirected to login.

Confirm your user details are correct using the following command:

diagrid whoami

The expected output contains the name of the organization, your user name, and the Diagrid API endpoint.

3. Clone Quickstart Code​

Clone the quickstart code from GitHub:

git clone https://github.com/diagridio/catalyst-quickstarts

Navigate to the quickstart directory:

cd catalyst-quickstarts/state/python

4. Install Dependencies​

Install the dependencies for the state management application.

Install Python dependencies:

uv sync --all-packages

5. Run the application with Diagrid Cloud​

The diagrid dev run command creates your Diagrid project, provisions resources (apps, Diagrid KV Store service), configures environment variables, and launches your application connected to Diagrid Cloud.

uv run diagrid dev run -f state-quickstart.yaml --project state-quickstart --approve
tip

Wait a few seconds until you see application logs in the terminal to ensure the application is up and running and connected to Diagrid.

6. Call the State API​

With the quickstart running, test the State API by storing, retrieving, and deleting state items.

6.1 Store state​

Open a new terminal and execute the following command to save a state item to the Diagrid KV store:

curl -i -X POST http://localhost:5001/order -H "Content-Type: application/json" -d '{"orderId":1}'

The expected response is:

HTTP/1.1 201 Created

The application logs in the diagrid dev run terminal should show an order was saved.

6.2 Retrieve state​

Confirm the state item was saved successfully by retrieving it:

curl -i -X GET http://localhost:5001/order/1

The expected response body is:

{"orderId":1}

6.3 View in the Diagrid Web Console​

Open the Diagrid Cloud web console and navigate to the KV Store data explorer to (Resources > Managed KV store) view stored state items. The data explorer displays the key-value pairs saved by your application.

Diagrid KV Store data explorer showing stored state items

7. Clean Up​

Press CTRL+C in the terminal that runs diagrid dev run to stop the application and disconnect from Diagrid Cloud.

To delete the entire project and all provisioned resources:

diagrid project delete state-quickstart

Summary​

In this quickstart you:

  • Logged in to Diagrid and provisioned a managed state store project with a single CLI command (diagrid dev run).
  • Saved and retrieved state items using the Dapr State API.
  • Inspected stored data using the Diagrid KV Store data explorer.

Diagrid handled state persistence and key-value storage automatically — no infrastructure to manage.

Next steps​

Durable Execution & Dapr University · Learn this hands-onRunning Dapr applications with DiagridRun Dapr apps on Diagrid's managed pub/sub, KV store, and workflow engine — no infrastructure to operate.Beginner30 min.NET · Python · Java · JavaScriptStart the track Durable Execution & Dapr University · New to Dapr?Dapr 101: State Management, Service Invocation, and Pub/Sub APIsLearn Dapr's core building blocks — state management, service invocation, and pub/sub — through hands-on coding.Beginner45 min.NET · Python · Java · JavaScriptStart the track