Toggle Menu Icon
Working with Python

Dev Environment

Python Development with uv

I recommend using uv for Python installation and package management. It’s an extremely fast Python package manager written in Rust that replaces pip, virtualenv, pyenv, and more in a single tool.

Installing uv

On macOS and Linux:

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

On Windows:

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

Or with Homebrew:

brew install uv

Installing Python

With uv, you can install and manage Python versions easily:

# Install the latest Python version
uv python install

# Install a specific version
uv python install 3.12

# List available and installed versions
uv python list

Creating Projects

Start a new Python project:

# Create a new project
uv init my-project
cd my-project

# Add dependencies
uv add requests flask

# Run your code
uv run app.py

For existing projects, create a virtual environment:

uv venv
source .venv/bin/activate  # On macOS/Linux
# or
.venv\Scripts\activate     # On Windows

Visual Studio Code / Cursor Setup

I recommend using Visual Studio Code as your primary Python editor, or Cursor if you want that AI goodness. Both provide excellent Python support with extensions and built-in features.

Essential Extensions

Install these extensions for the best Python development experience:

VS Code Settings

Here are example settings for your VS Code settings.json to auto format on save, using Ruff for both linting and formatting:

{
    "python.defaultInterpreterPath": ".venv/bin/python",
    "python.terminal.activateEnvironment": true,
    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        }
    },
    "ruff.fixAll": true,
    "ruff.organizeImports": true
}

Formatting and Linting with Ruff

Ruff is a fast Python linter and formatter written in Rust. It can handle both code formatting and linting in a single tool, making it simpler than using separate tools like Black. With the extension installed, it will automatically format your code on save and show errors and warnings inline.

You can also run ruff from the command line:

# Install ruff in your project
uv add --dev ruff

# Run the linter
uv run ruff check .

# Auto-fix issues
uv run ruff check --fix .