.replit: A beginners guide

A common misconception is the file you are currently editing is the file that will be executed when running your program. Actually, Replit is configured to execute a file by default, but were you aware these configurations could be changed?


Enter .replit, a hidden file storing the configuration of your Repl. This file’s contents can vary based on what template you chose but are usually similar regardless. These settings can be configured to gain more control over your Repl, or simply hide a couple of files.


First, navigate to a Repl you want to configure. I’d recommend choosing a template such as Python if you are following along.

Next, open the .replit file in your editor. It might not be shown in your Explorer, as it is set to be hidden. To show hidden files, find the three dots and select “Show hidden files”.

Once opened, you should have something similar to the following.

Let’s quickly go over the three important fields.


run = "python3 main.py"

By default, when using a Python Repl, this field is ignored, as long as the [interpreter] section exists, which I will get to later.

You can ignore the language field, as it does not configure your Repl’s language as you would think. I would recommend just creating a new Repl if you need to switch your language, or follow the steps below to configure run.


entrypoint = "main.py"

Likely, this is the only reason your even looking at this guide in the first place. This field sets the default file to be executed when the Run button is used. It also sets the file that should be opened by default when you open the workspace. If you want to switch to another file you have been working on, replace it with its filename. For example, if I wanted to run a Pygame project I’ve been working on, but it’s not in main.py, I can change entrypoint to execute another file, like so:

entrypoint = "pygame.py"

Fun fact: Python will actually interpret files, even if they don’t have the .py extension. However, you should always name Python files with .py or another native file extension.


hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]

Another very nice feature of .replit, allows you to configure the hidden files within your project. Let’s say you had a .gitignore, but found it annoying to navigate through your files with it showing, just add it to the list!

hidden = [".gitignore", "venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]

Once “Show hidden files” is turned back off, .gitignore should now be hidden, along with any other files you choose to hide.


And that’s basically everything you need to know! However, in some cases, you might be facing issues when dealing with entrypoint, and need to take more control over your Repl.

I was facing a problem recently, where I had set entrypoint within another directory, like so:

entrypoint = "src/boot.py"

My script needed to create some files and folders, but it ended up creating them inside of the project’s root directory, instead of the script’s, causing many problems. I did end up finding a fix for this, but it can also be used for some other very nice purposes as well.


A quick disclaimer, if you’re not facing my issue, and want to try the following for a different reason, note that you do need to know Linux/Bash to configure it correctly, or at least your language’s shell command.

First, scrap the entire [interpreter] section. Delete everything until [env], but make sure to delete the env variable!

Second, delete the entrypoint field at the beginning of the file, as run will now configure as expected.

Let me explain run in further detail. run, upon running using the button, will execute a set bash command. This can be used to control your Repl much further than before. If you wondering, the fix to my problem was to simply cd into the src/ folder, and then run boot.py after, which can be done like so:

run = "cd src/ && python boot.py"

Which should fix the problem I had if you were wondering.

You could also set this command to run a Bash script, like so, and edit the script to run multiple shell commands, like logging to a file or executing multiple files, one after the other.

run = "sh bashScript.sh"
# OR
run = "bash bashScript.sh"

You can also take a look at the documentation on configuring a Repl:

https://docs.replit.com/programming-ide/configuring-repl


Anyway, I hoped that gave you an idea of some of the capabilities of .replit! This guide was fairly short and not very well structured, so TL4s, maybe make this a wiki so people can adjust as needed?

Good luck with your configuring journeys!

7 Likes

This is a great resource for people just starting out! Thanks for posting it.

1 Like