Python SDK Overview
IP Fabric is a Python API for connecting to and communicating against an IP Fabric instance using IP Fabric’s Rest API.
Please use release main
when viewing on the
IP Fabric Documentation Portal for all Integrations.
These docs are not versioned but versioned files can be found in the GitLab releases.
The IP Fabric Python SDK allows you to quickly gather data from your network in as little as 3 lines of code.
Minimum Requirements
- Python 3.8.1+
- Access to an instance of IP Fabric
- API Token or Username/Password to IP Fabric
Versioning
Semantic Versioning: Major.Minor.Patch
Starting with IP Fabric version 5.0.x the ipfabric
SDK is recommended to match your IP Fabric major and minor version.
We will try to keep some backwards compatability (SDK version 6.9.x
should work with IP Fabric API 6.8
) however new
features may break some functionality. By ensuring that your ipfabric
SDK’s match your IP Fabric major and minor
version will ensure compatibility and will continue to work.
The Patch version of the SDK is used for bug fixes and new features that are compatible with the major and minor version.
Installation
It is recommended to use Python Virtual Environments
for any development purposes. Installing the package globally is not recommended but can be installed under your user
(pip install --user ipfabric
) which will give you access to run the IP Fabric CLI Tools without needing to activate
the virtual environment.
> curl https://demo1.us.ipfabric.io/api/version -q | jq
{
"apiVersion": "v6.8",
"releaseVersion": "6.8.6+0"
}
> pip install "ipfabric~=6.8" # To update to a new version use the `-U` flag
# This will match version `6.8.0` or any patch like `6.8.3` but not `6.7.x` nor `6.9.x`
- To return IP Fabric table data as Pandas DataFrames (
export='df'
):pip install "ipfabric[pd]~=6.8"
- To install extra requirements required for some CLI Tools:
pip install "ipfabric[cli]~=6.8"
- To run scripts in the examples directory:
pip install "ipfabric[examples]~=6.8"
- Multiple optional dependencies can be specified:
pip install "ipfabric[pd,cli]~=6.8"
For contributing to the project please see README.md > Development.
Authentication
Setting Up an API Token
Please follow the instruction on the API Tokens documentation page.
Environment Variables
Please add the following environment variables these can be included in a .env
file that can be copied from sample.env:
Variable Name | Python Parameter | Default | Description | Optional |
---|---|---|---|---|
IPF_URL |
base_url |
None |
IP Fabric URL | |
IPF_TOKEN |
auth |
None |
API Token | If not IPF_USERNAME/IPF_PASSWORD |
IPF_VERIFY |
verify |
True |
Enforce SSL | True |
IPF_USERNAME |
auth |
None |
Username | If not IPF_TOKEN |
IPF_PASSWORD |
auth |
None |
Password | If not IPF_TOKEN |
IPF_SNAPSHOT |
snapshot_id |
$last |
IPF Snapshot | True |
IPF_TIMEOUT |
timeout |
5 | Timeout | True |
streaming |
True |
Using Streaming HTTP | True | |
proxy |
None |
Proxy for requests | True |
Adding a .env
file in your home directory or setting these as environment variables will allow you to run the CLI
Tools from any location.
Environment Selection:
- Initialization arguments take precedence:
IPFClient(base_url='FQDN', auth='TOKEN')
. - Environment variables.
.env
file variables; file is selected using the following methods:IPFClient(env_file='/path/to/env')
- Check current working directory (
/opt/path/
->/opt/path/.env
). - Work up the directory tree until the root (
/opt/.env
,/.env
). - Finally check user home directory (
$HOME/.env
)
Initializing
Once you set up your environment variables:
Alternatively without Environment Variables
from ipfabric import IPFClient
ipf = IPFClient('https://demo3.ipfabric.io/', auth='token')
from ipfabric import IPFClient
ipf = IPFClient('https://demo3.ipfabric.io/', auth=('user', 'pass'))
Inventory
>>> from ipfabric import IPFClient
>>> IPFClient().inventory.
IPFClient().inventory.devices IPFClient().inventory.modules
IPFClient().inventory.eol_details IPFClient().inventory.os_version_consistency
IPFClient().inventory.eol_summary IPFClient().inventory.phones
IPFClient().inventory.families IPFClient().inventory.platforms
IPFClient().inventory.fans IPFClient().inventory.pn
IPFClient().inventory.hosts IPFClient().inventory.sites
IPFClient().inventory.hosts_ipv6 IPFClient().inventory.vendors
IPFClient().inventory.interfaces
from ipfabric import IPFClient
ipf = IPFClient()
devices = ipf.inventory.devices.all()
interfaces = ipf.inventory.interfaces.all()
Technology
>>> from ipfabric import IPFClient
>>> IPFClient().technology.
IPFClient().technology.addressing IPFClient().technology.oam
IPFClient().technology.cloud IPFClient().technology.platforms
IPFClient().technology.dhcp IPFClient().technology.port_channels
IPFClient().technology.fhrp IPFClient().technology.qos
IPFClient().technology.interfaces IPFClient().technology.routing
IPFClient().technology.ip_telephony IPFClient().technology.sdn
IPFClient().technology.load_balancing IPFClient().technology.sdwan
IPFClient().technology.managed_networks IPFClient().technology.security
IPFClient().technology.management IPFClient().technology.serial_ports
IPFClient().technology.mpls IPFClient().technology.stp
IPFClient().technology.multicast IPFClient().technology.vlans
IPFClient().technology.neighbors IPFClient().technology.wireless
Each one of these technologies relates to data IP Fabric has gathered about your network devices.
from ipfabric import IPFClient
ntp = IPFClient().technology.management.ntp_summary.all()
# Alternatively using API URL:
ntp = IPFClient().fetch_all('/tables/management/ntp/summary')
# Or even using the Front End GUI URL:
ntp = IPFClient().fetch_all('/technology/management/ntp/summary')