Python client for XCover API (XCore).
Project description
· xcover-python ·
xcover-python
is a Python API Client for XCover.
Installation
xcover-python
is available on PyPI. To install the latest version run:
pip install xcover-python
or
poertry install xcover-python
Features
- Authentication
- Simple configuration using env variables
- (WIP) High-level API to perform partner operations on quotes and bookings
Configuration
Config object
The library provides XCoverConfig
dataclass that can be used as shown:
from xcover import XCover, XCoverConfig
client = XCover(
XCoverConfig( # minimal config, check autocomplete for more options
base_url="https://api.xcover.com/xcover",
partner_code="--PARTNER_CODE--",
auth_api_key="--API_KEY--",
auth_api_secret="--API_SECRET--",
)
)
Env variables
Alternatively, it is possible to use env variables.
The full list of configuration options:
XC_BASE_URL
(XCoverConfig.base_url
): XCover base URL (e.g.https://api.xcover.com/api/v2/
).XC_PARTNER_CODE
(XCoverConfig.partner_code
): Partner code (e.g.LLODT
).XC_HTTP_TIMEOUT
(XCoverConfig.http_timeout
): HTTP timeout in seconds. Default value is10
.XC_AUTH_API_KEY
(XCoverConfig.auth_api_key
): API key to use.XC_AUTH_API_SECRET
(XCoverConfig.auth_api_secret
): API secret to use.XC_AUTH_ALGORITHM
(XCoverConfig.auth_algorithm
): HMAC encoding algorithm to use. Default ishmac-sha512
.XC_AUTH_HEADERS
(XCoverConfig.auth_headers
): Headers to sign. Default is(request-target) date
.XC_RETRY_TOTAL
(XCoverConfig.retry_total
): Total number of retries. Default is5
.XC_RETRY_BACKOFF_FACTOR
(XCoverConfig.retry_backoff_factor
): Backoff factor for retries timeout. Default is2
.
Usage example
Using low-level call
method
import requests
from xcover.xcover import XCover
# Env variables are used
client = XCover()
# Prepare payload
payload = {
"request": [
{
"policy_type": "event_ticket_protection",
"policy_type_version": 1,
"policy_start_date": "2021-12-01T17:59:00.831+00:00",
"event_datetime": "2021-12-25T21:00:00+00:00",
"event_name": "Ariana Grande",
"event_location": "The O2",
"number_of_tickets": 2,
"tickets": [
{"price": 100},
],
"resale_ticket": False,
"event_country": "GB",
}
],
"currency": "GBP",
"customer_country": "GB",
"customer_region": "London",
"customer_language": "en",
}
# Calling XCover API
response: requests.Response = client.call(
method="POST",
url="partners/LLODT/quotes/",
payload=payload,
)
quote = response.json()
print(quote)
Retries
This client will automatically retry certain operations when it is considered safe to do this. The retry number and intervals could be controlled via XC_RETRY_TOTAL and XC_RETRY_BACKOFF_FACTOR environment variables ot the same config options.
Auto retry logic can be enabled/disabled per operation. However, further fine-tuning is possible via extending XCover class if required.
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
File details
Details for the file xcover_python-0.1.1.tar.gz
.
File metadata
- Download URL: xcover_python-0.1.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e23b77808c93b11621bf0aa701976a4f903785a281ad24c238b4419482986c5 |
|
MD5 | 82ec40f374a40c618afe598b3c128fd6 |
|
BLAKE2b-256 | 6db0452387476f90506c7e33cba4d21b0f8bd28405ad45d0b0fc08a951cbcfae |
File details
Details for the file xcover_python-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: xcover_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6292a5a9de74361d81254da842b62e07f2f69a8e86f6b53bb15a0b0e1ac3d48d |
|
MD5 | a36fe8b25a2a04a268671902eccc4f35 |
|
BLAKE2b-256 | 4cc85785fdb8b16f41fa9dead94208db5f0fcfc63df9eaa2c0816bae4e99218e |