Skip to main content

simple_netbox is a simplified REST Client for Netbox

Features

simple_netbox has following features:
  • manage login

  • simple CRUD via ensure_exists and ensure_absent helper functions

  • auto add slug on creation of objects if not supplied

  • CRUD interface for all possible API URLs

  • create curl commands from all calls (for documentation purposes)

Installation

Install simple_netbox by running:

pip3 install simple_netbox

Examples

CRUD a site

from simple_netbox import NetboxClient
import logging
from getpass import getpass
import secrets
import string

logger = logging.getLogger()
logging.basicConfig(encoding="utf-8", level=logging.INFO)


URL=input("Please Enter Netbox URL: ") or "http://localhost:8000"
token=input("Please Enter the Netbox token: ") or "not set"


nb = NetboxClient(URL,token=token,log_curl_commands=True)

logging.info("list all sites")
logging.info(nb.api.dcim.sites.list()) # alternativly nb.api.dcim.sites.get() can be used


logging.info("create site demo1, slug will be autogenerated if not supplied")

site_id=nb.api.dcim.sites.create(body={"name":"demo1"})["id"] # alternativly nb.api.dcim.sites.post() can be used

logging.info("to filter results on server side following syntax can be used")

logging.info(nb.api.dcim.sites.list(params={"name":"demo1"})) # alternativly nb.api.dcim.sites.get() can be used


nb.api.dcim.sites.patch(site_id,body={"description":"demo1 desc"})

logging.info(f"delete site demo1 (id:{site_id})")

nb.api.dcim.sites.delete(site_id)


logging.info(f"create site demo2 via ensure_exists")

nb.api.dcim.sites.ensure_exists(name="demo2")

logging.info(f"update site demo2 via ensure_exists")

nb.api.dcim.sites.ensure_exists(name="demo2", description="nice location")

logging.info(f"delete site demo2 via ensure_absent")

nb.api.dcim.sites.ensure_absent(name="demo2")

print(nb.api.curl_commands)

API tokens

NetBox 4.6 introduced v2 API tokens, which are made of a public key and a secret token and authenticate with a different header. Pass the key and the client uses the v2 form; leave it out and the v1 form is used, so existing code keeps working unchanged.

# v1 token  ->  Authorization: Token <token>
nb = NetboxClient(URL, token=token)

# v2 token  ->  Authorization: Bearer nbt_<key>.<token>
nb = NetboxClient(URL, token=token, key=key)

# the credential can also be replaced on an existing client
nb.login(token, key)

Endpoints containing a hyphen cannot be reached by attribute access. Register them by path first:

nb.api.add_resource(resource_name="dcim/device-types")
device_types = getattr(nb.api.dcim, "device-types").get()

Contribute

Roadmap

Selected Roadmap items:
  • add more documentation

  • add some more examples

For documentation please refer to https://simple_netbox.readthedocs.io/en/latest/

License

This project is licensed under the Apache License Version 2.0

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

simple_netbox-0.2-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file simple_netbox-0.2-py3-none-any.whl.

File metadata

  • Download URL: simple_netbox-0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for simple_netbox-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35af04ab6c619c14961c6dae81b4c9205070d01bd5ba3ff94f204877377246e9
MD5 9c9edabc65f9c8d12aa5b7f6794f9c31
BLAKE2b-256 18c16aa952b3309eadc1a08f487faa6d1906cd15349c80454c918d1985d3eaca

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.2

1 file

This release

0.2 This release

1 file

0.1.1

1 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