Skip to main content

CLI for API sandboxes. Test your APIs in a sandbox env.

Project description

api-sandbox

Create a sandbox from your OpenAPI spec.

Use api-sandbox when you need to:

  • give partners a stable test endpoint
  • require API key or bearer authentication in the sandbox
  • test state changes, timers, and webhooks
  • inspect traces when an integration fails

Install

Recommended:

pipx install api-sandbox

Homebrew:

brew tap digitalapicraft/api-sandbox-cli https://github.com/digitalapicraft/api-sandbox-cli && brew install api-sandbox

If you already manage your own virtual environment:

python -m pip install api-sandbox

Requirements:

  • Python 3.12+

Verify the install:

sdb --help

For the hosted customer path, export your control-plane token before the first hosted command:

export API_SANDBOX_TOKEN=<REAL_CONTROL_PLANE_TOKEN>

The first interactive hosted command offers to create the default customer profile pointed at https://api.sandbox.digitalapi.ai.

Choose a guide

If you want to... Start here
Publish a sandbox from a spec Publisher quickstart
Connect to a sandbox as a consumer Consumer quickstart
Test stateful flows, timers, and webhooks Simulation runbook
See the end-to-end flow first Overview

Publish your first sandbox

This example creates bearer auth once, then publishes a sandbox in one command and returns a connect_url.

sdb auth create-profile payments-sim \
  --mode simulated \
  --scheme BearerAuth=bearer

sdb policy create refunds-only

sdb --output json publish ./payments.yaml \
  --sandbox bank-sim \
  --auth-profile payments-sim \
  --policy-pack refunds-only

After publish succeeds, copy publish.connection.connect_url from the JSON response. That is the consumer entry point.

Hosted control-plane commands fail fast if no control-plane token source is configured.

Protect endpoints with auth and scopes

Use an auth profile to define how consumers authenticate in the sandbox. Use a policy pack to enforce scopes.

For example, this flow creates bearer auth and a scope-aware release:

sdb auth create-profile payments-sim \
  --mode simulated \
  --scheme BearerAuth=bearer

sdb policy create refunds-only

sdb --output json publish ./payments.yaml \
  --sandbox bank-sim \
  --auth-profile payments-sim \
  --policy-pack refunds-only

Consumers can then:

  • discover the auth configuration from the sandbox alias
  • issue scoped credentials
  • exchange a bearer token
  • call protected endpoints with the saved session

Connect as a consumer

This example creates an app, issues client credentials, connects once, logs in, and sends a request.

sdb auth create-app bank-sim partner-app \
  --alias latest \
  --auth-profile payments-sim \
  --scheme BearerAuth

sdb auth issue-client partner-app \
  --sandbox bank-sim \
  --scope refunds.read

sdb connect <CONNECT_URL>

printf '%s\n' "<CLIENT_SECRET>" | sdb auth login \
  --client-id <CLIENT_ID> \
  --client-secret-stdin \
  --scope refunds.read

sdb sandbox request GET /refunds/ref_123

Consumer discovery, login, and request commands use the same hosted product URL: https://api.sandbox.digitalapi.ai.

Use these commands to inspect or clear saved sessions:

sdb connection show
sdb auth session list
sdb --yes auth session clear --expired

Test stateful integrations

Use simulation mode when the response should change over time.

Common cases:

  • banking flows such as deposits, credits, refunds, and disputes
  • commerce flows such as order creation, shipment updates, and cancellations
  • SaaS workflows such as tenant provisioning, entitlement changes, and delayed jobs
  • webhook-based integrations that need repeatable event delivery
  • negative-path testing for retries, failures, and time-based transitions

Simulation mode lets you:

  • seed known state for a sandbox
  • apply named scenarios
  • capture and restore snapshots
  • advance the sandbox clock explicitly
  • trigger deterministic timers
  • verify emitted webhook events

Example: credit an account and verify a webhook

This example creates a simulation sandbox, applies a scenario, advances time, and checks the emitted event.

sdb sandbox create banking-sim --api "Retail Banking API" --mode simulation

sdb simulation create-pack retail-banking-sim \
  --kind scenario_v1 \
  --seed 'getAccount@{"account_id":"{account_id}","balance":100,"status":"pending"}' \
  --scenario '{"scenario_id":"credit-ladder","name":"Credit ladder","state_patches":[{"path":"/accounts/{account_id}","body":{"status":"credited","balance":250}}]}'

sdb release create banking-sim \
  --spec "Retail Banking API@2026-04-18" \
  --simulation-pack retail-banking-sim

sdb release list --sandbox banking-sim
sdb release promote banking-sim --alias latest --release <SIM_RELEASE_ID>

sdb simulation snapshot create banking-sim --name pre-credit

sdb simulation webhook create banking-sim \
  --destination capture://partner-a \
  --event account.updated.demo

sdb simulation scenario apply banking-sim \
  --scenario credit-ladder \
  --binding account_id=acc_123 \
  --binding run_id=demo

sdb simulation timer list banking-sim
sdb simulation clock advance banking-sim --to 2026-04-18T20:00:00Z
sdb simulation event list --sandbox banking-sim --type account.updated.demo

Use snapshots and reset to rerun the same flow:

sdb simulation snapshot list banking-sim
sdb --yes sandbox reset banking-sim

Inspect requests and failures

Use traces to see what a consumer sent and how the sandbox handled the request.

sdb trace tail bank-sim --limit 10
sdb trace list --sandbox bank-sim
sdb trace get <TRACE_ID>
sdb trace replay <TRACE_ID>

This is useful when you need to:

  • confirm the request path and method
  • check whether auth or scope enforcement blocked the request
  • replay a failing request against the sandbox

More guides

Video walkthrough

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

api_sandbox-0.1.6.tar.gz (108.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

api_sandbox-0.1.6-py3-none-any.whl (142.9 kB view details)

Uploaded Python 3

File details

Details for the file api_sandbox-0.1.6.tar.gz.

File metadata

  • Download URL: api_sandbox-0.1.6.tar.gz
  • Upload date:
  • Size: 108.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for api_sandbox-0.1.6.tar.gz
Algorithm Hash digest
SHA256 273340ce24d7ff5a4efb700987a7a2e54688db6e8eabb50c49cfd90934ebf46b
MD5 46eb645a69b8a7da7d1355a97627d3d0
BLAKE2b-256 d9d2b98f22c29ea7e0d35dd87195130939eca37fbc5117df65e64acba9010e35

See more details on using hashes here.

File details

Details for the file api_sandbox-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: api_sandbox-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 142.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for api_sandbox-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bccc7d3b65aa8f9514156231e6d747c2c38563a5123f3a970d9ec9c5034d86ae
MD5 a69138db9b904deef16b6c1bba802d7b
BLAKE2b-256 d5a46f4cd26bad04e866959ecd45a759f531fe4e3028e65f16bcabe25f9fac28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page