Skip to main content

NetBox API client library

Project description

Pynetbox

Python API client library for NetBox.

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

Compatibility

Each pyNetBox Version listed below has been tested with its corresponding NetBox Version.

NetBox Version Plugin Version
4.0.6 7.4.0
4.0.0 7.3.4
3.7 7.3.0
3.6 7.2.0
3.5 7.1.0
3.3 7.0.0

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,
)

Alternative Library

Note: For those interested in a different approach, there is an alternative Python API client library available for NetBox called netbox-python. This library provides a thin Python wrapper over the NetBox API.

netbox-python offers a minimalistic interface to interact with NetBox's API. While it may not provide all the features available in pynetbox, it offers a lightweight and straightforward option for interfacing with NetBox.

To explore further details and access the documentation, please visit the netbox-python.

Project details


Release history Release notifications | RSS feed

This version

7.4.0

Download files

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

Source Distribution

pynetbox-7.4.0.tar.gz (68.1 kB view details)

Uploaded Source

Built Distribution

pynetbox-7.4.0-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file pynetbox-7.4.0.tar.gz.

File metadata

  • Download URL: pynetbox-7.4.0.tar.gz
  • Upload date:
  • Size: 68.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pynetbox-7.4.0.tar.gz
Algorithm Hash digest
SHA256 fd0b1f197b3880048408ff5ed84422dd599bcd9389e32cb06a09b9b0d55c1636
MD5 52c1f3641f0779ae31236a94fafa2044
BLAKE2b-256 6477147ba1a06fd5c064ddab411bfd0d8ee86856e5723b82f7a4931e96838e4a

See more details on using hashes here.

File details

Details for the file pynetbox-7.4.0-py3-none-any.whl.

File metadata

  • Download URL: pynetbox-7.4.0-py3-none-any.whl
  • Upload date:
  • Size: 35.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pynetbox-7.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 974d93da77ad404e813bc7b3948d9664e0653262f0fb1e97715217aee062a648
MD5 e502c9a43dd795fc5ba49503fbbdbf55
BLAKE2b-256 f3b8ec860ce21476788037a9b1460a91c31d43b8742fcd1b752a660bcbbd9284

See more details on using hashes here.

Supported by

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