"Statuscake API v1 wrapper"
Project description
Lightweight wrapper around Statuscake’s APIs. Heavily inspired by the OVH python client https://github.com/ovh/python-ovh
# -*- encoding: utf-8 -*-
import statuscake_api
client = statuscake_api.Client(
api_key='<api_key>',
)
# Print nice welcome message
print("Welcome", client.get('/uptime'))
Installation
The python wrapper works with Python 2.7 and Python 3.4+.
The easiest way to get the latest stable release is to grab it from pypi using pip.
pip install statuscake_api
Alternatively, you may get latest development version directly from Git.
pip install -e git+https://github.com/alkivi-sas/python-statuscake-api.git#egg=statuscake_api
Example Usage
1. Create an application
Go to your statuscake account and get your API KEY
2. Configure your application
The easiest and safest way to use your application’s credentials is to create an statuscake.conf configuration file in application’s working directory. Here is how it looks like:
[default]
; general configuration: default endpoint
endpoint=my_user
[my_user]
; configuration specific to 'my_user' endpoint
api_key=my_api_key
Depending on the API you want to use, you may set the several endpoint to handle severals accounts
Get all tests
# -*- encoding: utf-8 -*-
import statuscake_api
# create a client
client = statuscake_api.Client()
finished = False
page = 1
tests = []
while not finished:
params = {'page': page}
response = client.get('/uptime', **params)
test = response['data']
tests = tests + test
if 'metadata' in response:
page_count = response['metadata']['page_count']
if page < page_count:
page += 1
else:
finished = True
else:
finished = True
print(f'We have fetched {len(tests)}')
Add new test
When array in parameters, you need to add [] for the parameter
# -*- encoding: utf-8 -*-
import statuscake_api
# create a client
client = statuscake_api.Client()
new_test = {
'name': 'test-connection',
'test_type': 'PING',
'website_url': '8.8.8.8',
'check_rate': 60,
'tags_csv': 'test,api',
'contact_groups_csv': '31173',
'regions[]': ['paris', 'london'],
}
test = client.post('/uptime', **new_test)
Environment vars and predefined configuration files
Alternatively it is suggested to use configuration files or environment variables so that the same code may run seamlessly in multiple environments. Production and development for instance.
This wrapper will first look for direct instantiation parameters then STATUSCAKE_ENDPOINT, STATUSCAKE_API_KEY environment variables. If either of these parameter is not provided, it will look for a configuration file of the form:
[default]
; general configuration: default endpoint
endpoint=statuscake-eu
[statuscake-eu]
; configuration specific to 'statuscake-eu' endpoint
api_key=my_api_key
The client will successively attempt to locate this configuration file in
Current working directory: ./statuscake.conf
Current user’s home directory ~/.statuscake.conf
System wide configuration /etc/statuscake.conf
This lookup mechanism makes it easy to overload credentials for a specific project or user.
Example usage:
client = statuscake_api.Client()
Custom configuration file
You can also specify a custom configuration file. With this method, you won’t be able to inherit values from environment.
Example usage:
client = statuscake_api.Client(config_file='/my/config.conf')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for statuscake_api-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b3e55d50e621055615b1cb29c60437cb0ac1e5d040bd4ca583f81f0e7b90bd5 |
|
MD5 | 5ddb3ea9fb0ff780cfd2f665c01157f5 |
|
BLAKE2b-256 | 4006506b1a41a000fbd9d66db658e90b072a3ddfe9282551bdc546a03fdc0f94 |