Skip to main content

A Python wrapper for Conviva's Metrics V3 API

Project description

PyConviva

PyConviva is a Python wrapper for Conviva's Metrics V3 API, which provides programmatic access to historical and real-time metrics data.

For example, to get attempts metric data for the past 5 days, grouped by ISP:

import os

from pyconviva import ConvivaAPI

api = ConvivaAPI(os.environ["client_key"], os.environ["client_id"])
data = api.get_historical_data("attempts", group_by="isp", time_range=5)

Getting started

Prerequisites

First you need to generate API client-based credentials from Conviva.

Once you have your client_id and client_key simply pass it to an instance of ConvivaAPI, as above.

Installation

pip install pyconviva

Usage

All API endpoints are available as a method of ConvivaAPI.

You'll most likely be using either get_historical_data() or get_real_time_data().

Check out the official Conviva Metrics API documentation for more detail.

Retrieving metric data

When retrieving real-time or historical data you have to specify the metric (or metrics) you want:

attempts = api.get_historical_data("attempts")

multiple_metrics = api.get_historical_data(["attempts", "bitrate"])

All other parameters are optional and are documented as follows. Note that all examples use get_historical_data() but are applicable to get_real_time_data():

Grouping

Simply pass the name of the dimension you want to group by.

If you want to group by a custom tag you need to pass a dictionary, the key of which is "custom-tag" and the value of which is the name of your custom tag:

# Grouping by Conviva dimension.
api.get_historical_data("attempts", group_by="isp")

# Grouping by custom tag.
api.get_historical_data("attempts", group_by={"custom-tag":"appVersion"})

Use api.get_available_dimensions() to find dimensions you can group by.

Filtering

To filter the data, pass a dictionary with the dimension and value by which you want to filter.

To filter by the same dimension but with different values (essentially an OR statement) you can pass a list of values (e.g. {"isp":["Optus", "Vodafone"]}).

Note that you can also filter by a saved Conviva filter but if you do so you can't filter by dimensions.

# To filter to ISPs that are Optus.
api.get_historical_data("attempts", filter_by={"isp":"Optus"})

# To filter to ISPs that are Optus OR Vodafone.
api.get_historical_data("attempts", filter_by={"isp":["Optus", "Vodafone"]})

# Filtering using a saved filter.
api.get_historical_data(["attempts", "bitrate"], filter_by={"filter_id":"180"})

Time range

With get_real_time_data() simply specify the number of minutes ago you want to retrieve data (note that there is a maximum of 15 minutes):

# Get data that is 5 minutes old or fresher.
api.get_real_time_data("attempts", time_range=5)

With get_historical_data() there are numerous ways (start/end_date, start/end_epoch) in which to specify the time range.

See the official Metrics documentation for detail.

# Getting Ended Plays metric data per country for the last 5 days:
api.get_historical_data("attempts", time_range=5)

# Getting attempts metric data for January 1st 2025 to January 5th 2025
api.get_historical_data("attempts", time_range={"start_date":"2025-01-01T12:00:00.000Z",
                                                "end_date":"2025-01-06T12:59:59.000Z"})

Sorting

To sort the data returned you can pass the name of the metric you want to sort by.

Default order of sorting is descending but if you want to sort in ascending order you can also pass this as the second argument of a list.

Note that you need to group by a dimension in order to sort.

# Ordering by bitrate in descending order.
api.get_historical_data(["attempts", "bitrate"], group_by="isp", sort_by="bitrate")

# Ordering by bitrate in ascending order.
api.get_historical_data(["attempts", "bitrate"], group_by="isp", sort_by=["bitrate", "asc"])

Granularity

To specify the time interval granularity by which the data will be broken down just pass the name of the granularity.

Ensure it's in ISO 8601 duration format.

# Data broken down by week:
api.get_historical_data("attempts", granularity="P1W")

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

pyconviva-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyconviva-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pyconviva-0.1.0.tar.gz.

File metadata

  • Download URL: pyconviva-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyconviva-0.1.0.tar.gz
Algorithm Hash digest
SHA256 adf59d29b42277f8a6476b6518077e3c0d5dfe4eb2b18b5c6e7238b098951352
MD5 5f7170273ffb67f836f179626e494103
BLAKE2b-256 0b5eb58b4c501f644a84079a22fadd1d491c519d45cebdb04814b83139d4a420

See more details on using hashes here.

File details

Details for the file pyconviva-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyconviva-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyconviva-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7df6e43b9e431dc484e0448f2322fb0fd5bd85a306f4169ab7b50c66291ceb79
MD5 885b634cd28e293e475e4bc9bb04a83b
BLAKE2b-256 bc4db5d80e8aaa5627c9a8dee488efb7580baaa265c74e57cf212b44261a0857

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page