Introducing "The Better Replit": a drop-in replacement for the "replit" module


Introducing the replit2 module, which is an improved version of the current replit package with extra bug fixes and improvements. Designed as a drop-in replacement, you can just change replit to replit2 in your imports to reap the benefits.
This release includes:

  • Database Backups
  • Graceful DB Errors
  • Support for non-repliters
  • and more!
    Its Github repository is linked below.


To install, you can go to the Packages tab and add replit2 as a dependency, or go the the Shell tab and execute…

pip install replit2


To use replit2’s DB and other features, you can simply import it (just like you would with the original replit module…

from replit2 import db, clear, 

…configure it…

db = db.start(backup="mybackup.json", backup_mode=0)
# backup: location of the backup file (default ".config/db_backup.json")
# backup_mode: method of backups. 
#    -1 = Never, 0 = on-write, n (pos int) = every n seconds

…use it…

db["foo"] = "bar"

…back it up…

db.backup()  # Triggers manual backup

…restore it…

db.restore_backup()  # Optional arg: location (where is the backup file)

…use it normally…

from replit2 import audio

…and use it abnormally.

# Not logged into replit
import replit2  # Wouldn't work normally

Why I created this


  1. The replit module doesn’t work while not logged in
  2. The replit database is stored off-repl


To address issue number one, I found that by importing anything from the replit package, it required the DB module to activate and a database update thread to be in progress. However, the DB doesn’t exist when the user is not logged in, which would eventually cause an error when the anonymous user tries to the the program, even if the program only needs an innocuous function such as replit.clear. By fixing this error, I allow the anonymous user to have an ephemeral database (a normal dict that isn’t saved) while preventing the other parts of the replit package from being unusable.
For issue number two, I implemented two methods: Database.backup, and Database.load_backup, which dump the database to a json file and replaces the database with the json file, respectively.

How to help me help you

If you have any bug reports, do not hesitate to submit a bug report here (or on github)! Errors that have not been encountered cannot be fixed, so your contribution would be greatly appreciated!

1 Like

Edit: ensure that you have replit2==3.2.6

It’s actually

Overall, well done! (I could make the same thing, though)