Precondition: python3 and pip3 are already installed.
-
Create dedicated virtual environment
python -m venv .venv
-
Activate virtualenv
source .venv/bin/activate
-
Clone the library repository
git clone https://github.com/kentik/community_sdk_python.git
-
cd community_sdk_python/kentik_api_library/
-
Install Python dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt
-
Generate grpc client code
python setup.py grpc_stubs
-
Install the library from repository
pip install -e .
-
Run unit tests
python setup.py pytest
-
Run mypy
python setup.py mypy
-
Run black and isort checks
python setup.py format --check
The example below illustrates how to create a new device using the library:
# library-specific imports
from kentik_api.public.types import ID
from kentik_api import (
KentikAPI,
Device,
DeviceSubtype,
CDNAttribute,
)
# initialize Kentik API client
api_client = KentikAPI("<API_EMAIL_STRING>", "<API_TOKEN_STRING>")
# prepare device object
device = Device.new_dns(
device_name="example-device-1",
device_subtype=DeviceSubtype.aws_subnet,
cdn_attr=CDNAttribute.yes,
device_sample_rate=100,
plan_id=ID(11466),
site_id=ID(8483),
device_bgp_flowspec=True,
)
# create the device
created = api_client.devices.create(device)
# print returned device's attributes
print(created.__dict__)
kentik_api
package is the root package of the libraryapi_resources
package contains implementations of all the KentikAPI resource manipulation classespublic
package contains classes representing all KentikAPI resourcesrequest_payloads
package contains serialization/deserialization structures for each KentikAPI resourceapi_calls
package contains definitions of all requests that enable interaction with each KentikAPI resource
Main components taking part in creating a device:
A sequence of interactions that leads to creating a new device:
For error handling there is an exception hierarchy that allows to handle:
- validation errors - when library user tries to create an incomplete/invalid resource
- deserialization erors - when invalid or incomplete resource json representation is received from KentikAPI
- protocol errors - errors covering selected HTTP error codes, in particular:
IntermittentError
- request can be reattempted and succeed after a delayRateLimitExceededError
- effect of throttling on KentikAPI side
The release process for the kentik-api library is based on Git repository tags. Every tag with format v[0-9].[0-9].[0-9]
will trigger an automatic build of the package and publish it in the PyPi repository.
To build and release package:
- Make sure that all code that you want to release is in the main branch
- Create a tag with format
v[0-9].[0-9].[0-9]
in GitHub. Releases -> Draft a new release -> Put tag version, name and description - Go to GitHub Actions