Skip to main content

analytix logo

A simple yet powerful SDK for the YouTube Analytics API.

PyPI - Version PyPI - Python Version PyPI - Implementation

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 across multiple sessions without reauthorising
  • Extra support enables you to export reports in a variety of filetypes and to a number of DataFrame formats
  • Easy enough for beginners, but powerful enough for advanced users

Installation

Installing analytix

To install the latest stable version of analytix, use the following command:

pip install analytix

You can also install the latest development version using the following command:

pip install git+https://github.com/parafoxia/analytix

You may need to prefix these commands with a call to the Python interpreter depending on your OS and Python configuration.

Dependencies

Below is a list of analytix's dependencies. Note that the minimum version assumes you're using CPython 3.8. The latest versions of each library are always supported.

Name Min. version Required? Usage
urllib3 2.2.0 Yes Making HTTP requests
jwt 1.2.0 No Decoding JWT ID tokens (from v5.1)
openpyxl 3.0.0 No Exporting report data to Excel spreadsheets
pandas ~1.3.0 No Exporting report data to pandas DataFrames
polars 0.15.17 No Exporting report data to Polars DataFrames
pyarrow ~5.0.0 No Exporting report data to Apache Arrow tables and file formats

OAuth authentication

All requests to the YouTube Analytics API need to be authorised through OAuth 2. In order to do this, you will need a Google Developers project with the YouTube Analytics API enabled. You can find instructions on how to do that in the API setup guide.

Once a project is set up, analytix handles authorisation — including token refreshing — for you.

More details regarding how and when refresh tokens expire can be found on the Google Identity documentation.

Usage

Retrieving reports

The following example creates a CSV file containing basic info for the 10 most viewed videos, from most to least viewed, in the US in 2022:

from datetime import date

from analytix import Client

client = Client("secrets.json")
report = client.fetch_report(
    dimensions=("video",),
    filters={"country": "US"},
    metrics=("estimatedMinutesWatched", "views", "likes", "comments"),
    sort_options=("-estimatedMinutesWatched",),
    start_date=date(2022, 1, 1),
    end_date=date(2022, 12, 31),
    max_results=10,
)
report.to_csv("analytics.csv")

If you want to analyse this data using additional tools such as pandas, you can directly export the report as a DataFrame or table using the to_pandas(), to_arrow(), and to_polars() methods of the report instance. You can also save the report as a .tsv, .json, .xlsx, .parquet, or .feather file.

There are more examples in the GitHub repository.

Fetching group information

You can also fetch groups and group items:

from analytix import Client

# You can also use the client as context manager!
with Client("secrets.json") as client:
    groups = client.fetch_groups()
    group_items = client.fetch_group_items(groups[0].id)

Logging

If you want to see what analytix is doing, you can enable the packaged logger:

import analytix

analytix.enable_logging()

This defaults to showing all log messages of level INFO and above. To show more (or less) messages, pass a logging level as an argument.

Compatibility

CPython versions 3.8 through 3.14 and PyPy versions 3.9 through 3.11 are officially supported*. CPython 3.15-dev is provisionally supported*. Windows, MacOS, and Linux are all supported.

*For base analytix functionality; support cannot be guaranteed for functionality requiring external libraries.

Contributing

Contributions are very much welcome! To get started:

License

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

Metadata

Release files for analytix 5.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for analytix 5.5.1
File Size Uploaded
analytix-5.5.1.tar.gz 56.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for analytix 5.5.1
File Interpreter ABI Platform
analytix-5.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 137.9 kB

Release files / analytix-5.5.1.tar.gz

Download URL analytix-5.5.1.tar.gz
Size 56.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3fbf56e3598881b0319cc522237c50b18560a47329ce41100c431cf7021432d6
BLAKE2b-256 checksum
How to use checksums
2ceeb4596409c50ada715c6de685d91d4e482bf4a5cf31acc83ecc85ddc2a185
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / analytix-5.5.1-py3-none-any.whl

Download URL analytix-5.5.1-py3-none-any.whl
Size 81.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cca131a69899e2c6cc109aba6311989d8feef24967e430047cacc9ef0daf944d
BLAKE2b-256 checksum
How to use checksums
b82a003c7cb6b8cc3da4d87ba07be01b2f390f1538469a16d057b69819b73451
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

5.5.1 This release

2 release files

5.5.0

2 release files

5.4.0

2 release files

5.3.0

2 release files

5.2.1

2 release files

5.2.0

2 release files

5.1.2

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.2.3

2 release files

4.2.2

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.5

2 release files

4.1.4

2 release files

4.1.3

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.6.1

2 release files

3.6.0

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page