Script library
Save, load, import/export Pine scripts via local IndexedDB, cloud Worker, or git (GitHub/GitLab).
This page
Script library
The script library is the operator-facing surface of storage plugins. The editor holds the working document; the library is durable, named documents with metadata.
Abstract
| Backend | Id | Medium | Auth |
|---|---|---|---|
| Local | local | IndexedDB (pynescript.axis.storage), LS fallback | none |
| Cloud | cloud | Worker /api/scripts (D1 or memory) | Bearer Pro API key |
| Git | git | GitHub/GitLab Contents API | PAT |
Active backend: store.activePlugins.storage (Settings or library picker).
Conceptual model
Rendering…
Service layer (listScripts, readScript, writeScript, …) never talks to engines.
Interface surface
Manager → Script Library:
| Control | Behavior |
|---|---|
| Backend select | Prompts to copy scripts onto the new engine (source is never deleted) |
| Refresh | list() |
| Name / description | Metadata for next write |
| Save | Write current editor doc |
| Load | read → inject editor (loadLibraryDoc / setDoc) |
| Delete | remove |
| Export JSON | Full library dump |
| Import JSON | Bulk write (importLibraryJson) |
| Cloud endpoint + key | Settings → Script storage and this panel. Saved under pluginsConfig['storage:cloud'] |
| Version history | Every engine (local snapshots, Worker revisions, git commits). Open / Restore on a card |
| Git fields | provider, token, owner, repo, branch, basePath, … |
Status line: backend · remote · branch · connected · count.
Pine Script™ v6 starter pack
Repo ships a portable library dump of v6 indicators, strategies, and helpers:
| Path | Role |
|---|---|
examples/script-library-starter.json | Importable library JSON (//@version=6 scripts: RSI, MACD, ATR, MTF, sessions, math lib, …) |
Import: Manager → Script Library → Import JSON → pick the file (or any prior export). Uses importLibraryJson with new ids so it merges into the active backend (local / cloud / git).
Prefer //@version=6 for new scripts; engines accept v5/v6 when the runtime supports them.
Local backend
- DB name
pynescript.axis.storagev1 storesscripts+kv - Older library keys migrate once
- Drafts: optional
saveDraft/loadDraftwithout polluting remote backends - Works fully offline
Invariant: browser profile wipe deletes local library—export JSON for backup.
Cloud backend
Authorization: Bearer <api_key>- Scripts partitioned by key hash on Worker
- Concurrent updates may use
If-Match/ revision → HTTP 409 on conflict - Default endpoint falls back to
store.endpointorhttp://127.0.0.1:8787
Configure key in library panel or Settings-related config; keys stay in this browser’s localStorage state blob.
Git backend
| Invariant | Detail |
|---|---|
| Save commits | Each write/remove is a commit (+ push via API) |
| Drafts local | No remote commit for draft buffer |
| basePath | Default pine-library/ |
| Providers | github, gitlab (+ self-hosted apiBaseUrl) |
Token scopes: GitHub contents:write; GitLab api or write_repository.
Published libraries (import emulator)
library("Name") scripts can be published as versioned folders so other scripts can import owner/Name/1 as alias:
{basePath}/published/index.json
{basePath}/published/{namespace}/{Name}/{version}/lib.pyne
{basePath}/published/{namespace}/{Name}/{version}/manifest.json
- Library panel → Publish library (or a successful Run of a
library()— auto, skipped if unchanged). - Namespace defaults to the git owner, else
user. - Local cache always updates so Pyodide / offline runs resolve imports.
- The engine receives
{namespace, name, version, source}and pyne registers them beforeimport(interpret path).
Worked examples
Solo offline library
- Storage = local
- Write indicator in editor
- Name
sma-ribbon→ Save - Reload page → Library → Load
Team cloud
- Admin creates key on Worker
- Storage = cloud; paste endpoint + key
- Save shared strategies
- Second browser: same key → list
Research monorepo
- Storage = git; GitHub owner/repo; basePath
research/pine - Save → commit message from template
- PR review on GitHub UI
Internals
| Path | Role |
|---|---|
src/ui/ScriptLibraryPanel.tsx | UI |
src/storage/service.ts | Facade |
src/storage/local.ts | IDB |
src/storage/cloud.ts | Worker API |
src/storage/git.ts | Git plugin |
src/storage/git-github.ts, git-gitlab.ts | Forges |
examples/script-library-starter.json | Pine v6 starter pack |
Contract: Plugin types StoragePlugin.
Failure modes
| Symptom | Cause | Mitigation |
|---|---|---|
| Empty list after switch | Wrong backend / auth | Check status line + key |
| 401 cloud | Bad/missing key | Regenerate; re-save config |
| 409 cloud | Revision conflict | Re-read then write |
| Git 404 | Wrong owner/repo/basePath | Fix config |
| Quota local | Huge scripts in LS fallback | Prefer IDB; export prune |