Choosing Between NetBox Plugins and Custom Scripts for Extensions
A decision guide comparing NetBox plugins and custom scripts, covering constraints, a capability matrix, trade‑offs, and step‑by‑step validation for NetBox v3.7+.
01 Sept 2025, 15:41 UTC

Decision at a Glance
When you need to extend NetBox you have two supported paths: plugins (packaged Python projects that integrate with the data model, UI, and REST API) and custom scripts (ad‑hoc Python files executed from the NetBox UI or CLI). The choice hinges on persistence, distribution, and how tightly the extension must bind to NetBox internals.
Constraints That Shape the Choice
- Plugins require a Python package, version pinning to a NetBox release, and a service restart/reload after installation.
- Custom scripts run inside the existing NetBox process via the UI or
manage.py runscript; they cannot add database tables, navigation items, or REST endpoints. - Both approaches execute with full NetBox permissions, so unsafe operations (raw SQL, arbitrary filesystem writes) must be avoided.
Supported Capabilities Comparison
| Capability | Plugin | Custom Script |
|---|---|---|
| Custom Django models & migrations | Yes | No |
| REST API endpoints | Yes | No |
| Navigation menu items & template extensions | Yes | No |
| Background tasks (RQ workers) | Yes | No |
| Read/write ORM access | Yes | Yes |
| User input forms | Via plugin views | Built‑in script form handling |
| Distribution via PyPI | Yes | No (scripts live in the repo or DB) |
| Upgrade resilience | Managed through version constraints & testing | Fragile – internal ORM may change between minor releases |
Trade‑offs
- Maintenance burden – Plugins demand packaging, CI, and compatibility testing for each NetBox version. Scripts are lightweight but must be re‑validated after every upgrade.
- Deployment cycle – Installing a plugin requires a container rebuild or
pip installpluspython manage.py migrateand a service restart. Scripts can be dropped intoscripts/and used immediately. - Auditability – Plugins live in version‑controlled repositories. Scripts stored only in the NetBox database (via the UI) lack Git history unless you use a Git‑backed script repository.
Concrete Validation: Minimal Plugin
Goal: add a SiteNote model with a REST endpoint and verify it appears in the UI and API.
- Scaffold the plugin (run on your development workstation):
mkdir -p netbox_site_note/{site_note,tests} touch netbox_site_note/site_note/__init__.py cat > netbox_site_note/site_note/models.py <<'EOF' from django.db import models from netbox.models import NetBoxModel class SiteNote(NetBoxModel): site = models.ForeignKey('dcim.Site', on_delete=models.CASCADE, related_name='notes') content = models.TextField() class Meta: ordering = ['site'] EOF - Register the model in the plugin entry point (
netbox_site_note/site_note/plugin.py):from netbox.plugins import PluginConfig class SiteNotePlugin(PluginConfig): name = 'netbox_site_note' verbose_name = 'Site Notes' version = '0.1.0' author = 'Your Name' description = 'Attach free‑form notes to sites.' base_url = 'site-notes' required_settings = [] default_settings = {} # NetBox v3.7+ expects `model_features` for REST exposure model_features = { 'SiteNote': ['api'], } - Install in a test NetBox instance (Docker Compose, NetBox v3.7):
# From the NetBox project root cd netbox-docker # Add the plugin as an editable install cat >> docker-compose.override.yml <<'EOF' services: netbox: volumes: - ./../netbox_site_note:/opt/netbox/netbox_site_note:ro EOF # Recreate the container docker compose up -d --build netbox # Inside the container docker compose exec netbox bash -c "pip install -e /opt/netbox/netbox_site_note" docker compose exec netbox python manage.py migrate docker compose restart netbox - Verify:
# Check plugin registration curl -s http://localhost:8000/api/plugins/ | jq '.[] | select(.name=="netbox_site_note")' # List the new endpoint curl -s http://localhost:8000/api/plugins/site-notes/site-notes/ | jq . # Confirm UI presence – navigate to /plugins/site-notes/ in the browser
Limitations: The plugin must declare compatible NetBox versions in install_requires (e.g., netbox>=3.7,<4.0). A breaking change in NetBox v4.0 may require updates to PluginConfig or migration handling.
Concrete Validation: Custom Script
Goal: create a device via the ORM from a script executed in the UI.
- Write the script (
scripts/create_device.py):from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site from ipam.models import IPAddress from netbox.scripts import Script, StringVar, ObjectVar class CreateDevice(Script): class Meta: name = "Create Device" description = "Provision a new device with minimal fields." site = ObjectVar(model=Site, required=True) role = ObjectVar(model=DeviceRole, required=True) manufacturer = ObjectVar(model=Manufacturer, required=True) device_type = ObjectVar(model=DeviceType, required=True) name = StringVar(required=True) def run(self, data, commit): device = Device( name=data['name'], site=data['site'], device_role=data['role'], device_type=data['device_type'], ) if commit: device.save() self.log_success(f"Created device {device}") return f"Device {data['name']} {'created' if commit else 'simulated'}" - Place the file in the NetBox container’s
scripts/directory (or a Git‑backed script repo). In Docker Compose:docker compose exec netbox bash -c "mkdir -p /opt/netbox/scripts && cat > /opt/netbox/scripts/create_device.py" < create_device.py - Execute via UI: navigate to
/scripts/, select “Create Device”, fill the form, tick Commit, and run. - Verify side‑effects:
docker compose exec netbox python manage.py shell -c " from dcim.models import Device print(Device.objects.filter(name='test-switch').exists()) "
Limitations: The script uses internal model imports that are not part of a public API; a NetBox minor upgrade can rename fields or change validation, breaking the script without warning. No automatic migration or UI integration is provided.
Practical Verification Checklist
- Spin up NetBox v3.7+ with the official Docker image (
netboxcommunity/netbox:v3.7). - For plugins:
pip install -e /path/to/plugin, runpython manage.py migrate, restart, then query/api/plugins/. - For scripts: drop
.pyintoscripts/, run via UI, inspect job results and database state withmanage.py shell. - Cross‑reference NetBox release notes for plugin API changes (e.g.,
PluginMenuButton,PluginTemplateExtension) before targeting a new version.
When to Choose Which
- Plugin – you need a reusable, versioned component that adds data models, API endpoints, or UI elements and you can invest in packaging and CI.
- Custom script – you need a one‑off operational task, rapid prototype, or data‑migration helper that does not require schema changes.
Both mechanisms are officially supported; the decision rests on longevity, distribution needs, and tolerance for upgrade‑time maintenance.