This library is intended to be your friend and help you import all the device-types defined within the NetBox Device Type Library Repository.
Tested working with NetBox 3.2+ through 4.5+ (weekly CI run against NetBox
main)
⚠️ direnv users — This repo ships a.envrc.examplefile. If you use direnv, review the file before enabling it:cp .envrc.example .envrc cat .envrc # confirm it only loads .env vars and syncs uv direnv allowThe file exclusively loads variables from
.envinto your shell and runsuv syncto keep dependencies up to date. Your.envrcis git-ignored.
This script will clone a copy of the netbox-community/devicetype-library repository to your
machine to allow it to import the device types you would like without copy and pasting them
into the NetBox UI.
-
Install dependencies with
uv:uv sync
-
Copy
.env.exampleto.envand fill in your NetBox URL and API token (the token needs write rights):cp .env.example .env vim .env
-
Run the script:
uv run nb-dt-import.py
Running the script clones (or updates) the netbox-community/devicetype-library repository
into the repo subdirectory (configurable via REPO_PATH), then loops over every manufacturer
and device, creating anything that is missing from NetBox while skipping entries that already exist.
| Variable | Required | Default | Description |
|---|---|---|---|
NETBOX_URL |
✅ | — | URL of your NetBox instance |
NETBOX_TOKEN |
✅ | — | API token with write access |
REPO_URL |
community library | Git URL of the device-type library to clone | |
REPO_BRANCH |
master |
Branch to check out | |
REPO_PATH |
./repo |
Local path where the library is cloned. Accepts absolute or relative paths. | |
IGNORE_SSL_ERRORS |
False |
Set True to skip TLS verification (dev only) |
|
GRAPHQL_PAGE_SIZE |
5000 |
Items per GraphQL page | |
PRELOAD_THREADS |
8 |
Threads for concurrent component preloading |
⚠️ Tokens: Please note there is a difference in setting the token based on whether you are using v1 or v2 tokensFor v1, your token will simply be the secret part generated when you create the api token in netbox:
NETBOX_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFor v2 tokens, you need to include prefix "nbt_", the bearer key (represented here by capital X-es), a dot, and finally the secret token (represented by lowercase x-es):
NETBOX_TOKEN=nbt_XXXXXXXXXXXX.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This script provides ways to selectively import devices via --vendors and --slugs arguments.
To import only devices from one vendor, or multiple vendors:
uv run nb-dt-import.py --vendors apc
uv run nb-dt-import.py --vendors apc,juniper--slugs does partial matching on each device type's slug and supports multiple values:
uv run nb-dt-import.py --slugs x440-g2 # Imports 11 network switch device type variations
uv run nb-dt-import.py --slugs ap4433a,ap7526 # Imports two specific PDUs--vendors and --slugs can be combined:
uv run nb-dt-import.py --vendors "Palo Alto" --slugs 440By default, the script only creates new device types and skips existing ones. To update existing device types:
uv run nb-dt-import.py --updateThis will:
- Add new components (interfaces, power ports, etc.) that are in YAML but missing from NetBox
- Update properties of existing components if they've changed
- Update device type properties (u_height, part_number, etc.) if they've changed
- Report components that exist in NetBox but are missing from YAML (won't delete by default)
WARNING: Removing components can affect existing device instances in NetBox.
If you've changed a device type definition (for example, converting interfaces to module-bays to support SFP modules), you can remove obsolete components with:
uv run nb-dt-import.py --update --remove-componentsThis will delete any components (interfaces, ports, bays, etc.) that exist in NetBox but are no longer present in the YAML definition.
Use cases:
- Converting fixed interfaces to module-bays for modular devices
- Removing incorrectly defined components from device templates
- Cleaning up after major device type definition changes
Important considerations:
- Components attached to actual device instances may prevent deletion
- Review the change detection report before enabling component removal
- Test on a staging NetBox instance first if possible
We're happy about any pull requests!
MIT