Skip to content

baseuniverse

roblox.bases.baseuniverse

This file contains the BaseUniverse object, which represents a Roblox universe ID. It also contains the UniverseLiveStats object, which represents a universe's live stats.

BaseUniverse (BaseItem)

Represents a Roblox universe ID.

Attributes:

Name Type Description
id int

The universe ID.

Source code in roblox/bases/baseuniverse.py
class BaseUniverse(BaseItem):
    """
    Represents a Roblox universe ID.

    Attributes:
        id: The universe ID.
    """

    def __init__(self, client: Client, universe_id: int):
        """
        Arguments:
            client: The Client this object belongs to.
            universe_id: The universe ID.
        """

        self._client: Client = client
        self.id: int = universe_id

    async def get_favorite_count(self) -> int:
        """
        Grabs the universe's favorite count.

        Returns:
            The universe's favorite count.
        """
        favorite_count_response = await self._client.requests.get(
            url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/favorites/count")
        )
        favorite_count_data = favorite_count_response.json()
        return favorite_count_data["favoritesCount"]

    async def is_favorited(self) -> bool:
        """
        Grabs the authenticated user's favorite status for this game.

        Returns:
            Whether the authenticated user has favorited this game.
        """
        is_favorited_response = await self._client.requests.get(
            url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/favorites")
        )
        is_favorited_data = is_favorited_response.json()
        return is_favorited_data["isFavorited"]

    def get_badges(self, page_size: int = 10, sort_order: SortOrder = SortOrder.Ascending,
                   max_items: int = None) -> PageIterator:
        """
        Gets the universe's badges.

        Arguments:
            page_size: How many members should be returned for each page.
            sort_order: Order in which data should be grabbed.
            max_items: The maximum items to return when looping through this object.

        Returns:
            A PageIterator containing this universe's badges.
        """

        return PageIterator(
            client=self._client,
            url=self._client.url_generator.get_url("badges", f"v1/universes/{self.id}/badges"),
            page_size=page_size,
            sort_order=sort_order,
            max_items=max_items,
            handler=_universe_badges_handler,
        )

    async def get_live_stats(self) -> UniverseLiveStats:
        """
        Gets the universe's live stats.
        This data does not update live. These are just the stats that are shown on the website's live stats display.

        Returns:
            The universe's live stats.
        """
        stats_response = await self._client.requests.get(
            url=self._client.url_generator.get_url("develop", f"v1/universes/{self.id}/live-stats")
        )
        stats_data = stats_response.json()
        return UniverseLiveStats(data=stats_data)

    def get_gamepasses(self, page_size: int = 10, sort_order: SortOrder = SortOrder.Ascending,
                       max_items: int = None) -> PageIterator:
        """
        Gets the universe's gamepasses.

        Arguments:
            page_size: How many members should be returned for each page.
            sort_order: Order in which data should be grabbed.
            max_items: The maximum items to return when looping through this object.

        Returns:
            A PageIterator containing the universe's gamepasses.
        """

        return PageIterator(
            client=self._client,
            url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/game-passes"),
            page_size=page_size,
            sort_order=sort_order,
            max_items=max_items,
            handler=lambda client, data: GamePass(client, data),
        )

    async def get_social_links(self) -> List[SocialLink]:
        """
        Gets the universe's social links.

        Returns:
            A list of the universe's social links.
        """

        links_response = await self._client.requests.get(
            url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/social-links/list")
        )
        links_data = links_response.json()["data"]
        return [SocialLink(client=self._client, data=link_data) for link_data in links_data]

__init__(self, client: Client, universe_id: int) special

Parameters:

Name Type Description Default
client Client

The Client this object belongs to.

required
universe_id int

The universe ID.

required
Source code in roblox/bases/baseuniverse.py
def __init__(self, client: Client, universe_id: int):
    """
    Arguments:
        client: The Client this object belongs to.
        universe_id: The universe ID.
    """

    self._client: Client = client
    self.id: int = universe_id

get_badges(self, page_size: int = 10, sort_order: SortOrder = <SortOrder.Ascending: 'Asc'>, max_items: int = None) -> PageIterator

Gets the universe's badges.

Parameters:

Name Type Description Default
page_size int

How many members should be returned for each page.

10
sort_order SortOrder

Order in which data should be grabbed.

<SortOrder.Ascending: 'Asc'>
max_items int

The maximum items to return when looping through this object.

None

Returns:

Type Description
PageIterator

A PageIterator containing this universe's badges.

Source code in roblox/bases/baseuniverse.py
def get_badges(self, page_size: int = 10, sort_order: SortOrder = SortOrder.Ascending,
               max_items: int = None) -> PageIterator:
    """
    Gets the universe's badges.

    Arguments:
        page_size: How many members should be returned for each page.
        sort_order: Order in which data should be grabbed.
        max_items: The maximum items to return when looping through this object.

    Returns:
        A PageIterator containing this universe's badges.
    """

    return PageIterator(
        client=self._client,
        url=self._client.url_generator.get_url("badges", f"v1/universes/{self.id}/badges"),
        page_size=page_size,
        sort_order=sort_order,
        max_items=max_items,
        handler=_universe_badges_handler,
    )

