Script library

Save, load, import/export Pine scripts via local IndexedDB, cloud Worker, or git (GitHub/GitLab).

This page

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.

Script Library panel with local IndexedDB storage

Abstract

BackendIdMediumAuth
LocallocalIndexedDB (pynescript.axis.storage), LS fallbacknone
CloudcloudWorker /api/scripts (D1 or memory)Bearer Pro API key
GitgitGitHub/GitLab Contents APIPAT

Active backend: store.activePlugins.storage (Settings or library picker).

Conceptual model

Diagram

Rendering…

Service layer (listScripts, readScript, writeScript, …) never talks to engines.

Interface surface

Manager → Script Library:

ControlBehavior
Backend selectPrompts to copy scripts onto the new engine (source is never deleted)
Refreshlist()
Name / descriptionMetadata for next write
SaveWrite current editor doc
Loadread → inject editor (loadLibraryDoc / setDoc)
Deleteremove
Export JSONFull library dump
Import JSONBulk write (importLibraryJson)
Cloud endpoint + keySettings → Script storage and this panel. Saved under pluginsConfig['storage:cloud']
Version historyEvery engine (local snapshots, Worker revisions, git commits). Open / Restore on a card
Git fieldsprovider, token, owner, repo, branch, basePath, …

Status line: backend · remote · branch · connected · count.

Panel conventions

The docked panel is tuned for a 300px column:

  • Search — / focuses it, Esc clears it, and every match is highlighted in card titles and descriptions.
  • Built-in tab — star a card to pin it into a Pinned group; category headers collapse (counts update). Recently applied built-ins appear in a Recent strip for one-click re-apply, and an applied script shows an on chart chip.
  • Personal tab — sort Recent / Name / Storage, filter by kind, and pinned scripts float to the top. Each card has Load, version history, and a ··· row for Copy Pine, Duplicate, and Delete.
  • Save composer — prefills the name from the editor's indicator() / strategy() / library() title; description and Publish library live under Description · publish.
  • Import / export — compact icon actions next to the storage picker; both also appear in the Personal empty state.

Built-in studies (always in the app)

Original AXIS Pine catalog — apply from Scripts → Built-in or ⌘K Add built-in script…. Not TradingView® templates. See Built-in scripts.

Pine Script™ v6 starter pack

Repo ships a portable library dump of v6 language examples (libraries, enums, MTF):

PathRole
examples/script-library-starter.jsonImportable library JSON (//@version=6 helpers + sample studies)

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.storage v1 stores scripts + kv
  • Older library keys migrate once
  • Drafts: optional saveDraft / loadDraft without 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.endpoint or http://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

InvariantDetail
Save commitsEach write/remove is a commit (+ push via API)
Drafts localNo remote commit for draft buffer
basePathDefault pine-library/
Providersgithub, 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:

code
{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 before import (interpret path).

Worked examples

Solo offline library

  1. Storage = local
  2. Write indicator in editor
  3. Name sma-ribbon → Save
  4. Reload page → Library → Load

Team cloud

  1. Admin creates key on Worker
  2. Storage = cloud; paste endpoint + key
  3. Save shared strategies
  4. Second browser: same key → list

Research monorepo

  1. Storage = git; GitHub owner/repo; basePath research/pine
  2. Save → commit message from template
  3. PR review on GitHub UI

Internals

PathRole
src/ui/ScriptLibraryPanel.tsxUI
src/ui/library/cards.tsxBuilt-in / personal cards + version history
src/ui/library/prefs.tsPinned scripts + recent built-ins (localStorage)
src/ui/library/format.tsSearch, sort, highlight, name suggestion
src/ui/library/library.cssPanel design (command bar, cards, empty states)
src/storage/service.tsFacade
src/storage/local.tsIDB
src/storage/cloud.tsWorker API
src/storage/git.tsGit plugin
src/storage/git-github.ts, git-gitlab.tsForges
examples/script-library-starter.jsonPine v6 starter pack

Contract: Plugin types StoragePlugin.

Failure modes

SymptomCauseMitigation
Empty list after switchWrong backend / authCheck status line + key
401 cloudBad/missing keyRegenerate; re-save config
409 cloudRevision conflictRe-read then write
Git 404Wrong owner/repo/basePathFix config
Quota localHuge scripts in LS fallbackPrefer IDB; export prune

See also