Skip to content

ANAC


Async NetBox API Client

anac - is a simple Python NetBox API client with async interface and based on awesome httpx and pydantic

Features#

  • Minimalistic interface
  • Async only
  • Python interpreter autocompletion
  • Supports NetBox 2.x, 3.x
  • Flexibility. All the objects are coroutines or coroutine iterators
  • Simple integration with parsers (TextFSM, TTP)

Installation#

with pip:

pip install anac 

with git:

git clone https://github.com/timeforplanb123/anac.git
cd anac 
pip install .
# or
poetry install

Simple Example#

Api Instantiating

from anac import api

a = api(
    "https://demo.netbox.dev",
    token="cf1dc7b04de5f27cfc93aba9e3f537d2ad6fdf8c",
)
# get openapi spec and create attributes/endpoints   
await a.openapi()
get some device and patch it
# get some device from NetBox
In [1]: some_device = await a.dcim_devices(get={"name": "dmi01-rochster-sw01"})

# check some attributes
In [2]: some_device.name
Out[2]: 'dmi01-rochster-sw01'

In [3]: some_device.device_type.model
Out[3]: 'C9200-48P'

# 'patch' some_device status
In [4]: some_device = await some_device(patch={"status": "failed"})

# check new status
In [5]: some_device.status
Out[5]: {'value': 'failed', 'label': 'Failed'}

asciicast