HomeGuidesAPI Reference
GuidesAPI ReferenceGitHubAirheads Developer Community
Guides

Quickstart Guide

This guide walks you through installing PyCentral-V2, set up authentication, and make your first API call to New Central and/or GLP using the PyCentral SDK

Installation

To install the latest pre-release version of PyCentral, use the following command:

pip3 install --pre pycentral

🚧

Note

PyCentral-v2 is currently in pre-release, and we welcome feedback here as we continue improving it.

Upgrading from PyCentral V1 to V2

If you are using PyCentral-V1 and want to upgrade to the latest pre-release version of PyCentral-V2, run:

pip3 install --upgrade --pre pycentral

📘

Backwards Compatibility

Upgrading to V2 will not break existing Classic Central workflows - V2 remains fully backward-compatible with V1 while enabling access to New Central & GLP APIs.

Setting Up Authentication

PyCentral provides a flexible authentication system allowing users to make API calls to New Central, GLP, and/or Classic Central. You only need to provide credentials for the platform(s) you want PyCentral to interact with.

New Central

  1. Base URL
    You can find your Central account's base URL from the table here
  2. API Credentials (Choose one):
    • Client ID & Client Secret (Recommended)
      The SDK automatically generates new tokens when they expire, so you don't have to manage them manually. Learn how to create your credentials here .
    • Access Token
      Manually, retrieve an access token here (Tokens expire in 2 hours)

GLP

  1. No Base URL Required
  2. API Credentials (Choose one):
    • Client ID & Client Secret (Recommended)
      The SDK automatically generates new tokens when they expire, so you don't have to manage them manually. Get your credentials here .
    • Access Token
      Manually, retrieve an access token here (Tokens expire in 15 mins)

Choosing an Authentication Method

PyCentral supports two authentication methods for New Central & GLP:

MethodBest ForToken Expiry
Client ID & Client Secret (Recommended)Automation & long-running scriptsAuto-renews - New tokens are generated automatically by SDK upon expiry
Access TokensQuick tests & one-time API callsManually need to update token upon expiry

📘

Which method should you use ?

If you want a hassle-free setup use Client ID & Secret, the SDK will automatically generate a new token whenever required.

If you're just testing an API, using Access Token is fine.

Making your First API call Using Python

Now that authentication is set-up, let's see how to use PyCentral to interact with New Central.

Prerequisites

Before running the script, create a token.yaml file in the same directory, as mentioned here, and populate it with the required credentials as follows:

new_central:
  base_url: <api-base-url>
  client_id: <client-id>
  client_secret: <client-secret>

This file provides the authentication credentials required by the SDK to make API calls to New Central

📘

Note

In the above token.yaml file, only New central API credentials are provided as the script will only be making API calls to New Central. If your script needs to make API calls to GLP, you will need to include your GLP API client credentials or token.

Example: Python Script to Get Devices

The python script below demonstrates:

  1. Load API Client Credentials from token.yaml file.
  2. Initialize the PyCentral SDK's connection to New Central
  3. Fetch a list of devices from New Central

Once you have the token.yaml file ready, you can run the following Python script:

import os
from pycentral import NewCentralBase

# Validate token file exists
token_file = "token.yaml"
if not os.path.exists(token_file):
    raise FileNotFoundError(
        f"Token file '{token_file}' not found. Please provide a valid token file."
    )

# Initialize NewCentralBase class with the token credentials for New Central/GLP
new_central_conn = NewCentralBase(
    token_info=token_file,
)

# New Central API Call
new_central_resp = new_central_conn.command(
    api_method="GET", api_path="network-monitoring/v1alpha1/devices"
)

# Check response status and print results or error message
if new_central_resp["code"] == 200:
    print(new_central_resp["msg"])
else:
    print(f"Error - Response code {new_central_resp['code']}")
    print(new_central_resp["msg"])

Running the Script

Save the code above as get_devices.py then execute it using:

python get_devices.py

If successful, you'll see a list of devices retrieved from New Central.


The above example serves as a foundation for writing your own custom scripts. As you explore more API endpoints , you can extend this approach to automate tasks, gather monitoring statistics, or integrate with your existing tools. The PyCentral SDK is designed to help you script confidently and build workflows that fit your specific needs. ith yous just a starting point.