Pro API

Flask Pro API — /run with mode=auto, /optimize strategy search, plot_meta/fill, alerts + L2 webhooks, preview, backtest, and shared evaluate contract.

This page

Pro API

The PYNE Pro API is a Flask HTTP service that runs Pine scripts over caller-supplied OHLCV, returns plots / series / plot_meta (incl. fill bands) / strategy events / drawings / alerts, optional L2 alert webhooks, and gates thumbnail + backtest routes behind API keys. Default evaluate path is mode=auto (compile when safe, interpret on fallback). It is intentionally not the language server: different auth, scaling, and failure domains.

Abstract

Where the LSP answers static editor questions, the Pro API answers dynamic evaluate questions:

POST JSON { script, data: OHLCV[], mode?, libraries?, webhook_url?, … }
  → pynescript.runtime.Runtime.run  (Pro API re-export; mode default: auto)
  → { plots, series, plot_meta, events, drawings, alerts,
      mode, auto_backend?, compile_fallback_reason?,
      script_id, run_id, alert_forward?, … }

Free-tier evaluate (POST /run, POST /run/batch) validates bodies with hand-rolled schemas, enforces a 5 MB body cap, and restricts CORS. Optional bar/script/rate/concurrency guards (backend/middleware/free_limits.py) are off unless FREE_TIER_LIMITS is 1/true/yes/on. GET / and GET /health are the same unauthenticated readiness payload (features.free_tier_limits reports the switch). Optional L2 webhooks POST last-bar alert() / alertcondition() firings to webhook_url or env ALERT_WEBHOOK_URL (see Alerts). Pro routes under /preview/* and /backtest/* use track_usage (Bearer / ApiKey / query key). Chart PNGs are matplotlib Agg renders encoded as base64.

The same evaluate contract is mirrored by pyne-worker so AXIS and HOOX can swap hosts without redesigning payloads — see contract.

Conceptual model

Diagram

Rendering…

Interface surface

MethodPathAuthRole
GET/ · /healthnoneHealth + endpoint map + compile cache section
POST/runnone (free)Single-script evaluate (mode default auto; libraries[]; alerts + optional webhooks)
POST/run/batchnone (free)≤8 scripts, shared OHLCV
POST/scripts · /cron/*optional runnerHosted scripts + bar-close — off unless PYNE_RUNNER=1 (runner)
POST/optimizenone (free)Strategy input.* search — N interpret Runtime runs (docs)
WS/ws/runnone (free)Same evaluate contract over JSON frames (flask-sock optional)
POST/preview/chartAPI key + usageLine / OHLCV PNG
POST/preview/indicatorAPI key + usageExpression series PNG
POST/backtest/quickAPI key + usageQuick strategy metrics + equity PNG
POST/auth/create_keyadmin decoratorMint pyn_… key (fail-closed ADMIN_TOKEN)
GET/auth/usageAPI keyUsage counters
POST/auth/validatenone (body key)Validate without consuming quota
POST/compile/prewarmnone (free, rate-gated)Product warm-compile — skip cold Numba JIT
POST/lsp/*none (free)AXIS editor completion / hover / diagnostics
POST/api/git/oauth/device/*none (device flow)Optional GitHub/GitLab device OAuth for SPA git (blueprint)

/run response highlights

FieldRole
series / plots / plot_metaBar values + display meta (color, linewidth, kind, fill band refs)
eventsStrategy broker events
drawingsDrawing registry / compile __drawings
alertsStructured alert() / alertcondition() firings
mode / auto_backendEffective path (interpret | compile)
compile_fallback_reasonWhy auto chose interpret (eligibility or compile error)
alert_forwardPresent when a webhook URL was configured
error_kindOn failure: parse | compile | runtime | data | order | mode

Local runner: make runpython -m backend.app (default 127.0.0.1:5002).

Tracks in this tab

  1. App lifecycle — Flask app, CORS, limits, blueprints
  2. Auth and keys — tiers, stores, decorators
  3. Run · Optimize · Preview · Backtest
  4. Chart renderer
  5. Runtime bridgeRuntime / series / evaluator glue
  6. Contract — shared evaluate schema across Flask and workers

Internals (map)

PathRole
backend/app.pyApp object, /run*, /health, /compile/prewarm, /auth*, CORS
backend/api/preview.pyPreview + backtest blueprints
backend/api/git_oauth.pyOptional device OAuth for SPA git
backend/api/lsp_http.pyFree AXIS editor LSP-HTTP
backend/middleware/*Auth, schemas, free_limits, optional Redis/SQLite stores
src/pynescript/runtime/host.pyPackage SoT bar-loop (mode=auto, alerts pack)
backend/runtime.pyCompat re-export of the package host
backend/alert_forwarder.pyL2 HTTP webhook delivery
backend/evaluator.py / backend/series.pyCompat shims
backend/services/*Charts + backtest simulation

See also