get_favorite_count(self) -> int async

Grabs the universe's favorite count.

Returns:

Type Description
int

The universe's favorite count.

Source code in roblox/bases/baseuniverse.py
async def get_favorite_count(self) -> int:
    """
    Grabs the universe's favorite count.

    Returns:
        The universe's favorite count.
    """
    favorite_count_response = await self._client.requests.get(
        url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/favorites/count")
    )
    favorite_count_data = favorite_count_response.json()
    return favorite_count_data["favoritesCount"]

get_gamepasses(self, page_size: int = 10, sort_order: SortOrder = <SortOrder.Ascending: 'Asc'>, max_items: int = None) -> PageIterator

Gets the universe's gamepasses.

Parameters:

Name Type Description Default
page_size int

How many members should be returned for each page.

10
sort_order SortOrder

Order in which data should be grabbed.

<SortOrder.Ascending: 'Asc'>
max_items int

The maximum items to return when looping through this object.

None

Returns:

Type Description
PageIterator

A PageIterator containing the universe's gamepasses.

Source code in roblox/bases/baseuniverse.py
def get_gamepasses(self, page_size: int = 10, sort_order: SortOrder = SortOrder.Ascending,
                   max_items: int = None) -> PageIterator:
    """
    Gets the universe's gamepasses.

    Arguments:
        page_size: How many members should be returned for each page.
        sort_order: Order in which data should be grabbed.
        max_items: The maximum items to return when looping through this object.

    Returns:
        A PageIterator containing the universe's gamepasses.
    """

    return PageIterator(
        client=self._client,
        url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/game-passes"),
        page_size=page_size,
        sort_order=sort_order,
        max_items=max_items,
        handler=lambda client, data: GamePass(client, data),
    )

get_live_stats(self) -> UniverseLiveStats async

Gets the universe's live stats. This data does not update live. These are just the stats that are shown on the website's live stats display.

Returns:

Type Description
UniverseLiveStats

The universe's live stats.

Source code in roblox/bases/baseuniverse.py
async def get_live_stats(self) -> UniverseLiveStats:
    """
    Gets the universe's live stats.
    This data does not update live. These are just the stats that are shown on the website's live stats display.

    Returns:
        The universe's live stats.
    """
    stats_response = await self._client.requests.get(
        url=self._client.url_generator.get_url("develop", f"v1/universes/{self.id}/live-stats")
    )
    stats_data = stats_response.json()
    return UniverseLiveStats(data=stats_data)

Gets the universe's social links.

Returns:

Type Description
List[SocialLink]

A list of the universe's social links.

Source code in roblox/bases/baseuniverse.py
async def get_social_links(self) -> List[SocialLink]:
    """
    Gets the universe's social links.

    Returns:
        A list of the universe's social links.
    """

    links_response = await self._client.requests.get(
        url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/social-links/list")
    )
    links_data = links_response.json()["data"]
    return [SocialLink(client=self._client, data=link_data) for link_data in links_data]

is_favorited(self) -> bool async

Grabs the authenticated user's favorite status for this game.

Returns:

Type Description
bool

Whether the authenticated user has favorited this game.

Source code in roblox/bases/baseuniverse.py
async def is_favorited(self) -> bool:
    """
    Grabs the authenticated user's favorite status for this game.

    Returns:
        Whether the authenticated user has favorited this game.
    """
    is_favorited_response = await self._client.requests.get(
        url=self._client.url_generator.get_url("games", f"v1/games/{self.id}/favorites")
    )
    is_favorited_data = is_favorited_response.json()
    return is_favorited_data["isFavorited"]

UniverseLiveStats

Represents a universe's live stats.

Attributes:

Name Type Description
total_player_count int

The amount of players present in this universe's subplaces.

game_count int

The amount of active servers for this universe's subplaces.

player_counts_by_device_type Dict[str, int]

A dictionary where the keys are device types and the values are the amount of this universe's subplace's active players which are on that device type.

Source code in roblox/bases/baseuniverse.py
class UniverseLiveStats:
    """
    Represents a universe's live stats.

    Attributes:
        total_player_count: The amount of players present in this universe's subplaces.
        game_count: The amount of active servers for this universe's subplaces.
        player_counts_by_device_type: A dictionary where the keys are device types and the values are the amount of
                                      this universe's subplace's active players which are on that device type.
    """

    def __init__(self, data: dict):
        self.total_player_count: int = data["totalPlayerCount"]
        self.game_count: int = data["gameCount"]
        self.player_counts_by_device_type: Dict[str, int] = data["playerCountsByDeviceType"]

__init__(self, data: dict) special

Source code in roblox/bases/baseuniverse.py
def __init__(self, data: dict):
    self.total_player_count: int = data["totalPlayerCount"]
    self.game_count: int = data["gameCount"]
    self.player_counts_by_device_type: Dict[str, int] = data["playerCountsByDeviceType"]