| name | policyengine-api-v2 |
| description | PolicyEngine API v2 - Next-generation microservices architecture with monorepo structure |
PolicyEngine API v2
The next-generation PolicyEngine API is a monorepo containing multiple microservices built with modern Python tooling.
For Users 👥
What is API v2?
API v2 is the next generation of the PolicyEngine API, currently in active development. When complete, it will replace the current Flask API with a more scalable, maintainable microservices architecture.
Status: 🚧 Active development (not yet in production)
Key improvements over v1:
- Microservices architecture for better scalability
- Modern Python tooling (Python 3.13+, uv package manager)
- Docker-based development and deployment
- Auto-generated OpenAPI specs and clients
- Supabase for database management
For Analysts 📊
When to Use v2
Currently, analysts should continue using the v1 API at https://api.policyengine.org.
API v2 is not yet ready for production use. Check the repository README for the latest status.
For Contributors 💻
Repository
Location: PolicyEngine/policyengine-api-v2
Clone:
git clone https://github.com/PolicyEngine/policyengine-api-v2
cd policyengine-api-v2
Architecture Overview
API v2 is a monorepo containing multiple microservices:
To see current structure:
tree -L 2 .
Microservices
1. api-full (port 8081)
- Main API service
- Household calculations
- Policy management
- Most endpoints from v1
2. api-simulation (port 8082)
- Economic simulation engine
- Population-wide impact calculations
- Resource-intensive operations
3. api-tagger (port 8083)
- Deployment management
- Version tagging
- Release coordination
Technology Stack
To see current dependencies:
cat api-full/pyproject.toml
cat api-simulation/pyproject.toml
cat api-tagger/pyproject.toml
Key technologies:
- Python 3.13+ - Latest Python version
- uv - Fast Python package manager
- Docker + Docker Compose - Local development and deployment
- Supabase - PostgreSQL database with auth
- OpenAPI - API specification generation
- FastAPI or Flask - (check current implementation)
Development Setup
To start all services locally:
cat docker-compose.yml
docker-compose up
Alternative: Run individual service:
cd api-full
uv pip install -e .
python main.py
Package Management with uv
API v2 uses uv instead of pip for faster dependency management:
To see current uv usage:
cat pyproject.toml | grep -A 5 "tool.uv"
find . -name "uv.lock"
Common uv commands:
uv pip install -e .
uv add package-name
uv sync
Supabase Integration
To see current Supabase setup:
cat .env.example | grep SUPABASE
grep -r "supabase" . --include="*.py" | head -10
grep -r "create_client" . --include="*.py"
Common patterns:
from supabase import create_client
supabase = create_client(supabase_url, supabase_key)
result = supabase.table('policies').select('*').execute()
supabase.table('policies').insert({'data': policy}).execute()
Design Tokens Integration
API v2 may integrate with design tokens from policyengine-app-v2:
To check design token usage:
grep -r "design.*token\|designTokens" . --include="*.py"
grep -r "@policyengine/design" package.json
cat package.json | grep -A 5 "dependencies"
If using npm design tokens:
npm install @policyengine/design-tokens
OpenAPI Specification
To see current API spec generation:
grep -r "openapi\|swagger" . --include="*.py"
find . -name "openapi*.json" -o -name "openapi*.yaml"
Testing
To see current test setup:
ls -la tests/
cat pytest.ini
Run tests:
pytest
cd api-full && pytest
docker-compose run api-full pytest
Migration from v1
Key architectural differences:
| Aspect | v1 (Flask monolith) | v2 (Microservices) |
|---|
| Structure | Single Flask app | Multiple services |
| Database | Redis + Cloud SQL | Supabase (PostgreSQL) |
| Deployment | Google App Engine | Docker containers |
| Package manager | pip | uv |
| Python version | 3.9+ | 3.13+ |
To understand migration patterns:
git log --grep="migrate\|port" --oneline
Common Development Tasks
Task 1: Add New Endpoint to api-full
-
Find current endpoint pattern:
ls api-full/endpoints/
cat api-full/endpoints/example.py
-
Follow the pattern (likely FastAPI or Flask)
-
Update OpenAPI spec (may be auto-generated)
-
Add tests:
cat tests/test_endpoints.py
Task 2: Work with Supabase
cat supabase/migrations/*.sql
docker-compose up supabase
Task 3: Use Design Tokens
grep -r "design.*token" .
Environment Variables
To see required environment variables:
cat .env.example
Monorepo Best Practices
To see current monorepo structure:
ls -d */
ls shared/ common/ lib/
grep -r "../api-" pyproject.toml
Pattern:
- Each service should be independently deployable
- Shared code goes in
shared/ or similar
- Each service has its own tests
- Docker Compose for local multi-service development
Related Skills
- policyengine-api-skill - v1 API patterns (for migration reference)
- policyengine-core-skill - Understanding the simulation engine
- policyengine-us-skill - Country model integration
- policyengine-design-skill - Design tokens and branding
- policyengine-standards-skill - Code quality standards
Resources
Repository: https://github.com/PolicyEngine/policyengine-api-v2
Related:
Development Status
⚠️ Important: API v2 is in active development. Always check the repository README for:
- Current status and roadmap
- Breaking changes
- Migration timeline from v1
- Deployment instructions
To see current status:
cat README.md
git log -10 --oneline