[Pro API]

Flask Pro API for Pine evaluation — /run, preview, backtest, API keys, and the shared evaluate contract.

Pro API

The PYNE Pro API is a Flask HTTP service that runs Pine scripts over caller-supplied OHLCV, returns plots / series / strategy events / drawings, and gates thumbnail + backtest routes behind API keys. 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[], … }
  → backend.runtime.Runtime.run
  → { plots, series, plot_meta, events, drawings, script_id, run_id, … }

Free-tier evaluate (POST /run, POST /run/batch) validates bodies with hand-rolled schemas, enforces a 5 MB body cap, and restricts CORS. 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 edge workers (pyne-worker / pine-worker) so AXIS and HOOX can swap hosts without redesigning payloads — see contract.

Conceptual model

Interface surface

MethodPathAuthRole
GET/noneHealth + endpoint map
POST/runnone (free)Single-script evaluate
POST/run/batchnone (free)≤8 scripts, shared OHLCV
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
GET/auth/usageAPI keyUsage counters
POST/auth/validatenone (body key)Validate without consuming quota

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 · 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 factory surface, /run*, /auth*, CORS
backend/api/preview.pyPreview + backtest blueprints
backend/middleware/*Auth, schemas, optional Redis/SQLite stores
backend/runtime.pyBar-loop evaluate façade
backend/evaluator.pyCustomEvaluator bridge
backend/series.pyPineSeries history deque
backend/services/*Charts + backtest simulation

See also