Skip to content

NORFAB Python APIยค

The NORFAB Python API provides a programmatic interface to interact with the NORFAB automation fabric. It is designed for developers who want to integrate NORFAB capabilities into their Python applications for advanced network automation and management tasks.

NorFab Python API can be used to interact with automations fabric. To start working with Python API need to import NorFab object and instantiate it.

from norfab.core.nfapi import NorFab

nf = NorFab(inventory="./inventory.yaml")
nf.start()
nf.destroy()

Refer to Getting Started section on how to construct inventory.yaml file.

All interaction with NorFab happens via client, to create a client need to call make_client method:

Example

This example demonstrates steps to create NorFab instance, create client, run job and destroy NorFab instance.

import pprint
from norfab.core.nfapi import NorFab

nf = NorFab(inventory="./inventory.yaml")
nf.start()

client = nf.make_client()

result = nf.client.run_job(
    service="nornir",
    task="cli",
    kwargs={"commands": ["show version", "show clock"]}
)

pprint.pprint(result)

nf.destroy()

Context manager simplifies code and handles client creation and NorFab cleanup.

import pprint
from norfab.core.nfapi import NorFab

with NorFab(inventory="./inventory.yaml") as nf:
    result = nf.client.run_job(
        service="nornir",
        task="cli",
        kwargs={"commands": ["show version", "show clock"]}
    )

pprint.pprint(result)

Calling destroy method will kill all the clients as well.