TL;DR

Instantiate the Api. Use the methods available on Endpoint to return Record objects.

API

class pynetbox.api.Api(url, token=None, private_key=None, private_key_file=None, ssl_verify=True, threading=False)

The API object is the point of entry to pynetbox.

After instantiating the Api() with the appropriate named arguments you can specify which app and endpoint you wish to interact with.

Valid attributes currently are:
  • dcim
  • ipam
  • circuits
  • secrets
  • tenancy
  • extras
  • virtualization

Calling any of these attributes will return App which exposes endpoints as attributes.

Parameters:
  • url (str) – The base url to the instance of Netbox you wish to connect to.
  • token (str) – Your netbox token.
  • private_key_file (str,optional) – The path to your private key file.
  • private_key (str,optional) – Your private key.
  • ssl_verify (bool/str,optional) – Specify SSL verification behavior see: requests.
Raises:
  • ValueError – If private_key and private_key_file are both specified.
  • AttributeError – If app doesn’t exist.
Examples:
>>> import pynetbox
>>> nb = pynetbox.api(
...     'http://localhost:8000',
...     private_key_file='/path/to/private-key.pem',
...     token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.dcim.devices.all()
version

Gets the API version of NetBox.

Can be used to check the NetBox API version if there are version-dependent features or syntaxes in the API.

Returns:Version number as a string.
Example:
>>> import pynetbox
>>> nb = pynetbox.api(
...     'http://localhost:8000',
...     private_key_file='/path/to/private-key.pem',
...     token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.version
'2.6'
>>>

App

class pynetbox.api.App(api, name)

Represents apps in NetBox.

Calls to attributes are returned as Endpoint objects.

Returns:Endpoint matching requested attribute.
Raises:RequestError if requested endpoint doesn’t exist.
choices()

Returns _choices response from App

Returns:Raw response from NetBox’s _choices endpoint.
custom_choices()

Returns _custom_field_choices response from app

Returns:Raw response from NetBox’s _custom_field_choices endpoint.
Raises:RequestError if called for an invalid endpoint.
Example:
>>> nb.extras.custom_choices()
{'Testfield1': {'Testvalue2': 2, 'Testvalue1': 1},
 'Testfield2': {'Othervalue2': 4, 'Othervalue1': 3}}

Indices and tables