In this tutorial, you will learn how to set up a development environment for Python.
In the environment, you can use uv for package management BasedPyright as the language server. It is basic but sufficient for navigating an existing code base with LSP, and can be effortlessly added to an existing project.
Initialize a new project
Make
uv
executable available:Terminal window nix shell nixpkgs#uvUse
uv init
to create a new project:Terminal window uv init sample_app --bareEnter the directory:
Terminal window cd 'sample_app'
Below are extra steps to create a minimal Streamlit application. Actual steps would be dependent on the type of application you are creating.
Add streamlit to the Python project:
Terminal window uv add streamlitCreate
app.py
:Terminal window import streamlit as st_ = st.title("My First Streamlit App with uv")st.write("Hello, Streamlit!")
Add flake.nix to the project
Initialize the template from the root directory of the project:
Terminal window nix flake init github:akirak/flake-templates#python-uv-simpleAdd
.envrc
:Terminal window use flakeAllow direnv:
Terminal window direnv allow
For the sample streamlit application, also add pkgs.streamlit
to the development shell in flake.nix
.
Developing
Use uv
to develop the Python project as you would normally do without Nix.
Depending on the dependencies of your Python project, you might need to take extra steps. Follow instructions in the NixOS Wiki.
To build the project with Nix, follow the instructions in Nixpkgs Reference Manual.
The sample streamlit application can be run with the following command:
streamlit run app.py