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.0.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.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: analytix-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 ed08e2a042e1d3f09caf7bd8804a0663bec4895c29df86983d6976af6da4f267
MD5 b1a999bf7ba3c9345212f1f737cd52e2
BLAKE2b-256 78d82e393c1c9e4b9e0e31b82b7579641b3d4aa3ea49f5152a9caaebdbef7c08

See more details on using hashes here.

File details

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

File metadata

  • Download URL: analytix-1.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1c2114c1e99be3e22cb31ca67cb2f951d1f6ffd2478dceeb6ef0906380d6062
MD5 6b316c547983afa1c9bdef27b7a40421
BLAKE2b-256 0da1d8b2438a656c6db2a913950e06e8bbaf9de99db35078475d39c6145bf331

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