Python API guide
Everything the CLI does is a thin wrapper over a Python API, and the package exports that API deliberately. Use it when you want a build matrix, a bring-up script, a test harness, or NSX wired into a larger tool.
Every public symbol and signature is in the generated Python API reference. This page is how to start and what to watch for.
The shape of it
Section titled “The shape of it”from pathlib import Pathfrom neuralspotx import build_app, configure_app, create_app
app_dir = create_app(Path("hello_ap510"), board="apollo510_evb")configure_app(app_dir)build_app(app_dir)Most app lifecycle functions take the app directory or a request object as their first argument, with additional function options passed by keyword. Request dataclasses also accept positional fields; prefer keywords when constructing them.
There are deliberate exceptions. reset_target takes keyword arguments only;
resolve_rtt_app and rtt_app require an AppRttRequest. Module functions such as
add_module also accept a positional module name, and registry and inspection helpers
have their own signatures. Consult the generated reference for each function.
Operations report failures through exceptions rather than error-code return values.
The supported Python imports are the names in neuralspotx.__all__ and
neuralspotx.api.__all__. PathLike is available from neuralspotx.api.
Implementation packages such as neuralspotx.operations and private modules are not
extension APIs. The existing neuralspotx.api.operations attribute remains importable
for compatibility, but is not a supported export.
Two calling styles
Section titled “Two calling styles”Keyword arguments are the direct style:
build_app(app_dir, board="apollo4p_blue_kxr_evb", toolchain="armclang", jobs=16)Request dataclasses are the other, and they are better when you are building a call programmatically or passing one around:
from neuralspotx import AppBuildRequest, build_app
request = AppBuildRequest(app_dir=app_dir, board="apollo510_evb", frozen=True)build_app(request)The exported request types include: AppActionRequest,
AppBuildRequest, AppCleanRequest, AppCreateRequest, AppFlashRequest,
AppLockRequest, AppOutdatedRequest, AppSyncRequest, AppUpdateRequest,
AppViewRequest, AppRttRequest, BoardCreateRequest, ModuleChangeRequest, ModuleInitRequest,
ModuleRegisterRequest and ModuleUpdateRequest.
What comes back
Section titled “What comes back”Most operations return nothing and raise on failure. The ones with something to say return a typed object rather than parsed text:
| Call | Returns |
|---|---|
create_app |
The Path of the app it created |
doctor |
A DoctorReport |
flash_app |
A FlashResult |
reset_target |
A ResetResult |
resolve_rtt_app |
Offline RttSettings without accessing probes |
rtt_app |
A RttResult with selected probe and byte count |
add_module, remove_module, update_modules |
A list of ModuleChange |
register_module |
One ModuleChange |
from neuralspotx import doctor
report = doctor()if not report.ok: for check in report.checks: if not check.ok: print(check.label, check.hint)For bounded RTT channel 0 capture, use a typed request:
from neuralspotx import AppRttRequest, resolve_rtt_app, rtt_app
request = AppRttRequest(app_dir=app_dir, probe_serial="123456789", duration_s=10)settings = resolve_rtt_app(request) # ELF address and configured device; no probe accessresult = rtt_app(request, on_data=lambda data: print(repr(data)))The callback receives bytes and must return promptly; its exceptions propagate
after worker cleanup. request.capture creates a new byte-exact file and retains
partial data on failure. The target must already run the firmware matching the
resolved executable. See RTT capture
for installation and timing contracts.
Errors
Section titled “Errors”Everything NSX raises derives from NSXError, so one except clause is enough to catch
any NSX failure and let real bugs through:
from neuralspotx import NSXError, build_app
try: build_app(app_dir, frozen=True)except NSXError as exc: print(f"build failed: {exc}")Catch a narrower type when you intend to handle a specific case. The ten exported types
are NSXCacheError, NSXConfigError, NSXGitError, NSXIntegrityError, NSXLockError,
NSXModuleError, NSXResolutionError, NSXTimeoutError, NSXToolchainError and the
NSXError base. NSXIntegrityError is the one a --frozen equivalent raises when the
tree has drifted from the lock.
Progress output
Section titled “Progress output”Long operations accept an emit callable, which is how the CLI prints progress. Pass your
own to route events into a log. Omitting it (or passing None) uses the default
emitter: progress goes to stderr and line events to stdout. A no-op callback such as
emit=lambda event: None suppresses these events; it does not suppress every source of
output, such as separately configured subprocess or capture callbacks:
from neuralspotx import build_app, default_emitter
build_app(app_dir, emit=default_emitter)build_app and flash_app additionally take on_line, called once per line of compiler
output, which is what you want for streaming a build into a test report rather than
buffering it.
Beyond the five commands
Section titled “Beyond the five commands”The exported surface is wider than the app lifecycle. It covers modules
(list_modules, describe_module, search_modules, init_module,
validate_module_metadata), locking (lock_app, sync_app, outdated_app,
update_app), the registry (load_registry, starter_profile,
registry_module_project), boards (create_board), caches (cache_info, clean_cache),
SBOM generation (generate_sbom) and app discovery (find_app_root, resolve_app_dir).
load_registry() and starter_profile() return independent snapshots. You may edit
nested dictionaries and lists without changing later results or other callers’ data.
These edits do not persist registry overrides; use app configuration for that.
find_app_root is the one to reach for first in a script: it reproduces the walk-up that
the CLI does, so your tool resolves an app the same way nsx build would.
A build matrix
Section titled “A build matrix”The case where the API is clearly better than shelling out:
from neuralspotx import NSXError, build_app, configure_app
BOARDS = ["apollo510_evb", "apollo510b_evb", "apollo4p_blue_kxr_evb"]
for board in BOARDS: try: configure_app(app_dir, board=board, frozen=True) build_app(app_dir, board=board, frozen=True) except NSXError as exc: print(f"{board}: FAIL {exc}") else: print(f"{board}: ok")Each board builds into its own directory, so the loop does not need to clean between iterations. See Multi-target and portability.
For agents
Section titled “For agents”An agent driving NSX should not parse help text. Two commands emit structured data instead.
nsx commands --json returns the whole command tree: every command and subcommand, which
ones are aliases, and for each one its options with flags, destination, default, help
string and whether it is required. It is the machine-readable equivalent of walking every
--help.
nsx commands --jsonnsx doctor --json returns the environment report as {ok, checks[], notes}, where each
check carries label, ok, required, detail and hint. That is enough to decide
whether a build can be attempted and what to tell a user if not.
Several module commands take --json too, including nsx module list,
nsx module describe, nsx module validate and nsx outdated. The module catalog is
also published as data at
/neuralspotx/modules/catalog.json.
For anything beyond inspection, import the API rather than shelling out. You get typed
results and typed exceptions instead of exit codes and text, and find_app_root and
resolve_app_dir give you the same app resolution the CLI uses.