Skip to main content

A simple yet powerful API wrapper to make getting analytical information from the YouTube Analytics API easier than ever.

Project description

analytix

PyPi version PyPI pyversions License

A simple yet powerful API wrapper to make getting analytical information from the YouTube Analytics API easier than ever.

Features

  • Pythonic syntax lets you feel right at home
  • Dynamic error handling saves hours of troubleshooting, and makes sure only valid requests count toward your API quota
  • A clever interface allows you to make multiple requests per session without reauthorising
  • Extra support allows the native saving of CSV files and conversion to DataFrame objects
  • Easy enough for beginners, but powerful enough for advanced users

Installation

You need Python 3.7.1 or greater to run analytix. You will also need to have a Google Developers project with the YouTube Analytics API enabled. You can find instructions on how to do that in the YouTube Analytics API docs.

It is recommended you install analytix in a virtual environment. To do this, run the following:

# Windows
> py -3.9 -m venv .venv
> .venv\Scripts\activate
> pip install analytix

# Linux\macOS
$ python3.9 -m venv .venv
$ source ./.venv/bin/activate
$ pip install analytix

To install analytix outside of a virtual environment instead, run the following:

# Windows
> py -3.9 -m pip install analytix

# Linux/macOS
$ python3.9 -m pip install analytix

You can also install the development version by running the following (this assumes you're on Linux/macOS):

$ git clone https://github.com/parafoxia/analytix
$ cd analytix
$ git checkout develop  # Any valid branch name can go here.
$ python3.9 -m pip install -U .

Usage examples

The following example shows you how easy analytix can be to use. This retrieves day-by-day analytics for the last 28 days using all metrics.

from analytix.youtube import YouTubeAnalytics, YouTubeService

service = YouTubeService("./secrets.json")  # Load from secrets file
service.authorise()
analytics = YouTubeAnalytics(service)
report = analytics.retrieve(dimensions=("day",))
report.to_csv("./analytics-28d.csv")

Of course not all requests will be that simple, but analytix can handle all the complicated stuff too. This example retrieves day-by-day analytics for live streams in January 2021, split by device type and subscription status, and sorted by views. It then saves the report as a CSV, converts to a dataframe for further analysis, and saves a boxplot figure.

import datetime as dt

import matplotlib.pyplot as plt
import seaborn as sns
from analytix.youtube import YouTubeAnalytics, YouTubeService

service = YouTubeService("./secrets.json")
service.authorise()
analytics = YouTubeAnalytics(service)

report = analytics.retrieve(
    metrics=("views",),
    dimensions=("day", "deviceType", "subscribedStatus"),
    filters={"liveOrOnDemand": "LIVE"},
    start_date=dt.date(2021, 1, 1),
    end_date=dt.date(2021, 1, 31),
    sort_by=("views",),
)
report.to_csv("./live-device-types.csv")
df = report.to_dataframe()

fig = plt.figure()
sns.boxplot(data=df, x="day", y="views", hue="deviceType")
fig.savefig("./live-device-types.png")

To read up further, have a look at the documentation.

License

The analytix module for Python is licensed under the BSD-3-Clause License.

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 Distribution

analytix-1.1.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

analytix-1.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file analytix-1.1.1.tar.gz.

File metadata

  • Download URL: analytix-1.1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for analytix-1.1.1.tar.gz
Algorithm Hash digest
SHA256 45af394f210dc6a6c9b67731086b75837d2eb63b238b8d52aca49cd29bc47482
MD5 59855347566a2c758d0627ea4b7a9e95
BLAKE2b-256 e6f4e59f27af3dac54c54c240add3b8e6a36bdf868f983ea9bb3b328e0e7c0af

See more details on using hashes here.

File details

Details for the file analytix-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: analytix-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for analytix-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 323ef17859637284e5dd2d4146dc21a7642681eb802a0e06d096b7ff7c9eee6b
MD5 857f0789ed759854b4eb19f43001a732
BLAKE2b-256 a1aae2e14c933a0752bd9da2add638263160ee7294075a7f3e04621810a470c1

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