reports#

class analytix.reports.ColumnType(value)#

An enumeration of possible column types.

DIMENSION = 'DIMENSION'#
METRIC = 'METRIC'#
class analytix.reports.DataType(value)#

An enumeration of possible data types.

STRING = 'STRING'#
INTEGER = 'INTEGER'#
FLOAT = 'FLOAT'#
class analytix.reports.ColumnHeader(name: str, column_type: analytix.reports.ColumnType, data_type: analytix.reports.DataType)#

A dataclass representing a column header.

Parameters
  • name – The column name.

  • column_type – The column type.

  • data_type – The column’s data type.

classmethod from_json(header: dict[str, str]) ColumnHeader#

Create a column header from its JSON representation.

Parameters

header – The JSON representation of the column header.

Returns

The newly created ColumnHeader instance.

class analytix.reports.Report(data: dict[t.Any, t.Any], type: ReportType)#

A class representing a YouTube Analytics API report. You will never need to manually create an instance of this.

Parameters
  • data – The raw data retrieved from the API.

  • type – The report type.

data#

The raw data retrieved from the API.

type#

The report type.

property shape: tuple[int, int]#

The shape of the report in the format (rows, columns).

property rows: List[List[Union[str, int, float]]]#

The rows in the report.

New in version 3.5.0.

property column_headers: list[ColumnHeader]#

The column headers in the report.

New in version 3.5.0.

property columns: list[str]#

The names of all columns in the report.

Changed in version 3.5.0: This is now a property.

property dimensions: set[str]#

The names of columns which are dimensions in the report.

New in version 3.3.0.

property metrics: set[str]#

The names of columns which are metrics in the report.

New in version 3.3.0.

property ordered_dimensions: list[str]#

The names of columns which are dimensions in the report in the order in which they appear.

New in version 3.5.0.

property ordered_metrics: list[str]#

The names of columns which are metrics in the report in the order in which they appear.

New in version 3.5.0.

to_dataframe(*, skip_date_conversion: bool = False) pd.DataFrame#

Export the report data to a pandas or Modin DataFrame. If you wish to use Modin, you are responsible for selecting and initialising your desired engine.

Keyword Arguments

skip_date_conversion – Whether to skip automatically converting date columns to the datetime64[ns] format. Defaults to False.

Returns

The newly created DataFrame.

to_arrow_table(*, skip_date_conversion: bool = False) pa.Table#

Export the report data to an Apache Arrow Table.

Keyword Arguments

skip_date_conversion – Whether to skip automatically converting date columns to the datetime64[ns] format. Defaults to False.

Returns

The newly constructed Apache Arrow Table.

New in version 3.2.0.

to_json(path: str, *, indent: int = 4) analytix.reports.JSONReportWriter#

Write the report data to a JSON file.

Note

This method can also be run asynchronously by awaiting it.

Parameters

path – The path the file should be saved to.

Keyword Arguments

indent – The amount of indentation the data should be written with. Defaults to 4.

Returns

The report writer. This is done to allow this method to run sync or async in a typed context.

to_csv(path: str, *, delimiter: str = ',') analytix.reports.CSVReportWriter#

Write the report data to a CSV file.

Note

This method can also be run asynchronously by awaiting it.

Parameters

path – The path the file should be saved to.

Keyword Arguments

delimiter – The delimiter to use. Defaults to a comma. Passing a tab here will save the file as a TSV instead.

Returns

The report writer. This is done to allow this method to run sync or async in a typed context.

to_excel(path: str, *, sheet_name: str = 'Analytics') None#

Write the report data to an Excel spreadsheet.

Parameters

path – The path the file should be saved to.

Keyword Arguments

sheet_name – The name for the worksheet.

New in version 3.1.0.

to_feather(path: str) None#

Write the report data to an Apache Feather file.

Parameters

path – The path the file should be saved to.

New in version 3.2.0.

to_parquet(path: str) None#

Write the report data to an Apache Parquet file.

Parameters

path – The path the file should be saved to.

New in version 3.2.0.