API Module¶
- class pynautobot.core.api.Api(url, token=None, threading=False, api_version=None, retries=0)¶
Bases:
object
The API object is the point of entry to pynautobot.
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
tenancy
extras
virtualization
users
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 Nautobot you wish to connect to.
token (str) – Your Nautobot token.
threading (bool,optional) – Set to True to use threading in
.all()
and.filter()
requests.api_version (str,optional) – Set to override the default Nautobot REST API Version for all requests.
retries (int,optional) – Number of retries, for HTTP codes 429, 500, 502, 503, 504, this client will try before dropping.
- Raises:
AttributeError – If app doesn’t exist.
- Examples:
>>> import pynautobot >>> nb = pynautobot.api( ... 'http://localhost:8000', ... token='d6f4e314a5b5fefd164995169f28ae32d987704f' ... ) >>> nb.dcim.devices.all()
- __init__(url, token=None, threading=False, api_version=None, retries=0)¶
- openapi()¶
Returns the OpenAPI spec.
Quick helper function to pull down the entire OpenAPI spec.
- Returns:
dict
- Example:
>>> import pynautobot >>> nb = pynautobot.api( ... 'http://localhost:8000', ... token='d6f4e314a5b5fefd164995169f28ae32d987704f' ... ) >>> nb.openapi() {...} >>>
- status()¶
Gets the status information from Nautobot.
Available in Nautobot 2.10.0 or newer.
- Returns:
Dictionary as returned by Nautobot.
- Raises:
RequestError
if the request is not successful.- Example:
>>> pprint.pprint(nb.status()) {'django-version': '3.1.3', 'installed-apps': {'cacheops': '5.0.1', 'debug_toolbar': '3.1.1', 'django_filters': '2.4.0', 'django_prometheus': '2.1.0', 'django_rq': '2.4.0', 'django_tables2': '2.3.3', 'drf_yasg': '1.20.0', 'mptt': '0.11.0', 'rest_framework': '3.12.2', 'taggit': '1.3.0', 'timezone_field': '4.0'}, 'nautobot-version': '1.0.0', 'plugins': {}, 'python-version': '3.7.3', 'rq-workers-running': 1} >>>
- property version¶
Gets the API version of Nautobot.
Can be used to check the Nautobot API version if there are version-dependent features or syntaxes in the API.
- Returns:
Version number as a string.
- Example:
>>> import pynautobot >>> nb = pynautobot.api( ... 'http://localhost:8000', ... token='d6f4e314a5b5fefd164995169f28ae32d987704f' ... ) >>> nb.version '1.0' >>>