Code Monkey home page Code Monkey logo

pynetbox's Introduction

Pynetbox

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',
    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.

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
>>>

Note that the all() and filter() methods are generators and return an object that can be iterated over only once. If you are going to be iterating over it repeatedly you need to either call the all() method again, or encapsulate the results in a list object like this:

>>> devices = list(nb.dcim.devices.all())

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,
)

pynetbox's People

Contributors

markkuleinio avatar raddessi avatar zachmoody avatar arthanson avatar tyler-8 avatar dimaqa avatar jqueuniet avatar jsenecal avatar jeremystretch avatar abringenberg avatar victorpavlushin avatar stsmrvestas avatar lamiskin avatar fach avatar jerradgit avatar dvaccarosenna avatar weisdd avatar meoflynn avatar h-otter avatar vincentbernat avatar tweippert avatar steffenschumacher avatar stefanmcshane avatar explody avatar mandarg avatar lukasjuhrich avatar johanfleury avatar kani999 avatar ignatenkobrain avatar thedac avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.