Skip to main content

Dynamic NetBox CLI generated from the live OpenAPI schema.

Project description

netbox-super-cli (nsc)

A Python CLI for NetBox that builds its command tree dynamically from your install's live OpenAPI schema. The same binary works against any NetBox version and exposes plugin-provided endpoints automatically — the schema, not hand-written code, defines the surface.

Docs: thomaschristory.github.io/netbox-super-cli — the full guide, including install, first-run, guides, and the auto-generated CLI/config/exit-code reference.

Status: Phase 3 complete (v0.3.0-phase3). The full read + safe-write surface is shipped: dynamic command tree, dry-run-by-default writes with --apply to commit, --explain for resolved-request introspection, bulk-endpoint detection with loop fallback, stable error envelopes with locked exit codes, append-only audit log, and a live-NetBox e2e suite running in CI against netboxcommunity/netbox:v4.5.9. Not yet on PyPI.

Why

  • Plugins just work. If your install has plugins, their endpoints appear as commands automatically.
  • Multi-instance. Named profiles per NetBox instance, plus env-var overrides.
  • Safe by default. POST/PATCH/PUT/DELETE preview as dry-runs unless you pass --apply.
  • Agent-friendly. Deterministic command shape, machine-readable JSON output, stable error envelope with documented exit codes.

Install (preview)

uv tool install netbox-super-cli

Not on PyPI yet; install from source:

git clone https://github.com/thomaschristory/netbox-super-cli
cd netbox-super-cli
uv sync
uv run nsc --version

Reading

export NSC_URL=https://netbox.example.com
export NSC_TOKEN=$(cat ~/.netbox-token)

uv run nsc dcim devices list
uv run nsc dcim devices list --site-id 42 --status active --all --output json
uv run nsc dcim devices get 7
uv run nsc circuits providers list --output csv
uv run nsc ipam prefixes list --filter created__gte=2026-01-01 --output yaml

Writing

# Dry-run by default — shows the resolved request without sending it.
uv run nsc dcim devices create -f device.yaml --explain

# Commit with --apply.
uv run nsc dcim devices create -f device.yaml --apply

# Bulk create: one HTTP call when the schema supports it, sequential loop otherwise.
uv run nsc dcim devices create -f devices.yaml --apply
uv run nsc dcim devices create -f devices.yaml --no-bulk --on-error continue --apply

# NDJSON / JSONL — one record per line; parse failures abort the whole batch
# before any wire request fires (`type: input_error`, exit 4, `details.bad_lines`).
uv run nsc dcim devices create -f devices.ndjson --apply
cat devices.ndjson | uv run nsc dcim devices create -f - --apply

# Per-field overrides (CLI wins over file on overlap).
uv run nsc dcim devices update 42 --field status=active --apply

# Delete; default is exit-0 if already gone, --strict turns missing-id into exit 9.
uv run nsc dcim devices delete 42 --apply
uv run nsc dcim devices delete 42 --apply --strict

Every write attempt — dry-run included — appends one line to ~/.nsc/logs/audit.jsonl; the most recent exchange is also mirrored to ~/.nsc/logs/last-request.json.

Bulk input formats

Form File extension or stdin shape Routing
YAML mapping .yaml / .yml Single record.
YAML list .yaml / .yml Bulk: one record per list item.
JSON object .json or {...}EOF on stdin Single record.
JSON array .json or [...] on stdin Bulk: one record per array item.
NDJSON .ndjson / .jsonl or {...}\n{...} on stdin Bulk: one record per line.

