Skip to content
Sign upLog in
← Back to Community

How To Use Repl's Database

Profile icon
Michael8910

Repl.it has its own way of saving information called Repl Database. It is very easy to use and is great for making Log In Systems. In this tutorial, you will learn how to use repl's database by making a login system.

Before you can start using its functionality you will need to import it. You can do that by putting in

from replit import db

this will then install the database into your code.

The next thing you would want to do is create an area yourself where the user will be able to type in what they want their username or nickname to be. Have an input variable for what they decide to use. Next, you will need to add that input variable to the DB.

username = input()

Now, let's add a value that we want to save to this user.

value = input()
db["username"] = "value"

You can make the value anything you want. It could be money, coins, XP, etc. As you can see that when we set the keys they are the same as the input names.

Now that we have a way of creating an account now let's be able to log in.

LogUser = input()
GetValue = db["LogUser"]

Now we have a way of getting the user's value. You can implement this however you would like.

Voters
Profile icon
Mara-SimonaSimo
Profile icon
BrianCronin
Profile icon
mesostables
Profile icon
EL-12MD-680103
Profile icon
EpicCoderGuy1
Profile icon
McJoe21
Profile icon
EdwardBentler
Profile icon
IsaacRichardson
Profile icon
AnishAgrawal1
Profile icon
Baconman321
Comments
hotnewtop
Profile icon
Montrouze

what if the computer accesing this code is unable to install the database?

I'm asking this question cuz my friend cant install it :/

Profile icon
PrinceOfHeaven

Pretty good! I like the idea and I'm trying to use a log in system in a game I'm creating. Could you tell me how to implement username and password system?

Profile icon
bigboyyyyyyyy69

@PrinceOfHeaven
I know this is a late response but I found this cool so I went ahead and made a SIMPLE example of this..
check it out here

Profile icon
Michael8910

@bigboyyyyyyyy69
yea cool. What I did when I made my stuff is made the username a key, the password a value and then the password also a key to save user information

Profile icon
bigboyyyyyyyy69

@MikeJMS8910
epic, I made this earlier tbh idk if I did that or not but none the less it works, although would you happen to know any db error handler code such as on key not found or smth (whatever it is obvi that code wont work).. it's good for checking if user exists like the example I put rather than just trying for an exception since an exception could be raised due to another error in the code.

Profile icon
PrinceOfHeaven

[email protected]

@MikeJMS8910
but as you know something do not have repl database. I want to do something like this on pycahrm. Do you know how?

Profile icon
Michael8910

@PrinceOfHeaven
the only other one that I learned was pickle and repls db

Profile icon
PrinceOfHeaven

@bigboyyyyyyyy69

Profile icon
bigboyyyyyyyy69

@PrinceOfHeaven
nah idk how to use pycharm tbh but u can use that code to implement it.

Profile icon
RhinoRunner

I like it, but you probably should use markdown to make your post a little bit better (such as putting 3 backticks before your code)

Profile icon
Michael8910

@RhinoRunner
ok ill make that change