Skip to main content

Backend Setup

This guide walks you through setting up the Maybern Django backend for local development.
All commands in this guide should be run from within the backend/ directory unless otherwise specified.

Set Up PostgreSQL Database

1

Add PostgreSQL to PATH

Add the PostgreSQL binaries to your shell path:
echo 'export PATH="/opt/homebrew/opt/postgresql@13/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
2

Set up libpq for psycopg

The libpq library is required for the Python PostgreSQL adapter:
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
3

Create database user

Create the maybern user in PostgreSQL:
createuser maybern -d -s -r -P
When prompted for a password, enter maybern.
4

Create database

Create the maybern database with the new user as owner:
createdb maybern -O maybern
Verify the database setup by running psql -U maybern -d maybern -c '\dt'. You should connect successfully (the table list will be empty until migrations run).

Set Up Python with Pyenv

1

Configure Pyenv

Add Pyenv to your shell configuration:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
2

Install the project Python version

Install the Python version specified in the project’s .python-version file:
pyenv install < .python-version
3

Set global Python version (optional)

Set this version as your global default:
pyenv global $(cat .python-version)

Set Up uv for Dependency Management

1

Install uv

Install uv using the standalone installer:
curl -LsSf https://astral.sh/uv/install.sh | sh
Or using Homebrew:
brew install uv
2

Verify installation

Check that uv is installed correctly:
uv --version

Set Up Virtual Environment

1

Install dependencies

Create the virtual environment and install all dependencies:
uv sync
This will create a .venv directory and install all dependencies from the lockfile.
2

Activate the virtual environment

Activate the virtual environment:
source "$(pwd)/.venv/bin/activate"
Consider adding an alias to your .zshrc for quick activation:
alias activate-maybern='cd ~/path/to/maybern/backend && source .venv/bin/activate'
If uv is using the wrong Python version:
  1. Check what Python versions are available:
    uv python list
    
  2. Verify Pyenv is using the correct version:
    pyenv which python
    
  3. Pin uv to use the correct Python version:
    uv python pin "$(pyenv which python)"
    
  4. Remove the existing virtual environment and reinstall:
    rm -rf .venv
    uv sync
    

Set Up Environment Variables

Create the local .env file from the template:
DJANGO_SECRET_KEY=$(python3 -c 'from django.utils.crypto import get_random_string; print(get_random_string(50))') \
  POSTGRES_DB=maybern POSTGRES_USER=maybern POSTGRES_PASSWORD=maybern \
  DJANGO_DATABASE_HOST=localhost \
  envsubst < config/.env.template > config/.env
This is a single command that spans multiple lines. Run it as-is.
Reach out to your onboarding partner to get additional environment variables for third-party services (Stytch, AWS, etc.).

IDE Setup (VS Code / Cursor)

Install the recommended extensions for Python development:
  • Ruff: Python formatting and linting
Add to your settings.json:
{
  "[python]": {
    "editor.defaultFormatter": "charliermarsh.ruff"
  }
}
For Cursor users, also install Cursor Pyright for type checking:
{
  "cursorpyright.analysis.typeCheckingMode": "recommended"
}

Next Steps