Skip to content

badges

This module contains classes intended to parse and deal with data from Roblox badge information endpoints.

Badge

Bases: BaseBadge

Represents a badge from the API.

Attributes:

Name Type Description
id int

The badge Id.

name str

The name of the badge.

description str

The badge description.

display_name str

The localized name of the badge.

display_description str

The localized badge description.

enabled bool

Whether or not the badge is enabled.

icon BaseAsset

The badge icon.

display_icon BaseAsset

The localized badge icon.

created datetime

When the badge was created.

updated datetime

When the badge was updated.

statistics BadgeStatistics

Badge award statistics.

awarding_universe PartialUniverse

The universe the badge is being awarded from.

Source code in roblox/badges.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Badge(BaseBadge):
    """
    Represents a badge from the API.

    Attributes:
        id: The badge Id.
        name: The name of the badge.
        description: The badge description.
        display_name: The localized name of the badge.
        display_description: The localized badge description.
        enabled: Whether or not the badge is enabled.
        icon: The badge icon.
        display_icon: The localized badge icon.
        created: When the badge was created.
        updated: When the badge was updated.
        statistics: Badge award statistics.
        awarding_universe: The universe the badge is being awarded from.
    """

    def __init__(self, client: Client, data: dict):
        """
        Arguments:
            client: The Client to be used when getting information on badges.
            data: The data from the endpoint.
        """
        self.id: int = data["id"]

        super().__init__(client=client, badge_id=self.id)

        self.name: str = data["name"]
        self.description: str = data["description"]
        self.display_name: str = data["displayName"]
        self.display_description: str = data["displayDescription"]
        self.enabled: bool = data["enabled"]
        self.icon: BaseAsset = BaseAsset(client=client, asset_id=data["iconImageId"])
        self.display_icon: BaseAsset = BaseAsset(client=client, asset_id=data["displayIconImageId"])
        self.created: datetime = parse(data["created"])
        self.updated: datetime = parse(data["updated"])

        self.statistics: BadgeStatistics = BadgeStatistics(data=data["statistics"])
        self.awarding_universe: PartialUniverse = PartialUniverse(client=client, data=data["awardingUniverse"])

__init__(client, data)

Parameters:

Name Type Description Default
client Client

The Client to be used when getting information on badges.

required
data dict

The data from the endpoint.

required
Source code in roblox/badges.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def __init__(self, client: Client, data: dict):
    """
    Arguments:
        client: The Client to be used when getting information on badges.
        data: The data from the endpoint.
    """
    self.id: int = data["id"]

    super().__init__(client=client, badge_id=self.id)

    self.name: str = data["name"]
    self.description: str = data["description"]
    self.display_name: str = data["displayName"]
    self.display_description: str = data["displayDescription"]
    self.enabled: bool = data["enabled"]
    self.icon: BaseAsset = BaseAsset(client=client, asset_id=data["iconImageId"])
    self.display_icon: BaseAsset = BaseAsset(client=client, asset_id=data["displayIconImageId"])
    self.created: datetime = parse(data["created"])
    self.updated: datetime = parse(data["updated"])

    self.statistics: BadgeStatistics = BadgeStatistics(data=data["statistics"])
    self.awarding_universe: PartialUniverse = PartialUniverse(client=client, data=data["awardingUniverse"])

BadgeStatistics

Attributes:

Name Type Description
past_day_awarded_count int

How many instances of this badge were awarded in the last day.

awarded_count int

How many instances of this badge have been awarded.

win_rate_percentage int

Percentage of players who have joined the parent universe have been awarded this badge.

Source code in roblox/badges.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class BadgeStatistics:
    """
    Attributes:
        past_day_awarded_count: How many instances of this badge were awarded in the last day.
        awarded_count: How many instances of this badge have been awarded.
        win_rate_percentage: Percentage of players who have joined the parent universe have been awarded this badge.
    """

    def __init__(self, data: dict):
        """
        Arguments:
            data: The raw input data.
        """
        self.past_day_awarded_count: int = data["pastDayAwardedCount"]
        self.awarded_count: int = data["awardedCount"]
        self.win_rate_percentage: int = data["winRatePercentage"]

    def __repr__(self):
        return f"<{self.__class__.__name__} past_day_awarded_count={self.past_day_awarded_count} awarded_count={self.awarded_count} win_rate_percentage={self.win_rate_percentage}>"

__init__(data)

Parameters:

Name Type Description Default
data dict

The raw input data.

required
Source code in roblox/badges.py
29
30
31
32
33
34
35
36
def __init__(self, data: dict):
    """
    Arguments:
        data: The raw input data.
    """
    self.past_day_awarded_count: int = data["pastDayAwardedCount"]
    self.awarded_count: int = data["awardedCount"]
    self.win_rate_percentage: int = data["winRatePercentage"]