Python xMatters API wrapper
Project description
python-xmatters
python-xmatters is a wrapper for the xMatters API.
Features
- Most documented endpoints and objects implemented.
- Auto-refresh of access tokens and storage of tokens.
- Support for both basic and OAuth2 authentication.
- Support for most query parameters.
- Support for pagination objects.
- Conversion to datetime objects (local or UTC timezone) for time attributes.
Requirements
Installation
$ pip install python-xmatters
Documentation
See python-xmatters.readthedocs.io and xMatters REST API Reference for object reference.
Example Usage
Authentication
Basic Authentication
from xmatters import XMSession
xm = XMSession('my_instance.xmatters.com')
xm.set_authentication(username='my_username', password='my_password')
groups = xm.groups_endpoint()
for group in groups.get_groups():
print(group.target_name)
OAuth2 Authentication
It is assumed that if a client_id is provided; OAuth2 authentication is desired.
Using refresh token
from xmatters import XMSession
refresh_token = 'my-refresh-token'
xm = XMSession('my_instance.xmatters.com')
xm.set_authentication(client_id='my-client-id', token=refresh_token)
groups = xm.groups_endpoint()
for group in groups.get_groups():
print(group.target_name)
Using token object
from xmatters import XMSession
my_token = {
"access_token": "my-access-token",
"token_type": "bearer",
"refresh_token": "my-refresh-token",
"expires_in": 900,
"jti": "my-jti",
"sbu": "my-sbu",
"expires_at": 0123456789.012345
}
xm = XMSession('my_instance.xmatters.com')
xm.set_authentication(client_id='my-client-id', token=my_token)
groups = xm.groups_endpoint()
for group in groups.get_groups():
print(group.target_name)
Using username and password with token storage
Any class instance with read_token and write_token methods should work as token_storage
from xmatters import XMSession
from xmatters.utils import TokenFileStorage
token_storage = TokenFileStorage('/path/to/my_token.json')
xm = XMSession('my_instance.xmatters.com')
xm.set_authentication(client_id='my-client-id', username='my_username', password='my_password',
token_storage=token_storage)
groups = xm.groups_endpoint()
for group in groups.get_groups():
print(group.target_name)
Timestamp conversion to local timezone
from xmatters import XMSession
from xmatters.utils import TokenFileStorage
token_storage = TokenFileStorage('/path/to/my_token.json')
xm = XMSession('my_instance.xmatters.com')
xm.set_authentication(client_id='my-client-id', token_storage=token_storage)
groups = xm.groups_endpoint()
for group in groups.get_groups():
print(group.created.local())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python-xmatters-1.1.1.tar.gz.
File metadata
- Download URL: python-xmatters-1.1.1.tar.gz
- Upload date:
- Size: 28.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c419424b61e52753ab2b58da53371646e2a01e552b5719a66782453079ebebca
|
|
| MD5 |
f9e1b2b31d358a94bf241c9247caa2aa
|
|
| BLAKE2b-256 |
3f7cd3da7b6a0816af50d591b0732c607d919c6fc986a75f83bf1241085295d1
|
File details
Details for the file python_xmatters-1.1.1-py3-none-any.whl.
File metadata
- Download URL: python_xmatters-1.1.1-py3-none-any.whl
- Upload date:
- Size: 45.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5c8da414830935927fb8812c0407698feea36ddc318935fbce68fb5f9ccdd73
|
|
| MD5 |
993e925a947973b2887a5af78382177e
|
|
| BLAKE2b-256 |
f03573fe65e00f8b5514661d2e37dbdb00cd4be7aa31bc298cc01d674c8ce9d5
|