Skip to main content

Nautobot API client library

Project description

pynautobot

Pynautobot

Python API client library for Nautobot.

Pynautobot was initially developed as a fork of pynetbox. Pynetbox was originally developed by Zach Moody at DigitalOcean and the NetBox Community.

The complete documentation for pynautobot can be found at Read the Docs.

Questions? Comments? Join us in the #nautobot Slack channel on Network to Code!

Installation

You can install via pip or poetry

Using pip

$ pip install pynautobot
...

Using poetry

$ git clone https://github.com/nautobot/pynautobot.git
...
$ pip install poetry
...
$ poetry shell
Virtual environment already activated: /home/user/pynautobot/.venv
$ poetry install
...

Quick Start

A short introduction is provided here; the full documention for pynautobot is at Read the Docs.

To begin, import pynautobot and instantiate an Api object, passing the url and token.

import pynautobot
nautobot = pynautobot.api(
    url="http://localhost:8000",
    token="d6f4e314a5b5fefd164995169f28ae32d987704f",
)

The Api object provides access to the Apps in Nautobot. The Apps provide access to the Models and the field data stored in Nautobot. Pynautobot uses the Endpoint class to represent Models. For example, here is how to access Devices stored in Nautobot:

devices = nautobot.dcim.devices
devices
<pynautobot.core.endpoint.Endpoint object at 0x7fe801e62fa0>

Queries

Pynautobot provides several ways to retrieve objects from Nautobot. Only the get() method is show here. To continue from the example above, the Endpoint object returned will be used to get the device named hq-access-01.

switch = devices.get(nam="hq-access-01")

The object returned from the get() method is an implementation of the Record class. This object provides access to the field data from Nautobot.

switch.id
'6929b68d-8f87-4470-8377-e7fdc933a2bb'
switch.name
'hq-access-01'
switch.site
hq

Threading

Pynautobot supports multithreaded calls for .filter() and .all() queries. It is highly recommended you have MAX_PAGE_SIZE in your Nautobot 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 when instantiating the Api object:

nautobot = pynautobot.api(
    url="http://localhost:8000",
    token="d6f4e314a5b5fefd164995169f28ae32d987704f",
    threading=True,
)

Versioning

Used for Nautobot Rest API versioning. Versioning can be controlled globally by setting api_version on initialization of the API class and/or for a specific request e.g (list(), get(), create() etc.) by setting an optional api_version parameter.

Global versioning

import pynautobot
nautobot = pynautobot.api(
    url="http://localhost:8000",
    token="d6f4e314a5b5fefd164995169f28ae32d987704f",
    api_version="1.3"
)

Request specific versioning

import pynautobot
nautobot = pynautobot.api(
  url="http://localhost:8000", token="d6f4e314a5b5fefd164995169f28ae32d987704f",
)
tags = nautobot.extras.tags
tags.create(name="Tag", slug="tag", api_version="1.2",)
tags.list(api_version="1.3",)

Retry logic

By default, the client will not retry any operation. This behavior can be adjusted via the retries optional parameters. This will only affect for HTTP codes: 429, 500, 502, 503 and 504.

Retries

import pynautobot
nautobot = pynautobot.api(
    url="http://localhost:8000",
    token="d6f4e314a5b5fefd164995169f28ae32d987704f",
    retries=3
)

Related projects

Please see our wiki for a list of relevant community projects.

Project details


Download files

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

Source Distribution

pynautobot-1.3.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynautobot-1.3.0-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file pynautobot-1.3.0.tar.gz.

File metadata

  • Download URL: pynautobot-1.3.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pynautobot-1.3.0.tar.gz
Algorithm Hash digest
SHA256 306d3ea972deb8ed22718dfe076c8109fcad1b3c76f94607ba4b1c2b7fac6d61
MD5 92806d67f809e6e991d7a1e3c1ff3fcb
BLAKE2b-256 c178aa386ff822279367c61a17e9da01329f422019d6625c1b10b4cc7ad90977

See more details on using hashes here.

File details

Details for the file pynautobot-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: pynautobot-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pynautobot-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 775e091ae76a261da0a15fa9c5cc30658655620a4acdfe751dc58ec8033634cc
MD5 fddfc8811b02518c969c2937d5d01e0e
BLAKE2b-256 305ef1ffed8a58c70f791146c3a6b041695f5e0b5dc063b4428a2f33f357bb0d

See more details on using hashes here.

Supported by

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