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

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:

text
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
GET/statsnoneProcess runtime counters, latencies, gauges (docs)
POST/runnone (free)Single-script evaluate (mode default auto; libraries[]; from_bar/to_bar; alerts + optional webhooks)
POST/run/batchnone (free)≤8 scripts, shared OHLCV
POST/sessionnone (free)Live session — O(1) ticks, O(delta) appends (docs)
GET/POST/DELETE/session/<id> · …/tick · …/appendnone (free)Advance / inspect / release a live session
GET/POST/data/series · /data/series/bars · /data/series/provide · /data/series/fetchAPI keyEngine-owned OHLCV store (docs)
POST/data/session · /data/session/<id>/tickAPI keyLive session bound to a stored series
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 run → python -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 · Live sessions · Data plane · Stats
  4. Optimize · Preview · Backtest · Runner
  5. Chart renderer
  6. Runtime bridge — Runtime / series / evaluator glue
  7. Contract — shared evaluate schema across Flask and workers

Internals (map)

PathRole
backend/app.pyApp object, /run*, /session*, /data/session*, /health, /stats, /compile/prewarm, /auth*, CORS
backend/api/preview.pyPreview + backtest blueprints
backend/api/data_series.pyEngine-owned OHLCV store routes
backend/api/datafeed.pyCCXT gateway + WS /datafeed/watch
backend/datafeed_app.pyStandalone compose datafeed app (same blueprint)
backend/datastore/*SQLite OHLCV store, session ↔ series binding
backend/middleware/sessions.pyProcess-local live-session store (TTL + capacity)
backend/middleware/window.pyapply_window — response windowing
backend/logging_setup.pyPYNE_DEBUG level policy
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 key stores
src/pynescript/runtime/host.pyPackage SoT bar-loop (mode=auto, sessions, alerts pack)
src/pynescript/stats.pyRuntime counter / latency / gauge registry
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