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
- Base URL
You can find your Central account's base URL from the table here - API Credentials (Choose one):
GLP
- No Base URL Required
- API Credentials (Choose one):
Choosing an Authentication Method
PyCentral supports two authentication methods for New Central & GLP:
Method | Best For | Token Expiry |
---|---|---|
Client ID & Client Secret (Recommended) | Automation & long-running scripts | Auto-renews - New tokens are generated automatically by SDK upon expiry |
Access Tokens | Quick tests & one-time API calls | Manually 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:
- Load API Client Credentials from
token.yaml
file. - Initialize the PyCentral SDK's connection to New Central
- 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.
Updated 8 days ago