NetBox API client library
Project description
Pynetbox Fork to fix Issue #497
This is a Fork of pynetbox which fixes this issue by applying the fix @endreszabo suggested in this comment
Python API client library for NetBox.
Note: Version 6.7 and later of the library only supports NetBox 3.3 and above.
Installation
To install run pip install pynetbox
.
Alternatively, you can clone the repo and run python setup.py install
.
Quick Start
The full pynetbox API is documented on Read the Docs, but the following should be enough to get started using it.
To begin, import pynetbox and instantiate the API.
import pynetbox
nb = pynetbox.api(
'http://localhost:8000',
private_key_file='/path/to/private-key.pem',
token='d6f4e314a5b5fefd164995169f28ae32d987704f'
)
The first argument the .api() method takes is the NetBox URL. There are a handful of named arguments you can provide, but in most cases none are required to simply pull data. In order to write, the token
argument should to be provided. To decrypt information from the secrets
endpoint either the private_key_file
or private_key
argument needs to be provided.
Queries
The pynetbox API is setup so that NetBox's apps are attributes of the .api()
object, and in turn those apps have attribute representing each endpoint. Each endpoint has a handful of methods available to carry out actions on the endpoint. For example, in order to query all the objects in the devices
endpoint you would do the following:
>>> devices = nb.dcim.devices.all()
>>> for device in devices:
... print(device.name)
...
test1-leaf1
test1-leaf2
test1-leaf3
>>>
Threading
pynetbox supports multithreaded calls for .filter()
and .all()
queries. It is highly recommended you have MAX_PAGE_SIZE
in your Netbox 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 to the .api
:
nb = pynetbox.api(
'http://localhost:8000',
threading=True,
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file paulexyz_pynetbox-7.0.0.post1.tar.gz
.
File metadata
- Download URL: paulexyz_pynetbox-7.0.0.post1.tar.gz
- Upload date:
- Size: 65.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6991712dcebb134fe1b44bbbbdc32ed4ce7f95b91a96278e524da90f82817c2f |
|
MD5 | 06e44277319b541db40e1017de43f87e |
|
BLAKE2b-256 | f0f738c658b77fb2aeef9337e9a61d664d97b7fadc2c1e0c15053f2f5e7e6a35 |
File details
Details for the file paulexyz_pynetbox-7.0.0.post1-py3-none-any.whl
.
File metadata
- Download URL: paulexyz_pynetbox-7.0.0.post1-py3-none-any.whl
- Upload date:
- Size: 33.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6dfd96f36cc0e292add53c31cafd6d711af6133f023208214f2d6f64dfdbb46 |
|
MD5 | d1b64d017c970e8c426a1bd0d46990f2 |
|
BLAKE2b-256 | a28904c2f65756df9fe26ecff35d1ccc844d25ef8f89753eae4bac3db29d2767 |