Skip to content

Record

Record Class

Represents a statistical record for a player, team, or manufacturer in ESPN's data.

This class extracts and organizes record-related information from the provided JSON data, including general details and associated statistics.

Attributes:

Name Type Description
espn_instance object

An instance of the ESPN API client.

record_json dict

The raw JSON data containing record details.

stats list

A list of Stat objects representing individual statistical entries.

id str or None

The unique identifier for the record.

ref str or None

The API reference URL for the record.

name str or None

The full name of the record.

abbreviation str or None

The abbreviated form of the record name.

display_name str or None

The display name for the record.

short_display_name str or None

The short display name for the record.

description str or None

A brief description of the record.

type str or None

The type of record (e.g., season record, career record).

Methods:

Name Description
_load_record_data

Extracts and assigns values from record_json to class attributes.

Source code in pyespn/classes/stat.py
@validate_json("record_json")
class Record:
    """
    Represents a statistical record for a player, team, or manufacturer in ESPN's data.

    This class extracts and organizes record-related information from the provided JSON data,
    including general details and associated statistics.

    Attributes:
        espn_instance (object): An instance of the ESPN API client.
        record_json (dict): The raw JSON data containing record details.
        stats (list): A list of Stat objects representing individual statistical entries.
        id (str or None): The unique identifier for the record.
        ref (str or None): The API reference URL for the record.
        name (str or None): The full name of the record.
        abbreviation (str or None): The abbreviated form of the record name.
        display_name (str or None): The display name for the record.
        short_display_name (str or None): The short display name for the record.
        description (str or None): A brief description of the record.
        type (str or None): The type of record (e.g., season record, career record).

    Methods:
        _load_record_data(): Extracts and assigns values from record_json to class attributes.
    """

    def __init__(self, record_json, espn_instance):
        """
        Initializes a Record object.

        Args:
            record_json (dict): The JSON data representing the record.
            espn_instance (object): An instance of the ESPN API client.
        """
        self._espn_instance = espn_instance
        self.record_json = record_json
        self.stats = []
        self._load_record_data()

    def __repr__(self):
        """
        Returns a string representation of the Record instance.

        The representation includes the record's display name and abbreviation
        for easy identification.
        """
        return f"<Record | {self.display_name} ({self.abbreviation})>"

    @property
    def espn_instance(self):
        """
            PYESPN: the espn client instance associated with the class
        """
        return self._espn_instance

    def _load_record_data(self):
        """
        Parses and assigns values from record_json to class attributes.

        This method extracts record details such as names, abbreviations, descriptions, and stats.
        It also initializes Stat objects for each statistical entry found in the record.
        """
        self.id = self.record_json.get('id')
        self.ref = self.record_json.get('$ref')
        self.name = self.record_json.get('name')
        self.summary = self.record_json.get('summary')
        self.display_value = self.record_json.get('displayValue')
        self.value = self.record_json.get('value')
        self.abbreviation = self.record_json.get('abbreviation')
        self.display_name = self.record_json.get('displayName')
        self.short_display_name = self.record_json.get('shortDisplayName')
        self.description = self.record_json.get('description')
        self.type = self.record_json.get('type')
        self.name = self.record_json.get('name')
        for stat in self.record_json.get('stats', []):
            self.stats.append(Stat(stat_json=stat,
                                   espn_instance=self._espn_instance))

    def to_dict(self) -> dict:
        """
        Converts the Record instance to its original JSON dictionary.

        Returns:
            dict: The records's raw JSON data.
        """
        return self.record_json

espn_instance property

PYESPN: the espn client instance associated with the class

__init__(record_json, espn_instance)

Initializes a Record object.

Parameters:

Name Type Description Default
record_json dict

The JSON data representing the record.

required
espn_instance object

An instance of the ESPN API client.

required
Source code in pyespn/classes/stat.py
def __init__(self, record_json, espn_instance):
    """
    Initializes a Record object.

    Args:
        record_json (dict): The JSON data representing the record.
        espn_instance (object): An instance of the ESPN API client.
    """
    self._espn_instance = espn_instance
    self.record_json = record_json
    self.stats = []
    self._load_record_data()

__repr__()

Returns a string representation of the Record instance.

The representation includes the record's display name and abbreviation for easy identification.

Source code in pyespn/classes/stat.py
def __repr__(self):
    """
    Returns a string representation of the Record instance.

    The representation includes the record's display name and abbreviation
    for easy identification.
    """
    return f"<Record | {self.display_name} ({self.abbreviation})>"

to_dict()

Converts the Record instance to its original JSON dictionary.

Returns:

Name Type Description
dict dict

The records's raw JSON data.

Source code in pyespn/classes/stat.py
def to_dict(self) -> dict:
    """
    Converts the Record instance to its original JSON dictionary.

    Returns:
        dict: The records's raw JSON data.
    """
    return self.record_json