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
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
from replit2 import db, clear,
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
db["foo"] = "bar"
…back it up…
db.backup() # Triggers manual backup
db.restore_backup() # Optional arg: location (where is the backup file)
…use it normally…
from replit2 import audio audio.play_file("rickroll.wav")
…and use it abnormally.
# Not logged into replit import replit2 # Wouldn't work normally
- The replit module doesn’t work while not logged in
- 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.
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!