• Stars
    star
    563
  • Rank 79,150 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python API client library for Netbox.

Pynetbox

Python API client library for NetBox.

Note: Version 6.7 and later of the library only supports NetBox 3.3 and above.

Installation

To install run pip install pynetbox.

Alternatively, you can clone the repo and run python setup.py install.

Quick Start

The full pynetbox API is documented on Read the Docs, but the following should be enough to get started using it.

To begin, import pynetbox and instantiate the API.

import pynetbox
nb = pynetbox.api(
    'http://localhost:8000',
    token='d6f4e314a5b5fefd164995169f28ae32d987704f'
)

The first argument the .api() method takes is the NetBox URL. There are a handful of named arguments you can provide, but in most cases none are required to simply pull data. In order to write, the token argument should to be provided.

Queries

The pynetbox API is setup so that NetBox's apps are attributes of the .api() object, and in turn those apps have attribute representing each endpoint. Each endpoint has a handful of methods available to carry out actions on the endpoint. For example, in order to query all the objects in the devices endpoint you would do the following:

>>> devices = nb.dcim.devices.all()
>>> for device in devices:
...     print(device.name)
...
test1-leaf1
test1-leaf2
test1-leaf3
>>>

Note that the all() and filter() methods are generators and return an object that can be iterated over only once. If you are going to be iterating over it repeatedly you need to either call the all() method again, or encapsulate the results in a list object like this:

>>> devices = list(nb.dcim.devices.all())

Threading

pynetbox supports multithreaded calls for .filter() and .all() queries. It is highly recommended you have MAX_PAGE_SIZE in your Netbox install set to anything except 0 or None. The default value of 1000 is usually a good value to use. To enable threading, add threading=True parameter to the .api:

nb = pynetbox.api(
    'http://localhost:8000',
    threading=True,
)

More Repositories

1

netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
Python
15,828
star
2

netbox-docker

🐳 Docker Image of NetBox
Python
1,800
star
3

devicetype-library

A collection of community-sourced DeviceType definitions for import to NetBox
Python
899
star
4

netbox-topology-views

A netbox plugin that draws topology views
Python
753
star
5

ansible_modules

NetBox modules for Ansible using Ansible Collections
Python
327
star
6

Device-Type-Library-Import

This library is intended to assist with importing device and module types into NetBox from the NetBox Community DeviceType-Library
Python
262
star
7

netbox-chart

A Helm chart for NetBox
Mustache
247
star
8

netbox-bgp

NetBox plugin for BGP related objects documentation
Python
242
star
9

customizations

A collection of community submitted and maintained customizations including reports, scripts, validators and export templates
Python
205
star
10

netbox-qrcode

NetBox Plugin for generate QR Codes
Python
201
star
11

go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Shell
197
star
12

awesome-netbox

A curated list of awesome NetBox resources
186
star
13

netbox-zero-to-hero

A short course designed to take new NetBox users from β€˜Zero to Hero’.
Python
149
star
14

netbox-plugin-tutorial

A tutorial on building custom plugins for NetBox v3.2+
89
star
15

netbox-acls

A NetBox plugin for Access Lists based off of the NetBox Plugin Demo
Python
86
star
16

netbox-napalm-plugin

NetBox Napalm plugin
JavaScript
49
star
17

netbox-reorder-rack

NetBox plugin to allow users to reorder devices within a rack using a drag and drop UI.
Python
45
star
18

netbox-python

Python NetBox API Client
Python
37
star
19

netbox-operator

[INCUBATING] A Kubernetes operator to manage NetBox resources directly through Kubernetes.
Go
33
star
20

cookiecutter-netbox-plugin

Cookiecutter template for easy building NetBox plugins
Python
22
star
21

netbox-healthcheck-plugin

HTML
20
star
22

netbox-demo-data

Demo data useful for populating demo instances of NetBox
19
star
23

migration-scripts

Python
10
star
24

netbox-plugin-demo

Python
7
star
25

netbox.dev-old

netbox.dev website
HTML
1
star
26

netbox-demo

A plugin for NetBox demo instances
Python
1
star