Skip to content

Repository files navigation

· xcover-python ·

Supported Versionscodecov


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

poetry 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:

fromxcoverimportXCover, XCoverConfigclient=XCover(
XCoverConfig( # minimal config, check autocomplete for more optionsbase_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:

Environment VariableConfig PropertyDescriptionDefault Value
XC_BASE_URLXCoverConfig.base_urlXCover base URL (e.g. https://api.xcover.com/api/v2/)-
XC_PARTNER_CODEXCoverConfig.partner_codePartner code (e.g. LLODT)-
XC_HTTP_TIMEOUTXCoverConfig.http_timeoutHTTP timeout in seconds10
XC_AUTH_API_KEYXCoverConfig.auth_api_keyAPI key to use-
XC_AUTH_API_SECRETXCoverConfig.auth_api_secretAPI secret to use-
XC_AUTH_ALGORITHMXCoverConfig.auth_algorithmHMAC encoding algorithm to usehmac-sha512
XC_AUTH_HEADERSXCoverConfig.auth_headersHeaders to sign(request-target) date
XC_RETRY_TOTALXCoverConfig.retry_totalTotal number of retries5
XC_RETRY_BACKOFF_FACTORXCoverConfig.retry_backoff_factorBackoff factor for retries timeout2

Usage example

Using low-level call method

importrequestsfromxcover.xcoverimportXCover# Env variables are usedclient=XCover()
# Prepare payloadpayload= {
"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 APIresponse: 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.

About

xcover-python is an API client for XCover

Resources

Stars

3 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages