Skip to content

Bet Value

Bet Value Class Documentation

Represents a specific betting value or option within a betting category.

This class dynamically loads all key-value pairs from the given JSON, converting the keys to snake_case and setting them as attributes.

Attributes:

Name Type Description
name str

The name of the bet or betting category.

bet_json dict

The raw JSON data representing the individual bet value.

espn_instance PYESPN

The parent ESPN API wrapper instance.

(dynamic attributes

All key-value pairs from bet_json, converted to snake_case.

Source code in pyespn/classes/betting.py
class BetValue:
    """
    Represents a specific betting value or option within a betting category.

    This class dynamically loads all key-value pairs from the given JSON, converting
    the keys to snake_case and setting them as attributes.

    Attributes:
        name (str): The name of the bet or betting category.
        bet_json (dict): The raw JSON data representing the individual bet value.
        espn_instance (PYESPN): The parent ESPN API wrapper instance.
        (dynamic attributes): All key-value pairs from `bet_json`, converted to snake_case.
    """

    def __init__(self, bet_name, bet_json, espn_instance):
        """
        Initializes a BetValue instance with the given name and JSON data.

        Args:
            bet_name (str): The name or label for the betting option.
            bet_json (dict): The raw JSON data for the bet value.
            espn_instance (PYESPN): The main ESPN API instance.
        """
        self.name = bet_name
        self.bet_json = bet_json
        self._espn_instance = espn_instance
        self._load_bet_data()

    def __repr__(self) -> str:
        """
        Returns a string representation of the BetValue instance.

        Returns:
            str: A formatted string identifying the betting value.
        """
        return f"<BetValue | {self.name}>"

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

    def _load_bet_data(self):
        """
        Parses the raw bet JSON and sets each item as an instance attribute.

        Converts each key in the JSON to snake_case before assigning it. This allows
        flexible access to all JSON properties as attributes.

        Note:
            If there's an error in setting attributes (e.g., due to invalid characters),
            the process silently fails for that key.
        """

        try:
            for key, value in self.bet_json.items():
                snake_key = camel_to_snake(key)
                setattr(self, snake_key, value)
        except AttributeError:
            pass

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

        Returns:
            dict: The betvalues's raw JSON data.
        """
        return self.bet_json

espn_instance property

PYESPN: the espn client instance associated with the class

__init__(bet_name, bet_json, espn_instance)

Initializes a BetValue instance with the given name and JSON data.

Parameters:

Name Type Description Default
bet_name str

The name or label for the betting option.

required
bet_json dict

The raw JSON data for the bet value.

required
espn_instance PYESPN

The main ESPN API instance.

required
Source code in pyespn/classes/betting.py
def __init__(self, bet_name, bet_json, espn_instance):
    """
    Initializes a BetValue instance with the given name and JSON data.

    Args:
        bet_name (str): The name or label for the betting option.
        bet_json (dict): The raw JSON data for the bet value.
        espn_instance (PYESPN): The main ESPN API instance.
    """
    self.name = bet_name
    self.bet_json = bet_json
    self._espn_instance = espn_instance
    self._load_bet_data()

__repr__()

Returns a string representation of the BetValue instance.

Returns:

Name Type Description
str str

A formatted string identifying the betting value.

Source code in pyespn/classes/betting.py
def __repr__(self) -> str:
    """
    Returns a string representation of the BetValue instance.

    Returns:
        str: A formatted string identifying the betting value.
    """
    return f"<BetValue | {self.name}>"

to_dict()

Converts the BetValue instance to its original JSON dictionary.

Returns:

Name Type Description
dict dict

The betvalues's raw JSON data.

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

    Returns:
        dict: The betvalues's raw JSON data.
    """
    return self.bet_json