Replit Key-Value Store provides a simple, user-friendly database inside every Replit App. No configuration required—just import and start storing data immediately.

Features

  • Zero configuration: Start using the database right away with no setup required
  • Simple API: Store and retrieve data with an interface similar to Python dictionaries
  • Multiple data types: Store strings, numbers, lists, dictionaries, and other Python objects
  • Prefix filtering: Query for keys that share common prefixes
  • Built-in access: Access your database from the Replit workspace sidebar

Getting started

Accessing your key-value store

Importing the database

from replit import db

If you encounter deployment errors in Python, ensure you’re using replit version 3.3.0 or above. Check your version with pip show replit. Upgrade with upm add 'replit>=3.3.0'.

For Node.js, make sure to install the package with pnpm add @replit/database.

Using the key-value store

Creating and storing data

The Key-Value Store works similar to a dictionary in Python or an object in JavaScript. Here’s how to add data:

from replit import db

# Add a key and value to the database
db["key1"] = "value1"

Storing different data types

from replit import db

# Store different data types
db["string_key"] = "text value"
db["integer_key"] = 100
db["float_key"] = 9.99
db["list_key"] = [1, 2, 3]
db["dict_key"] = {"name": "user", "role": "admin"}
db["none_key"] = None

Use 2D arrays/lists to create table-like structures:

from replit import db

db["users"] = [["id", "name"], [1, "James"], [2, "Angel"]]

for row in db["users"]:
    print(row)

Reading data

Retrieve data by referencing the key:

from replit import db

# Create example data
db["username"] = "developer123"
db["user_info"] = {"email": "dev@example.com", "plan": "Pro"}

# Read the data
print(db["username"])                   # Outputs: developer123
print(db["user_info"]["email"])         # Outputs: dev@example.com

For safer access that won’t raise an error if the key doesn’t exist:

from replit import db

# Create example data
db["count"] = 42

# Access with get() method
print(db.get("count"))                  # Outputs: 42
print(db.get("missing_key", "Not found")) # Outputs: Not found

Listing and searching keys

Access all keys in the database:

from replit import db

# Create some sample data first
db["user1"] = "Alice"
db["user2"] = "Bob"
db["setting1"] = "enabled"

# Print all keys
print(db.keys())  # Outputs something like: {'user1', 'user2', 'setting1'}

# Loop through keys and print values
for key in db:
    print(f"{key}: {db.get(key)}")

Find keys with a specific prefix:

from replit import db

# Create data
db["user_id"] = 1001
db["user_name"] = "Alex"
db["item_id"] = 5001

# Find all keys starting with "user"
user_keys = db.prefix("user")
print(user_keys)  # Outputs: ('user_id', 'user_name')

Updating data

Update stored values by assigning new values to existing keys:

from replit import db

# Create and display data
db["score"] = 95
print(db["score"])  # Outputs: 95

# Update the value
db["score"] = 98
print(db["score"])  # Outputs: 98

Perform operations on stored values:

from replit import db

# Create numeric data
db["counter"] = 10

# Increment the value
db["counter"] += 5
print(db["counter"])  # Outputs: 15

Deleting data

Remove key-value pairs:

from replit import db

# Create data
db["temporary"] = "will be deleted"

# Delete the data
del db["temporary"]

# Verify deletion
if "temporary" not in db:
    print("Value deleted successfully.")

Complete example

Here’s a complete example of using the Key-Value Store for a simple task list:

from replit import db
import time

def add_task(title, description=""):
    task_id = int(time.time())  # Use timestamp as ID
    db[f"task_{task_id}"] = {
        "id": task_id,
        "title": title,
        "description": description,
        "completed": False,
        "created_at": time.time()
    }
    return task_id

def complete_task(task_id):
    key = f"task_{task_id}"
    if key in db:
        task = db[key]
        task["completed"] = True
        db[key] = task
        return True
    return False

def list_tasks(show_completed=True):
    tasks = []
    for key in db.prefix("task_"):
        task = db[key]
        if show_completed or not task["completed"]:
            tasks.append(task)
    return tasks

# Usage example
add_task("Buy groceries", "Milk, eggs, bread")
add_task("Call dentist")
task_id = add_task("Finish project", "Complete documentation")

# Mark a task as complete
complete_task(task_id)

# List all tasks
all_tasks = list_tasks()
for task in all_tasks:
    status = "✓" if task["completed"] else "☐"
    print(f"{status} {task['title']}: {task.get('description', '')}")

Use cases

The Key-Value Store is ideal for:

  • User preferences: Store user settings and preferences
  • Game state: Save game progress and high scores
  • Caching: Store temporary data to speed up your application
  • Simple configuration: Maintain configuration values across app restarts
  • Session data: Track user sessions without complex database setup

FAQs

Where can I find my store?

How can I access my store programmatically?

Replit provides official clients for multiple languages:

What if my language doesn’t have a client?

If your Replit App is in a language without an official client, you can use HTTP requests to interact with the database:

What is REPLIT_DB_URL?

REPLIT_DB_URL is an environment variable created with your Replit App. It’s the connection string that enables database access.

REPLIT_DB_URL provides full access to your database. Never expose it publicly or share it with untrusted parties.

What are the storage limits?

The Key-Value Store has the following limits:

  • 50 MiB per store (sum of keys and values)
  • 5,000 keys per store
  • 1,000 bytes per key
  • 5 MiB per value

Rate limits apply to all operations. If exceeded, you’ll receive an HTTP 429 response. Implement exponential retry with gradual delays to handle rate limiting.

How can I check my storage usage?

Is my store private?

Yes, each store is private and isolated. Every Replit App has its own database that is not shared with other Replit Apps.

How do I share a database across multiple Replit Apps?

Next steps

To learn about other storage options available in Replit: