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
Section titled “Install uv”Install uv with Homebrew:
brew install uvWSL and Linux
Section titled “WSL and Linux”Install uv with Astral’s standalone installer:
curl -LsSf https://astral.sh/uv/install.sh | shIf curl is not available, use wget:
wget -qO- https://astral.sh/uv/install.sh | shRestart your shell after the installer finishes so your PATH is updated.
Native Windows
Section titled “Native Windows”Install uv with WinGet:
winget install --id=astral-sh.uv -eIf WinGet is not available, use the official PowerShell installer:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Verify the installation
Section titled “Verify the installation”Confirm uv is available:
uv --versionCreate a project
Section titled “Create a project”Create a new Python project and pin the Python version the project should use:
uv init my-python-project --python 3.14cd my-python-projectuv syncuv 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 dependencies
Section titled “Add dependencies”Add runtime dependencies with uv add:
uv add requestsAdd development-only tools with --dev:
uv add --dev pytest ruffRun project code and tools with uv run:
uv run python main.pyuv run pytestuv run ruff check .Remove a dependency with uv remove:
uv remove requestsWork on an existing project
Section titled “Work on an existing project”After cloning a Python project that already uses uv, install the locked dependencies:
uv syncThen run the project through uv run:
uv run python main.pyIf a tool specifically requires an activated virtual environment, activate the project environment after running uv sync:
source .venv/bin/activateOn native Windows PowerShell, use:
.venv\Scripts\activateWhen you are done using an activated environment, exit it:
deactivateUse 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:
uvx checkov --versionFor tools you use often and want available on your PATH, use uv tool install:
uv tool install checkovuv tool install ruffIf 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.
Work with older requirements files
Section titled “Work with older requirements files”Some existing projects still use requirements.txt. You can install those dependencies into a local virtual environment with uv:
uv venvuv pip install -r requirements.txtFor new Python projects, prefer pyproject.toml and uv.lock. To migrate dependencies from an existing requirements.txt file into a uv project, run:
uv add -r requirements.txtUseful tools
Section titled “Useful tools”- 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.
