[CLI Commands Reference]

Complete option reference for the pynescript Click CLI: parse-and-dump, parse-and-unparse, lint, data, and download-builtin-scripts.

CLI Commands Reference

Abstract

Machine-oriented reference for every command registered on the pynescript Click group in src/pynescript/__main__.py. For workflows and pipelines, see the CLI guide. The language server is a separate console script (pynescript-lsp) and is documented under Editors.

Conceptual model

pynescript [--version] COMMAND [ARGS]...
CommandShort help (Click)
parse-and-dumpParse pinescript file to AST tree.
parse-and-unparseParse pinescript file and unparse back to pinescript.
download-builtin-scriptsDownload builtin scripts.
lintLint Pine Script file for issues.
dataFetch market data from providers.

Global:

pynescript --help
pynescript --version

Version source: package version option on the Click group (@click.version_option()), aligned with pynescript.__about__.__version__.

Interface surface

pynescript parse-and-dump

Parse a file and print an AST dump.

KindNameType / defaultDescription
argumentPATHexisting readable fileInput .pine path
option--encodingstr, default utf-8File text encoding
option--indentint, default 2Indent width for dump
option--output-filepath or -, default -Output path; - = stdout

Semantics: parse(text, filename) then dump(node, indent=indent); write with same encoding.

Examples:

pynescript parse-and-dump strategy.pine
pynescript parse-and-dump strategy.pine --indent 4 --output-file tree.txt
pynescript parse-and-dump strategy.pine --encoding utf-8 --output-file -

Exit codes: Click/path errors non-zero; uncaught parse exceptions propagate (non-zero).


pynescript parse-and-unparse

Parse a file and emit regenerated source.

KindNameType / defaultDescription
argumentPATHexisting readable fileInput path
option--encodingstr, default utf-8Text encoding
option--output-filepath or -, default -Output path; - = stdout

Semantics: parseunparse → write.

Examples:

pynescript parse-and-unparse messy.pine
pynescript parse-and-unparse messy.pine --output-file clean.pine

pynescript lint

Lint a file or stdin.

KindNameType / defaultDescription
argumentPATHoptional stringFile path; omit or - for stdin
option--encodingstr, default utf-8File encoding (ignored for stdin)
option--fixflagAttempt to fix issues where possible
option--fail-onchoice errors|warnings|all, default errorsNon-zero exit threshold

Semantics:

  1. Read source (stdin if PATH is missing or -).
  2. warnings = lint_script(source, filename).
  3. If empty → print No issues found. and return.
  4. Print each issue with emoji prefix by severity; print summary count.
  5. Raise click.ClickException when threshold met:
--fail-onFails when
errorsany severity == "error"
warningsany error or warning
allany issue

Examples:

pynescript lint strategy.pine
pynescript lint --fail-on warnings strategy.pine
pynescript lint --fail-on all strategy.pine
pynescript lint -
cat strategy.pine | pynescript lint
pynescript lint --encoding utf-8 strategy.pine

Issue line format (via LintWarning.__str__):

{severity}: [{code}] {message} at line {n}|unknown location

CLI prefixes (error) or ⚠️ (other).


pynescript data

Fetch market data for a symbol and print a short summary.

KindNameType / defaultDescription
argumentSYMBOLstringTicker / market symbol
option--providermock|yahoo|alphavantage|ccxt, default mockBackend
option--periodstr, default 1ye.g. 1d, 1w, 1mo, 3mo, 6mo, 1y, 2y, 5y
option--intervalstr, default 1de.g. 1m, 5m, 15m, 30m, 60m, 1d, 1w
option--api-keystr, default ""Alpha Vantage or CCXT
option--secretstr, default ""CCXT secret
option--exchangestr, default binanceCCXT exchange id

Semantics:

  1. Build provider kwargs (AV demo key warning if missing; CCXT exchange/key/secret).
  2. get_provider(provider, **kwargs).fetch(symbol, period, interval).
  3. Print symbol, bar count, first/last close, average volume.

Examples:

pynescript data AAPL
pynescript data AAPL --provider=yahoo --period=6mo
pynescript data EUR/USD --provider=alphavantage --api-key=YOUR_KEY
pynescript data BTC/USDT --provider=ccxt --exchange=binance

Errors: DataProviderErrorClickException with message.

Deps: ccxt providers require pip install "pynescript[data]".


pynescript download-builtin-scripts

Download TradingView® reference scripts used for tests/corpus.

KindNameType / defaultDescription
option--script-dirwritable directory pathRequired. Destination (e.g. tests/data/builtin_scripts)

Semantics: pynescript.util.pine_facade.download_builtin_scripts(script_dir).

Examples:

pynescript download-builtin-scripts --script-dir tests/data/builtin_scripts
pynescript download-builtin-scripts --script-dir /tmp/pine_corpus

Notes: Network-dependent; not required for ordinary desk use.


Related: pynescript-lsp (not a subcommand)

pynescript-lsp
python -m pynescript.langserver

Entry: pynescript.langserver.__main__:mainPynescriptLanguageServer().start_io().

Internals (repo paths)

ItemPath
CLI groupsrc/pynescript/__main__.py
Script entrypyproject.toml[project.scripts] pynescript = ...
parse/dump/unparsesrc/pynescript/ast/helper.py
lintsrc/pynescript/ast/linter.py
datasrc/pynescript/util/data.py
downloadsrc/pynescript/util/pine_facade.py

Invariants & edge cases

  • File arguments for parse commands use click.Path(exists=True, file_okay=True, dir_okay=False)no directory recursion.
  • lint deliberately accepts a free string path so stdin modes work; invalid paths surface as open errors.
  • Dump indent is passed as integer spaces to dump(..., indent=indent).
  • Output files are opened with Click open_file (creates/truncates as applicable).
  • There is currently no pynescript evaluate / pynescript run CLI subcommand — evaluation is library or HTTP.

Worked examples

CI lint gate

set -euo pipefail
for f in "$@"; do
  pynescript lint --fail-on errors "$f"
done

Normalize and re-dump for structural snapshot tests

pynescript parse-and-unparse in.pine --output-file /tmp/norm.pine
pynescript parse-and-dump /tmp/norm.pine --indent 2 --output-file /tmp/norm.ast

Offline data smoke

pynescript data TEST --provider mock --period 1mo --interval 1d

Failure modes

SituationResult
Missing input fileClick path validation error
Parse error in dump/unparsePython traceback / non-zero
Lint threshold exceededError: Lint failed with ...
Provider failureError: <DataProviderError message>
Missing --script-dirClick missing option error
Unknown providerClick choice validation error

See also