Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

netboxapi-client

This is a python client for netbox (https://github.com/digitalocean/netbox) API. It can be used either as a python module/library or directly from the command line. The goal of this project is to provide a simple way to automate infrastructure documentation based on the REST API from that great project that is Netbox.

Status

Under development.

Current developments are tested on netbox v2.2.2 and above.

Installation

You can clone that repo and install locally with:

python setup.py build && pip install -e .

Proper pypi package on it’s way.

Usage

From CLI, using a configuration file:

Copy netboxapi.json.example file to netboxapi.json and edit that file to match your netbox instance url and token.

python netboxapi_client.py -h will give you the overview of the models you can act on. -h is available at each depth level of the cli.

Here are some examples:

netboxapi_client -h
netboxapi_client dcim -h category
netboxapi_client dcim devices -h
netboxapi_client dcim devices list
netboxapi_client dcim devices create -d '$(cat mydevice.json)'
netboxapi_client dcim devices create \
        -d '{ "name": "sw-02-par-eq2", \
              "slug": "sw-02-par-eq2", \
              "device_role": "1", \
              "device_type": "8", \
              "site": "184" }'
netboxapi_client dcim devices show -n sw-02-par-eq2
netboxapi_client dcim devices show -i 10
netboxapi_client dcim devices delete -n sw-02-par-eq2

From code:

This is a very basic example:

from pprint import pprint
from netboxapi_client import Api, get

TOKEN = "thetokenyoucangetfromnetboxwebuionauserprofilepage"
URL = "https://netbox.example.org"

api = Api(url=URL, token=TOKEN)

res = get(api, model="dcim", obj="devices", name="sw-02-par-eq2")

pprint(res)

For now, you have to import the Api class and the function you need (get, get_list, update, create, delete, and so on…). This will be improved soon…

How-to test

Install docker and docker-compose and then:

sudo docker-compose run --rm netbox createsuperuser

You will be prompted for a username, email and password for the superuser.

sudo docker-compose up -d

Then you have to connect to the netbox instance you just installed. It should be accessible at http://localhost:8000 . Login with the credentials you choosed earlier. On the top right you can select username > profile. Then click on “API tokens” and create one, either use the one writen in tests/basic.py or choose one and replace the one in this file. (yeah token creation could be automated, it will be…)

Then you can try querying the api as described earlier.

To run unit tests:

python tests/basic.py

TODO

  • prevent sending multiple requests/discovering the model if not required

  • better catch exceptions to give users a more comprehensive output

  • setup CI/CD pipeline and build status on github

  • push docker image to public repo and add docker-compose.yml, entrypoint.sh to the repo, add testing process to documentation

Metadata

Release files for netboxapi-client 0.1b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for netboxapi-client 0.1b1
File Interpreter ABI Platform
netboxapi_client-0.1b1-py2-none-any.whl Python 2 none any Details

Release files / netboxapi_client-0.1b1-py2-none-any.whl

Download URL netboxapi_client-0.1b1-py2-none-any.whl
Size 9.7 kB
Tags Python 2
SHA-256 checksum
How to use checksums
3ebdd944b3895857396f0613a666f7686116da6af70462868e3e137115a0de4f
BLAKE2b-256 checksum
How to use checksums
b340def2014dd99c1ce091cc0ba2ee51b606a99c1439234b2302a699e5e35401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1b1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page