Skip to content

Profile provider

Profile

Get Userprofiles by XUID or Gamertag

pythonxbox.api.provider.profile.ProfileProvider(client)

Bases: RateLimitedProvider

Source code in src/pythonxbox/api/provider/ratelimitedprovider.py
def __init__(self, client: "XboxLiveClient") -> None:
    """
    Initialize Baseclass

    Args:
        client (:class:`XboxLiveClient`): Instance of XboxLiveClient
    """
    super().__init__(client)

    # Check that RATE_LIMITS set defined in the child class
    if hasattr(self, "RATE_LIMITS"):
        # Note: we cannot check (type(self.RATE_LIMITS) == dict) as the type hints have already defined it as such
        if "burst" and "sustain" in self.RATE_LIMITS:
            # We have the required keys, attempt to parse.
            # (type-checking for the values is performed in __parse_rate_limit_key)
            self.__handle_rate_limit_setup()
        else:
            raise XboxException(
                "RATE_LIMITS object missing required keys 'burst', 'sustain'"
            )
    else:
        raise XboxException(
            "RateLimitedProvider as parent class but RATE_LIMITS not set!"
        )

PROFILE_URL = 'https://profile.xboxlive.com' class-attribute instance-attribute

HEADERS_PROFILE = {'x-xbl-contract-version': '3'} class-attribute instance-attribute

SEPARATOR = ',' class-attribute instance-attribute

RATE_LIMITS = {'burst': 10, 'sustain': 30} class-attribute instance-attribute

get_profiles(xuid_list, **kwargs) async

Get profile info for list of xuids

Parameters:

Name Type Description Default
xuid_list list

List of xuids

required

Returns:

Type Description
ProfileResponse

class:ProfileResponse: Profile Response

Source code in src/pythonxbox/api/provider/profile/__init__.py
async def get_profiles(self, xuid_list: list[str], **kwargs) -> ProfileResponse:
    """
    Get profile info for list of xuids

    Args:
        xuid_list (list): List of xuids

    Returns:
        :class:`ProfileResponse`: Profile Response
    """
    post_data = {
        "settings": [
            ProfileSettings.GAME_DISPLAY_NAME,
            ProfileSettings.APP_DISPLAY_NAME,
            ProfileSettings.APP_DISPLAYPIC_RAW,
            ProfileSettings.GAMERSCORE,
            ProfileSettings.GAMERTAG,
            ProfileSettings.GAME_DISPLAYPIC_RAW,
            ProfileSettings.ACCOUNT_TIER,
            ProfileSettings.TENURE_LEVEL,
            ProfileSettings.XBOX_ONE_REP,
            ProfileSettings.PREFERRED_COLOR,
            ProfileSettings.LOCATION,
            ProfileSettings.BIOGRAPHY,
            ProfileSettings.WATERMARKS,
            ProfileSettings.REAL_NAME,
        ],
        "userIds": xuid_list,
    }
    url = self.PROFILE_URL + "/users/batch/profile/settings"
    resp = await self.client.session.post(
        url,
        json=post_data,
        headers=self.HEADERS_PROFILE,
        rate_limits=self.rate_limit_read,
        **kwargs,
    )
    resp.raise_for_status()
    return ProfileResponse.model_validate_json(resp.text)

get_profile_by_xuid(target_xuid, **kwargs) async

Get Userprofile by xuid

Parameters:

Name Type Description Default
target_xuid str

XUID to get profile for

required

Returns:

Type Description
ProfileResponse

class:ProfileResponse: Profile Response

Source code in src/pythonxbox/api/provider/profile/__init__.py
async def get_profile_by_xuid(self, target_xuid: str, **kwargs) -> ProfileResponse:
    """
    Get Userprofile by xuid

    Args:
        target_xuid: XUID to get profile for

    Returns:
        :class:`ProfileResponse`: Profile Response
    """
    url = self.PROFILE_URL + f"/users/xuid({target_xuid})/profile/settings"
    params = {
        "settings": self.SEPARATOR.join(
            [
                ProfileSettings.GAMERTAG,
                ProfileSettings.MODERN_GAMERTAG,
                ProfileSettings.MODERN_GAMERTAG_SUFFIX,
                ProfileSettings.UNIQUE_MODERN_GAMERTAG,
                ProfileSettings.REAL_NAME_OVERRIDE,
                ProfileSettings.BIOGRAPHY,
                ProfileSettings.LOCATION,
                ProfileSettings.GAMERSCORE,
                ProfileSettings.GAME_DISPLAYPIC_RAW,
                ProfileSettings.TENURE_LEVEL,
                ProfileSettings.ACCOUNT_TIER,
                ProfileSettings.XBOX_ONE_REP,
                ProfileSettings.PREFERRED_COLOR,
                ProfileSettings.WATERMARKS,
                ProfileSettings.IS_QUARANTINED,
            ]
        )
    }
    resp = await self.client.session.get(
        url,
        params=params,
        headers=self.HEADERS_PROFILE,
        rate_limits=self.rate_limit_read,
        **kwargs,
    )
    resp.raise_for_status()
    return ProfileResponse.model_validate_json(resp.text)

get_profile_by_gamertag(gamertag, **kwargs) async

Get Userprofile by gamertag

Parameters:

Name Type Description Default
gamertag str

Gamertag to get profile for

required

Returns:

Type Description
ProfileResponse

class:ProfileResponse: Profile Response

Source code in src/pythonxbox/api/provider/profile/__init__.py
async def get_profile_by_gamertag(self, gamertag: str, **kwargs) -> ProfileResponse:
    """
    Get Userprofile by gamertag

    Args:
        gamertag: Gamertag to get profile for

    Returns:
        :class:`ProfileResponse`: Profile Response
    """
    url = self.PROFILE_URL + f"/users/gt({gamertag})/profile/settings"
    params = {
        "settings": self.SEPARATOR.join(
            [
                ProfileSettings.GAMERTAG,
                ProfileSettings.MODERN_GAMERTAG,
                ProfileSettings.MODERN_GAMERTAG_SUFFIX,
                ProfileSettings.UNIQUE_MODERN_GAMERTAG,
                ProfileSettings.REAL_NAME_OVERRIDE,
                ProfileSettings.BIOGRAPHY,
                ProfileSettings.LOCATION,
                ProfileSettings.GAMERSCORE,
                ProfileSettings.GAME_DISPLAYPIC_RAW,
                ProfileSettings.TENURE_LEVEL,
                ProfileSettings.ACCOUNT_TIER,
                ProfileSettings.XBOX_ONE_REP,
                ProfileSettings.PREFERRED_COLOR,
                ProfileSettings.WATERMARKS,
                ProfileSettings.IS_QUARANTINED,
            ]
        )
    }
    resp = await self.client.session.get(
        url,
        params=params,
        headers=self.HEADERS_PROFILE,
        rate_limits=self.rate_limit_read,
        **kwargs,
    )
    resp.raise_for_status()
    return ProfileResponse.model_validate_json(resp.text)