New Python Template

This week, we’re rolling out a new Python Template. Please try it out and give us your feedback in this topic or email us devex@replit.com.

With 32M forks, the old Python Template was the most popular Template at Replit. It also had some issues:

  • Critical programs like pip, poetry, and python, were installed in the venv directory. If you deleted the directory or uninstalled these programs, your Repl wouldn’t work.
  • The runtime, packager, and code intelligence were frozen in time. If you wanted the newest version of Python or the code intelligence (language server), you needed to fork the Template from scratch.
  • It was hard to use other languages alongside Python in the same Repl.

This new template uses Nix Modules to solve these problems. With Nix Modules, many entries in the .replit file bundled into one modules entry in the .replit file like


modules = ["python-3.10:v18-20230807-322e88b"]

Here, the module identified by python-3.10:v18-20230807-322e88b contains:

  • the Python 3.10 runtime

  • our Prybar interpreter for Python

  • a state of the art Python language server

  • a Python debugger

  • our UPM packager as well as poetry and pip for installing pypi packages

With modules, we can deliver updates to your Python experience. Previously, when you forked a Template, your experience did not change unless you knew how to update the .replit file yourself. With this new Template, you’ll get automatic upgrades for the code intelligence and patch updates to Python.

One difference in the new Python Template is when you install Python packages, they will be installed in a hidden directory named .pythonlibs. It does not use virtual environments as the previous Template did, but instead uses the user install feature to install into that directory.

This week we’ll be rolling it out to 50% of general users of the Python Template. Soon, we’ll roll it out to 100%.

We’d appreciate it if you take the time to try it out and report back to us below.

14 Likes

Hi @tobyho , this looks great!
I would like to know, what is the difference between Beta and Beta LSP?

5 Likes
7 Likes

I have just tried it and it seems very nice. I hope it will take less storage space for small projects.

Is there a way to convert old Python projects to use this template without copying everything ?
Thanks

4 Likes

In most cases you can replace your .replit with this content:

entrypoint = "main.py"
modules = ["python-3.10:v18-20230807-322e88b"]

hidden = [".pythonlibs"]

[nix]
channel = "stable-23_05"

[deployment]
run = ["sh", "-c", "python3 main.py"]

Reload it (just in case), and test if it works. If you want to be safe, you can backup your .replit first.
The replit.nix and venv will be unnecessary now, and you can delete them.

5 Likes

Thanks, I’ll try it,
but I have a small issue : it seems that the Repls with the new template don’t start when I try to access them…
Is it normal ? I can give you an example if you want to test : a small Flask Example which doesn’t start when i try to access it while it always worked before… Maybe it’s an issue not related to the new template

3 Likes

Could you share a link to your Repl?

I have just created a Repl with Beta LSP and it works fine
https://replit.com/@fvillemin/RosybrownBeneficialDatasets
But the one with the new Template doesn’t work :
https://replit.com/@fvillemin/teststart

It seems to start quickly then stop

2 Likes

I just tried forking the one you say doesn’t work and it seems to work for me. What do you see that doesn’t work?

Well, if i don’t run it before trying to access the URL, it doesn’t start.
And it is the same for all Repls created with the new template. If I take the old template BetaLSP it works fine…
Maybe it’s just a bad coincidence but I can’t manage to have new template running when accessing the web url

I tried a few times but couldn’t reproduce the problem you are describing. Could you record a short screencast of the problem with loom or similar to show us what you are seeing? Or even a screenshot may help clarify.

1 Like

If you try to access the hosting URL without first going to the workspace and running the repl:

1 Like

I’m trying with screenshots :
first i create a Repl with Beta python template

Then I’m using ghostwriter to make a very small flask app

I’m running it to “configure” the Repl : it is ok, running

The url : https://testforstart.fvillemin.repl.co

I will Stop the Repl and then go to my Chrome and try to access the url. It should start it
but I get Unable to wake up and it doesn’t start

If I do the exact same steps with Beta LSP template
https://testbeta.fvillemin.repl.co
It works perfectly … When someone uses the Url, it is starting the Repl if it was stopped

Maybe that’s a coincidence but I can reproduce it everytime

2 Likes

Thank you @fvillemin and @UMARismyname! That clarifies what the problem is. I will investigate this today.

2 Likes

Update: a PR is in the works. We should be able to deploy the fix today or tomorrow.

3 Likes

@fvillemin and @UMARismyname, to my eye, this has been fixed. Could you test it again to verify?

3 Likes

Hello,
yes it works for my example.
I have created a new Repl with the same procedure and it works too. Excellent !
Can we have a small explanation about why it did not work ? it seems so strange that a new template would disable another different feature :frowning: and strange too that not so many people complained about that :slight_smile:
I also helps us to trust repl.it and know wthat we can now use this new tool without any risk
Thanks

2 Likes

Sure thing! When you click the “run” button, the Replit workspace sends a “run” command to the Repl. The Repl runs your program and starts the process. If you hit the web URL of your web server without having first started the process, our proxy web server first sends a “run” command to the Repl to “wake it up”.

Nix modules added some 2 new parameters to the “run” command, in particular, a runner ID - identifying how to run the program given it’s file extension, and a file path - the file to run. This gives us flexibility to support multiple programming languages in the same Repl. The workspace would figure out what runner ID and file path to send while you are developing, but this broke the wake up process because it did not know what parameters to send.

We fixed this by re-implementing some logic of the workspace in the backend so that even when those parameters are not provided, the Repl can infer them based on the module that’s active and the entrypoint specified in .replit.

3 Likes

Oh great, thanks for your precise explanation
I’m happy to have helped to find and correct this bug :slight_smile:
I’m going to use the new template now
Thanks

3 Likes