Skip to content

resources

Report resources.

These mirror YouTube Analytics API resources, but lack quality-of-life features that the analytix interfaces provide.

ColumnHeader dataclass

A column header.

Column headers contain various information about the columns in the report. You will never need to create one of these yourself.

Parameters:

Name Type Description Default
name str

The column name.

required
data_type DataType

The data type of the column.

required
column_type ColumnType

The column type.

required
Source code in analytix/reports/resources.py
@dataclass(frozen=True)
class ColumnHeader:
    """A column header.

    Column headers contain various information about the columns in the
    report. You will never need to create one of these yourself.

    Parameters
    ----------
    name
        The column name.
    data_type
        The data type of the column.
    column_type
        The column type.
    """

    __slots__ = ("name", "data_type", "column_type")

    name: str
    data_type: "DataType"
    column_type: "ColumnType"

    @property
    def data(self) -> Dict[str, Any]:
        """The raw data for this column header in JSON format.

        Returns
        -------
        Dict[str, Any]
            The response data.
        """
        return {
            "name": self.name,
            "dataType": self.data_type.value,
            "columnType": self.column_type.value,
        }

data property

data: Dict[str, Any]

The raw data for this column header in JSON format.

Returns:

Type Description
Dict[str, Any]

The response data.

ColumnType

Bases: Enum

An enum of column types. Can be DIMENSION or METRIC.

Source code in analytix/reports/resources.py
class ColumnType(Enum):
    """An enum of column types. Can be `DIMENSION` or `METRIC`."""

    DIMENSION = "DIMENSION"
    """Of type dimension."""

    METRIC = "METRIC"
    """Of type metric."""

DIMENSION class-attribute instance-attribute

DIMENSION = 'DIMENSION'

Of type dimension.

METRIC class-attribute instance-attribute

METRIC = 'METRIC'

Of type metric.

DataType

Bases: Enum

An enum of data types. Can be STRING, INTEGER, or FLOAT.

Source code in analytix/reports/resources.py
class DataType(Enum):
    """An enum of data types. Can be `STRING`, `INTEGER`, or `FLOAT`."""

    STRING = "STRING"
    """A string type."""

    INTEGER = "INTEGER"
    """An integer type."""

    FLOAT = "FLOAT"
    """A float type."""

FLOAT class-attribute instance-attribute

FLOAT = 'FLOAT'

A float type.

INTEGER class-attribute instance-attribute

INTEGER = 'INTEGER'

An integer type.

STRING class-attribute instance-attribute

STRING = 'STRING'

A string type.

ResultTable dataclass

A result table.

This is the resource type that gets sent from the YouTube Analytics API.

Parameters:

Name Type Description Default
kind Literal['youtubeAnalytics#resultTable']

The kind of resource this is. This will always be "youtubeAnalytics#resultTable".

required
column_headers List[ColumnHeader]

Information about the columns in the report, such as the name and the column type.

required
rows List[List[Union[str, int, float]]]

The rows in the report. This will be a list of lists.

required
See Also

Instances of this class are presented as part of Report instances.

Source code in analytix/reports/resources.py
@dataclass(frozen=True)
class ResultTable:
    """A result table.

    This is the resource type that gets sent from the YouTube Analytics
    API.

    Parameters
    ----------
    kind
        The kind of resource this is. This will always be
        "youtubeAnalytics#resultTable".
    column_headers
        Information about the columns in the report, such as the name
        and the column type.
    rows
        The rows in the report. This will be a list of lists.

    See Also
    --------
    Instances of this class are presented as part of `Report` instances.
    """

    kind: Literal["youtubeAnalytics#resultTable"]
    column_headers: List["ColumnHeader"]
    rows: List[List[Union[str, int, float]]]

    @classmethod
    def from_json(cls, data: Dict[str, Any]) -> "ResultTable":
        """Create a new `ResultTable` instance from JSON data.

        Parameters
        ----------
        data
            The raw JSON data from the API.

        Returns
        -------
        ResultTable
            The newly created instance.
        """
        return cls(
            data["kind"],
            [
                ColumnHeader(
                    header["name"],
                    DataType(header["dataType"]),
                    ColumnType(header["columnType"]),
                )
                for header in data["columnHeaders"]
            ],
            data["rows"],
        )

    @property
    def data(self) -> Dict[str, Any]:
        """The raw data for this result table in JSON format.

        Returns
        -------
        Dict[str, Any]
            The response data.
        """
        return {
            "kind": self.kind,
            "columnHeaders": [header.data for header in self.column_headers],
            "rows": self.rows,
        }

data property

data: Dict[str, Any]

The raw data for this result table in JSON format.

Returns:

Type Description
Dict[str, Any]

The response data.

from_json classmethod

from_json(data: Dict[str, Any]) -> ResultTable

Create a new ResultTable instance from JSON data.

Parameters:

Name Type Description Default
data Dict[str, Any]

The raw JSON data from the API.

required

Returns:

Type Description
ResultTable

The newly created instance.

Source code in analytix/reports/resources.py
@classmethod
def from_json(cls, data: Dict[str, Any]) -> "ResultTable":
    """Create a new `ResultTable` instance from JSON data.

    Parameters
    ----------
    data
        The raw JSON data from the API.

    Returns
    -------
    ResultTable
        The newly created instance.
    """
    return cls(
        data["kind"],
        [
            ColumnHeader(
                header["name"],
                DataType(header["dataType"]),
                ColumnType(header["columnType"]),
            )
            for header in data["columnHeaders"]
        ],
        data["rows"],
    )