Skip to content

Set up a Python project

Most NJIA projects use Node and should start from the Innovation repository template. When you do need Python, use uv so the Python version, virtual environment, dependencies, and command-line tools are managed in one place.

Install uv with Homebrew:

Terminal window
brew install uv

Install uv with Astral’s standalone installer:

Terminal window
curl -LsSf https://astral.sh/uv/install.sh | sh

If curl is not available, use wget:

Terminal window
wget -qO- https://astral.sh/uv/install.sh | sh

Restart your shell after the installer finishes so your PATH is updated.

Install uv with WinGet:

Terminal window
winget install --id=astral-sh.uv -e

If WinGet is not available, use the official PowerShell installer:

Terminal window
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Confirm uv is available:

Terminal window
uv --version

Create a new Python project and pin the Python version the project should use:

Terminal window
uv init my-python-project --python 3.14
cd my-python-project
uv sync

uv init creates a pyproject.toml for dependencies and a .python-version file for the project’s Python version. uv sync creates a .venv/ virtual environment and a uv.lock lockfile.

Commit pyproject.toml, .python-version, and uv.lock. Do not commit .venv/. If .venv/ is not already in .gitignore, add it.

Add runtime dependencies with uv add:

Terminal window
uv add requests

Add development-only tools with --dev:

Terminal window
uv add --dev pytest ruff

Run project code and tools with uv run:

Terminal window
uv run python main.py
uv run pytest
uv run ruff check .

Remove a dependency with uv remove:

Terminal window
uv remove requests

After cloning a Python project that already uses uv, install the locked dependencies:

Terminal window
uv sync

Then run the project through uv run:

Terminal window
uv run python main.py

If a tool specifically requires an activated virtual environment, activate the project environment after running uv sync:

Terminal window
source .venv/bin/activate

On native Windows PowerShell, use:

Terminal window
.venv\Scripts\activate

When you are done using an activated environment, exit it:

Terminal window
deactivate

Use Python tools without polluting projects

Section titled “Use Python tools without polluting projects”

Install project dependencies into the project with uv add. Do not install project dependencies globally or into your system Python.

For one-off command-line tools, use uvx:

Terminal window
uvx checkov --version

For tools you use often and want available on your PATH, use uv tool install:

Terminal window
uv tool install checkov
uv tool install ruff

If uv warns that its tool directory is not on your PATH, run uv tool update-shell and restart your shell.

uv keeps each installed tool in its own isolated environment, which avoids the dependency conflicts that happen when many tools are installed into one global Python environment.

Some existing projects still use requirements.txt. You can install those dependencies into a local virtual environment with uv:

Terminal window
uv venv
uv pip install -r requirements.txt

For new Python projects, prefer pyproject.toml and uv.lock. To migrate dependencies from an existing requirements.txt file into a uv project, run:

Terminal window
uv add -r requirements.txt
  • Black - Python counterpart to Biome/Prettier
  • requests - HTTP library
  • IPython - a better Python terminal (allows multi-line commands)

For data analysis:

  • Pandas - lets you manipulate tables/csv equivalents in-memory. We’ve got a couple Pandas wizards at the office, so feel free to ask for help if you’re unfamiliar.
  • Jupyter Notebooks - if you want to do iterative data analysis with charts/images as output, and you don’t care about source control (it sucks with git)
  • Positron - RStudio, but for both Python and R. It’s a VSCode IDE fork that helps with doing iterative data analysis, including viewing charts + images as an output. Unlike Jupyter Notebooks, you’re still fundamentally writing a Python script and can keep that source controlled.