Complete guide to set up Python Secrets for local development.
Before starting, ensure you have the following installed:
- Node.js: Version
^18.20.2 || >=20.9.0- Check version:
node --version - Download: nodejs.org
- Check version:
- pnpm: Version
^9 || ^10(required - do not use npm or yarn)- Install:
npm install -g pnpm - Check version:
pnpm --version
- Install:
- Git: For cloning the repository
Why pnpm? This project uses pnpm for efficient disk space usage and faster installs. The package.json has pnpm-specific configurations.
Supabase provides the PostgreSQL database and is required for the application to run.
- Create Account: supabase.com
- Create Project:
- Click "New Project"
- Choose organization (or create one)
- Set project name (e.g.,
python-secrets-dev) - Set database password (save it securely)
- Choose region closest to you
- Click "Create new project"
- Get Connection String:
- Go to Project Settings → Database
- Find "Connection string" section
- Copy the URI format (not the Transaction pool)
- Replace
[YOUR-PASSWORD]with your database password - Format:
postgresql://postgres.[YOUR-PROJECT-REF]:[YOUR-PASSWORD]@aws-0-[region].pooler.supabase.com:6543/postgres
E2B provides server-side Python execution in isolated environments. The playground is currently development-only and will be removed in production.
- Create Account: e2b.dev
- Get API Key:
- Go to Dashboard → API Keys
- Copy your API key
- Environment Variable: The E2B SDK automatically reads the
E2B_API_KEYenvironment variable
git clone <repository-url>
cd python-secrets-2pnpm installNote: This may take a few minutes as pnpm installs all dependencies including Payload CMS, Next.js, and other packages.
Payload CMS requires TypeScript types generation for type safety:
pnpm payload generate:typesThis creates payload-types.ts based on your collection configurations.
Copy the example environment file:
cp .env.example .envEdit .env and set the following variables:
# PostgreSQL Connection String (from Supabase)
DATABASE_URL=postgresql://postgres.[YOUR-PROJECT-REF]:[YOUR-PASSWORD]@aws-0-[region].pooler.supabase.com:6543/postgres
# Alternative format with individual parameters (also supported):
# POSTGRES_USER=postgres
# POSTGRES_PASSWORD=[YOUR-PASSWORD]
# POSTGRES_HOST=aws-0-[region].pooler.supabase.com
# POSTGRES_PORT=6543
# POSTGRES_DATABASE=postgres# Secret for Payload CMS (generate a secure random string)
PAYLOAD_SECRET=your-secure-random-string-here-min-32-charsGenerate PAYLOAD_SECRET:
openssl rand -base64 32
# Or use: node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"# E2B API Key for server-side Python execution
E2B_API_KEY=e2b_[your-api-key-here]# Base URL of your application (for auth callbacks)
NEXT_PUBLIC_APP_URL=http://localhost:3000If you're using Better Auth for authentication, you may need:
# Better Auth configuration
BETTER_AUTH_SECRET=your-auth-secret-here
BETTER_AUTH_URL=http://localhost:3000/api/authNote: These variables depend on your Better Auth setup. Check src/lib/auth.ts and src/lib/auth-client.ts for required variables.
# Database
DATABASE_URL=postgresql://postgres.abc123:password@aws-0-us-east-1.pooler.supabase.com:6543/postgres
# Payload CMS
PAYLOAD_SECRET=your-generated-secret-here-minimum-32-characters-long
# E2B (Python Execution)
E2B_API_KEY=e2b_k1234567890abcdefghijklmnopqrstuvwxyz
# Application
NEXT_PUBLIC_APP_URL=http://localhost:3000
# Better Auth (if configured)
BETTER_AUTH_SECRET=your-auth-secret
BETHER_AUTH_URL=http://localhost:3000/api/authThe database schema is automatically managed by Payload CMS. Tables will be created on first run.
- Verify Connection: Ensure your
DATABASE_URLis correct - Run the Application: Start the dev server (see below)
- Auto-Migration: Payload will automatically create tables on first startup
No manual migrations needed - Payload CMS handles schema synchronization.
If you have seed scripts for development (e.g., sample courses, lessons):
# Check if seed script exists
pnpm db:seed
# Or manually run seed files if availableNote: Seed scripts may not be implemented yet. Check with the team for data seeding procedures.
pnpm devThe application will start on http://localhost:3000
Expected Output:
▲ Next.js 15.4.10
- Local: http://localhost:3000
- Network: http://192.168.x.x:3000
✓ Ready in 2.3s
- Frontend: http://localhost:3000
- Payload Admin: http://localhost:3000/admin
- Playground (dev-only): http://localhost:3000/playground
- Navigate to http://localhost:3000/admin
- You should see the Payload CMS login screen
- Create your admin account (first user becomes admin)
- If Payload admin loads, the database connection is working
- Tables were automatically created in your Supabase database
- Verify in Supabase Dashboard → Table Editor
- Navigate to http://localhost:3000/playground
- Write a simple Python code:
print("Hello World") - Test both compilers:
- Pyodide (Client): Runs in browser, no API needed
- E2B (Server): Requires valid
E2B_API_KEY
Expected Result: Both should display Hello World in the output panel.
- Sign up through the frontend at
/signupor/login - Verify user appears in Supabase Dashboard → Authentication → Users
- Verify user appears in Payload Admin → Users collection
# Start development server
pnpm dev
# Start fresh (clears .next cache)
pnpm devsafe
# Build for production
pnpm build
# Start production server
pnpm start
# Lint code
pnpm lint
# Run tests
pnpm test
# Or separately:
pnpm test:int # Integration tests (Vitest)
pnpm test:e2e # End-to-end tests (Playwright)# Generate TypeScript types from collections
pnpm payload generate:types
# Generate import map for better module resolution
pnpm payload generate:importmap
# Open Payload CLI
pnpm payload# TypeScript type checking (not in package.json but recommended)
npx tsc --noEmitError: connection refused or authentication failed
Solutions:
- Verify
DATABASE_URLis correct - Check Supabase project is not paused
- Ensure password doesn't contain special characters that need URL encoding
- Try connecting from Supabase Dashboard's SQL Editor to verify credentials
Error: Cannot find module './payload-types.ts'
Solution:
pnpm payload generate:typesError: 401 Unauthorized or E2B_API_KEY not found
Solutions:
- Verify
E2B_API_KEYis set in.env - Check the key is valid in E2B Dashboard
- Restart dev server after adding the key
- Note: Playground is dev-only, you can use Pyodide (client) without E2B
Error: Port 3000 is already in use
Solutions:
# Find process using port 3000
lsof -i :3000
# Kill the process
kill -9 <PID>
# Or use a different port
PORT=3001 pnpm devError: Cannot find module '...'
Solutions:
- Delete
node_modulesand reinstall:rm -rf node_modules pnpm install
- Ensure you're using
pnpm, notnpmoryarn - Check
package.jsonhas the dependency
Solutions:
- Check browser console for errors
- Clear
.nextcache:pnpm devsafe - Verify
PAYLOAD_SECRETis set - Check database connection (see Database Connection Issues above)
Error: TypeScript or build errors during pnpm build
Solutions:
# Regenerate Payload types
pnpm payload generate:types
# Type check to see specific errors
npx tsc --noEmit
# Clear cache and rebuild
rm -rf .next
pnpm buildAfter setup is complete:
- Read Architecture: ARCHITECTURE.md - Understand the codebase structure
- Project Structure: PROJECT_STRUCTURE.md - Learn about folder organization
- Collections: COLLECTIONS.md - Database schema and data models
- API: API.md - Custom API routes and endpoints
- Compilers: COMPILERS.md - Python execution system
If you encounter issues not covered here:
- Check the documentation in the
docs/folder - Review the codebase for examples
- Check Payload CMS docs: payloadcms.com/docs
- Check Next.js docs: nextjs.org/docs
- Check E2B docs: e2b.dev/docs