Skip to content

API

pynautobot.core.api

pynautobot.core.api.Api

Bases: object

The Api object is the primary entry point for interacting with a Nautobot instance using pynautobot.

Parameters:

Name Type Description Default
url str

The base URL of the Nautobot instance you want to connect to.

required
token str

Your Nautobot authentication token.

None
threading bool

Enable threading for .all() and .filter() requests. Defaults to False.

False
max_workers int

The maximum number of worker threads to use for .all() and .filter() requests. Defaults to the number of CPU cores.

4
api_version str

Override the default Nautobot REST API version used for all requests.

None
retries int

The number of retries for HTTP status codes 429, 500, 502, 503, and 504. Defaults to 0 (no retries).

0
verify bool

Whether to verify SSL certificates. Defaults to True.

True

Attributes:

Name Type Description
dcim

An instance of the App class providing access to DCIM endpoints.

ipam

An instance of the App class providing access to IPAM endpoints.

circuits

An instance of the App class providing access to Circuits endpoints.

tenancy

An instance of the App class providing access to Tenancy endpoints.

extras

An instance of the App class providing access to Extras endpoints.

virtualization

An instance of the App class providing access to Virtualization endpoints.

users

An instance of the App class providing access to User endpoints.

http_session Session

The underlying HTTP session object used for making requests to Nautobot. You can override the default session with your own to control HTTP behavior such as SSL verification, custom headers, retries, and timeouts. See the documentation on custom sessions for more information.

Raises:

Type Description
AttributeError

If an invalid application name is provided.

Examples:

>>> import pynautobot
>>> nb = pynautobot.api(
...     'http://localhost:8000',
...     token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.dcim.devices.all()

version property

Retrieves the version of the Nautobot REST API that the connected instance is using.

This method can be helpful for checking API compatibility and determining if specific features or syntaxes are available.

Returns:

Name Type Description
str

The Nautobot API version string.

Raises:

Type Description
RequestException

If there is an error fetching the version information from Nautobot.

Examples:

>>> import pynautobot
>>> nb = pynautobot.api(
...     'http://localhost:8000',
...     token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.version
'1.0'

openapi()

Retrieves the OpenAPI specification (OAS) document for the connected Nautobot instance.

The OpenAPI specification provides a machine-readable description of the Nautobot REST API, including available endpoints, parameters, request and response formats, and more.

This can be useful for tools like code generation or API clients in other languages.

Returns:

Name Type Description
dict

The OpenAPI specification document as a Python dictionary.

Raises:

Type Description
RequestException

If there is an error fetching the OpenAPI spec from Nautobot.

Examples:

>>> import pynautobot
>>> nb = pynautobot.api(
...     'http://localhost:8000',
...     token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.openapi()
{...}

status()

Retrieves status information about the connected Nautobot instance.

This method provides various details about the Nautobot instance, including:

  • Django version
  • Installed apps and their versions
  • Nautobot version
  • Active plugins (if any)
  • Python version
  • Number of running RQ workers (if applicable)

Availability: Requires Nautobot version 2.10.0 or newer.

Returns:

Name Type Description
dict

A dictionary containing the status information as returned by Nautobot.

Raises:

Type Description
RequestError

If the request to Nautobot fails.

Examples:

>>> import pprint
>>> nb = pynautobot.api(
...     'http://localhost:8000',
...     token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> pprint.pprint(nb.status())
{'django-version': '3.1.3',
'installed-apps': {...},
'nautobot-version': '1.0.0',
'plugins': {},
'python-version': '3.7.3',
'rq-workers-running': 1}