Skip to main content

Annetbox - Netbox client used by annet and related projects

This project implements subset of Netbox API methods

Usage

  1. Install sync or async version
pip install 'annetbox[sync]'
  1. Create client instance according to your netbox version (only some are supported)
from annetbox.v37.client_sync import NetboxV37

netbox = NetboxV37(url="https://demo.netbox.dev", token="YOUR NETBOX TOKEN")
  1. Call methods
res = netbox.dcim_devices(limit=1)

Configuration

Verbose logging

For sync client

import http.client
import logging

logging.basicConfig()
http.client.HTTPConnection.debuglevel = 1
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

Custom SSL context

  1. Create context
import ssl

context = ssl.create_default_context(cafile="path/to/cacert.pem")
  1. Pass it to client
netbox = NetboxV37(url=url, token=token, ssl_context=context)

Development

Adding new methods

  1. Read openapi spec
  2. Edit models.py
  3. Edit client_async.py, do not forget adding limit/offset
  4. Convert async code to sync
python transform_to_sync.py src/annetbox/v37/client_async.py > src/annetbox/v37/client_sync.py
python transform_to_sync.py src/annetbox/v41/client_async.py > src/annetbox/v41/client_sync.py
python transform_to_sync.py src/annetbox/v42/client_async.py > src/annetbox/v42/client_sync.py

Integration tests

Integration tests are declarade in tests/integration/definitions.yaml. They are defined as call to specific client method:

  #
  # client.dcim_cables(limit=5)
  #
  - id: dcim_cables_01
    method: dcim_cables
    versions: ["v37", "v41", "v42"]
    args:
      limit: 5

Also supported chaining two calls:

  #
  # client.dcim_console_port(
  #   id=client.dcim_console_ports(limit=5)[0]
  # )
  #
  - id: dcim_console_port_01
    method: dcim_console_port
    versions: ["v37", "v41", "v42"]
    args:
      id: !from_call
        call: dcim_console_ports
        args: {limit: 5}
        extract: results[0].id

Frozen snapshot of data is stored in tests/integration/fixtures/v<client version>/<test case>/:

  • expected.yaml: holds name of a method, passed args and results.
  • cassette.yaml: holds raw netbox query and response generated by vcrpy lib.

Adding/modifying a test

  1. Spin up local netbox instances make docker (once)
  2. Edit tests/integration/definitions.yaml
  3. Run make fixtures and commit new generated files.

Download files

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

Source Distribution

annetbox-1.1.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

annetbox-1.1.1-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file annetbox-1.1.1.tar.gz.

File metadata

  • Download URL: annetbox-1.1.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for annetbox-1.1.1.tar.gz
Algorithm Hash digest
SHA256 1d1f60fb3f93b43d8768aae68f5ab741eb6e7b003ff93af82b2bc13aeccfdb47
MD5 31198ca03f77a5a21791b8e282e4f25d
BLAKE2b-256 14967a98a7b254e5bd5d9c833a0896e0d00c119ec3cb5d64fa01af02fd31feda

See more details on using hashes here.

Provenance

The following attestation bundles were made for annetbox-1.1.1.tar.gz:

Publisher: publish-to-pypi.yml on annetutil/annetbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file annetbox-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: annetbox-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for annetbox-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 74e2b6e2fb28c0b2924a11e305ac4e58511d1207b3895623de5d3dc53c43010c
MD5 da99da3ba17298a70ca34f5ed68e60b6
BLAKE2b-256 d9dca6a2faebc6c8940380638ff89d9c732cfc78a121dd97dea9422677ce25c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for annetbox-1.1.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on annetutil/annetbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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