TL;DR

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

API

class pynetbox.core.api.Api(url, token=None, private_key=None, private_key_file=None, 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.

Additional Attributes:
  • http_session(requests.Session):
    Override the default session with your own. This is used to control a number of HTTP behaviors such as SSL verification, custom headers, retires, and timeouts. See custom sessions for more info.
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.
  • threading (bool,optional) – Set to True to use threading in .all() and .filter() 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()
openapi()

Returns the OpenAPI spec.

Quick helper function to pull down the entire OpenAPI spec.

Returns:dict
Example:
>>> import pynetbox
>>> nb = pynetbox.api(
...     'http://localhost:8000',
...     private_key_file='/path/to/private-key.pem',
...     token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.openapi()
{...}
>>>
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.core.app.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

Note

This method is deprecated and only works with NetBox version 2.7.x or older. The choices() method in Endpoint is compatible with all NetBox versions.

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