Skip to main content
ATK Pine Script®

Library Authoring

How to publish and import reusable PyneScript V6 libraries — versioned exports, enum types, and selective import binding.

Library Contract#

  • Required: library(...).
  • Recommended: export small, reusable helpers or enum types.
  • Not expected: build_indicator_frame, build_signal_frame, or chart visuals.
  • Import through import_library(...) or library_import(...).

What a Library Should Optimize For#

Keep library code deterministic, narrow, and reusable. It should own helper logic such as length resolution, bias labeling, transform helpers, or shared signal utilities — not chart rendering or strategy mapping.

Import Functions#

library_import(name, version=None, exports=None, alias=None)#

Resolves a published ATK PyneScript library, validates exports, records metadata into script context, and returns a namespace object containing the selected callables.

import_library(spec, exports=None, alias=None)#

Convenience wrapper over library_import. Use it when the library spec already encodes the name and version information you want.

Library imports are version-aware, exported callables are discovered from the target module, missing exports raise errors, and a library cannot import itself.

Published libraries can export callables and enum types. Selective imports such as Pyne Enum Utils@1::TrendMode,resolve_length are supported in plain Python files through import_library(...). Quoted import syntax is also supported, but only after the editor preprocesses the source into valid Python.

Library Declaration and Import Pattern#

from source import library, import_library

library("Pyne Utils", version=2, overlay=False)

def plus_one(value):
    return int(value) + 1


# In another script
utils = import_library("Pyne Utils@2", exports=["plus_one"])
result = utils.plus_one(41)

Example Files#