Stdin is sniffed from the first 512 bytes (first non-whitespace byte plus a one-object lookahead for newline-then-{). NDJSON parse failures collect up to 20 bad_lines and abort before any wire request; --no-bulk still forces a loop fallback for any bulk shape.

Audit log sensitivity

audit.jsonl is confidential (not secret). It records what was sent — record-level data your account had write access to. The CLI redacts:

  • HTTP headers in the SENSITIVE_HEADERS set (e.g. Authorization, X-API-Key) — replaced with "<redacted>".
  • Request-body fields whose OpenAPI definition has format: password OR whose name (case-insensitive) is one of: password, secret, token, api_key, apikey, private_key, passphrase, client_secret. Nested fields and arrays of objects are walked recursively.

The wire body sent to NetBox is not redacted — only the audit log. A failed write still records the redacted body; redaction is irreversible. Treat audit.jsonl like a verbose application log: gate it behind your home-directory permissions and rotate / archive accordingly. A "redact everything" mode is deferred to Phase 5+.

Output and errors

  • --output {table,json,yaml,csv,jsonl}. Table is the default on a TTY; JSON is the default when stdout is piped.
  • On --output json, the records array is emitted directly (no NetBox-style count/results wrapper); single-record writes emit the resulting record dict.
  • Failures emit a stable ErrorEnvelope (JSON to stdout on --output json, Rich panel to stderr otherwise) with type ∈ {auth, not_found, validation, conflict, rate_limited, server, transport, schema, config, client, internal, ambiguous_alias, unknown_alias, input_error} and a documented exit code per type. See CHANGELOG.md and the spec for the full table.

Schema introspection

# Dump every endpoint in the bundled NetBox schema as JSON.
uv run nsc commands --schema nsc/schemas/bundled/netbox-4.6.0-beta2.json.gz --output json | head

# Or against a live install.
uv run nsc commands --schema https://netbox.example.com/api/schema/?format=json --output json

Cache management

The on-disk command-model cache lives at ~/.nsc/cache/<profile>/<schema-hash>.json and is regenerated automatically when the live NetBox schema changes. Over time, removed profiles or upgraded NetBox versions can leave orphan entries behind.

nsc cache prune                          # show what would be deleted (dry-run)
nsc cache prune --apply                  # actually delete
nsc cache prune --max-age 30 --apply     # also delete cache files older than 30 days
nsc cache prune --output json            # structured envelope for scripts

What gets pruned:

  1. Cache directories for profiles that are no longer in your config.
  2. Cache files whose schema-hash differs from the live NetBox schema (skipped per-profile when offline).
  3. With --max-age <days>: cache files older than the threshold (excludes files already covered by rule 1).

The adhoc cache directory (used by env-var-only invocations like NSC_URL=… nsc dcim devices list) is never pruned automatically.

Shell completion

nsc ships static completion stubs that complete subcommands and option names.

nsc --install-completion         # auto-detects $SHELL
nsc --show-completion            # prints the script instead of installing

Typer supports bash, zsh, fish, and pwsh. Completion of dynamic values (resource names, profile names, filter keys) is on the post-1.0 roadmap.

Bundled Skill for AI agents

nsc ships a portable Skill bundle at skills/netbox-super-cli/SKILL.md that briefs an AI agent on how to drive nsc correctly (dry-run discipline, JSON output, error envelope, audit log).

nsc skill install --target claude-code            # dry-run; prints the destination
nsc skill install --target claude-code --apply    # actually copies

Targets: claude-code, codex, gemini, copilot. Where a target has no documented programmatic install path, the helper prints actionable manual instructions instead of guessing.

License

Apache 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netbox_super_cli-1.0.0.tar.gz (598.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netbox_super_cli-1.0.0-py3-none-any.whl (449.3 kB view details)

Uploaded Python 3

File details

Details for the file netbox_super_cli-1.0.0.tar.gz.

File metadata

  • Download URL: netbox_super_cli-1.0.0.tar.gz
  • Upload date:
  • Size: 598.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for netbox_super_cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fbd342354717a131436369f1e6cc964acc006184a79863d3db6ec4228c631ee7
MD5 9f7c4b72078ea99617a456c02b570cb4
BLAKE2b-256 1e8d2b4178567b9530f4a66820f062e1d5bc146310c197c88a76d9f0e615f5f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for netbox_super_cli-1.0.0.tar.gz:

Publisher: release.yml on thomaschristory/netbox-super-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file netbox_super_cli-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for netbox_super_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34deb648e7289328845b376d5fc212518eddd94de43b7218f77f33f4259c00c6
MD5 e7670c02ca8a4dd58149236eafa4241d
BLAKE2b-256 ce9bb5f7121b0c280455d73645282897d0c144b381fc3d76961cab2afa52801d

See more details on using hashes here.

Provenance

The following attestation bundles were made for netbox_super_cli-1.0.0-py3-none-any.whl:

Publisher: release.yml on thomaschristory/netbox-super-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page