Share your repls and programming experiences

← Back to all posts
🟥 ScarletDB - Replit's first real database (Python)


  • Should know what a database is.
  • Should know basic-intermediate Python.

What is a document database?

To put it simply, a document database is a type of database that works a lot like a list of JSON objects (a collection of key value pairs), but with some extra cool beans added on top. You can have multiple of these collections, which can serve different purposes. For example, here is a basic structure for storing users.

We can easily represent this in a document database.

Why should I use a document database over a JSON file or the built-in Replit database?

Document databases provide a lot more functionality than a JSON file. For example, you can get things by their values without wasting a ton of processing power.

Why ScarletDB? Isn't MongoDB better?


  • Scarlet works on replit.
  • Scarlet is more lightweight.
  • Scarlet is faster (because it works in memory).


  • Scarlet only works with Python (so far).
  • Scarlet is memory-hungry (no feasible solution, unfortunately).
  • Scarlet can't store a lot of data (but definitely enough for an average to large replit project.

Getting started

First, install Scarlet using the packages button on the sidebar. The package is called scarletdb.

Take a look at this example:

As the comments describe, we first need to create the database so we can access it. Next, we load the data from replit database (if you aren't using replit, pass data to the constructor and use db.list to store it). After that, we clear the database to give us an empty canvas. You should remove this if you want your data to persist over restarts.

Then, we insert some documents into the database. We could use db.insert many times here, passing one dict instead of a list of them, but insert_many is more concise. Now we'll update anything with the name "Jack" and change the name to "Tom".



how does scarletdb store the data in replit


@ch1ck3n It works through normal Python dicts and lists, so it can be made into a JSON string and stored in a file, replit DB and many other places.


@xfinnbar so it doesn’t actually store the data? It just stringifies it?


@RoBlockHead By default it does not store anything but you can either call db.replit() to set it up for storage in replit DB or provide your own commit (save) function and data in the constructor. For example, here is how you would set it up with a JSON file.


umm i think its private


Replit's first real database (Python)

Arguable, but regardless pretty kewl.