Simulation API
Contents
Simulation API#
Module: spp_api_v2_simulation
Overview#
REST API for simulation scenario management.
Purpose#
This module is designed to:
Manage simulation scenarios via REST API: Create, read, update, list, and archive simulation scenarios through authenticated endpoints.
Execute simulations via API: Trigger simulation runs and retrieve results including beneficiary counts and equity scores.
Compare simulation runs: Create side-by-side comparisons of multiple simulation runs with overlap analysis.
Convert scenarios to programs: Transform validated simulation scenarios into real programs with CEL eligibility and cash entitlement managers.
Module Dependencies#
Dependency |
Purpose |
|---|---|
|
OpenSPP API V2 - Standards-aligned, consent-respecting AP... |
|
Simulate targeting scenarios, analyze fairness and distri... |
|
Query engine for indicators, simulations, and GIS analytics |
Key Features#
Scenario Management#
Method |
Path |
Description |
|---|---|---|
GET |
|
List scenarios with optional state/category filters and pagination |
POST |
|
Create a new scenario with entitlement rules |
GET |
|
Get scenario details including rules, preview counts, and latest results |
PUT |
|
Update a draft scenario |
DELETE |
|
Archive a scenario (soft delete) |
Scenarios include targeting expressions, budget configuration, entitlement rules, and state management (draft -> ready -> archived).
Scenario Lifecycle Actions#
Method |
Path |
Description |
|---|---|---|
POST |
|
Transition scenario from draft to ready state |
POST |
|
Execute the simulation (requires |
POST |
|
Convert a ready scenario into a real program (requires |
Simulation Runs#
Method |
Path |
Description |
|---|---|---|
GET |
|
List simulation runs with optional scenario/state filters |
GET |
|
Get run details with beneficiary counts and entitlement totals |
Run Comparisons#
Method |
Path |
Description |
|---|---|---|
POST |
|
Create a comparison of 2+ simulation runs |
GET |
|
Get comparison results with per-run metrics and overlap data |
Templates#
Method |
Path |
Description |
|---|---|---|
GET |
|
List active pre-built scenario templates |
Analytics Endpoints#
The module also exposes analytics endpoints for querying aggregated statistics:
Method |
Path |
Description |
|---|---|---|
POST |
|
Compute aggregation with scope, statistics, and group-by dimensions |
GET |
|
List available statistics for discovery |
Scope-Based Authorization#
Scope |
Operations |
|---|---|
|
List/read scenarios, runs, comparisons, templates, analytics |
|
Create/update/archive scenarios, create comparisons |
|
Run simulations |
|
Convert scenarios to programs |
Integration#
spp_simulation: All scenario, run, and comparison business logic is delegated to the simulation models and service layer. The API module provides HTTP transport.
spp_analytics: Analytics query endpoints delegate to the
spp.analytics.servicefor unified statistics computation with access control and caching.spp_api_v2: Provides the FastAPI framework, OAuth authentication, and scope-based authorization middleware.
openspp.org