Skip to content

Utility

These are all the utility classes and functions you can use.

Bases: Enum

Enum of all heroes available in the Marvel Rivals API.

This enumeration provides convenient access to all hero identifiers that can be used with the API. Hero names are standardized to lowercase with appropriate spacing.

Examples:

>>> from marvelrivalsapi.utility import Heroes
>>> Heroes.SPIDER_MAN.value
'spider-man'
Source code in marvelrivalsapi\utility.py
class Heroes(Enum):
    """
    Enum of all heroes available in the Marvel Rivals API.

    This enumeration provides convenient access to all hero identifiers
    that can be used with the API. Hero names are standardized to lowercase
    with appropriate spacing.

    Examples
    --------
    >>> from marvelrivalsapi.utility import Heroes
    >>> Heroes.SPIDER_MAN.value
    'spider-man'
    """

    HULK = "hulk"
    THE_PUNISHER = "the punisher"
    STORM = "storm"
    LOKI = "loki"
    HUMAN_TORCH = "human torch"
    DOCTOR_STRANGE = "doctor strange"
    MANTIS = "mantis"
    HAWKEYE = "hawkeye"
    CAPTAIN_AMERICA = "captain america"
    ROCKET_RACCOON = "rocket raccoon"
    HELA = "hela"
    CLOAK_AND_DAGGER = "cloak & dagger"
    BLACK_PANTHER = "black panther"
    GROOT = "groot"
    MAGIK = "magik"
    MOON_KNIGHT = "moon knight"
    LUNA_SNOW = "luna snow"
    SQUIRREL_GIRL = "squirrel girl"
    BLACK_WIDOW = "black widow"
    IRON_MAN = "iron man"
    VENOM = "venom"
    SPIDER_MAN = "spider-man"
    MAGNETO = "magneto"
    SCARLET_WITCH = "scarlet witch"
    THOR = "thor"
    MISTER_FANTASTIC = "mister fantastic"
    WINTER_SOLDIER = "winter soldier"
    PENI_PARKER = "peni parker"
    STAR_LORD = "star-lord"
    NAMOR = "namor"
    ADAM_WARLOCK = "adam warlock"
    JEFF_THE_LAND_SHARK = "jeff the land shark"
    PSYLOCKE = "psylocke"
    WOLVERINE = "wolverine"
    INVISIBLE_WOMAN = "invisible woman"
    THE_THING = "the thing"
    IRON_FIST = "iron fist"
    EMMA_FROST = "emma frost"

Returns the full URL for an image resource.

This function prepends the base image URL to the provided image path.

Parameters:

Name Type Description Default
url str

The relative path of the image resource.

required

Returns:

Type Description
str

The complete URL to the image resource.

Examples:

>>> from marvelrivalsapi.utility import image
>>> image("/heroes/spider-man/icon.png")
'https://marvelrivalsapi.com/rivals/heroes/spider-man/icon.png'
Source code in marvelrivalsapi\utility.py
def image(url: str) -> str:
    """
    Returns the full URL for an image resource.

    This function prepends the base image URL to the provided image path.

    Parameters
    ----------
    url : str
        The relative path of the image resource.

    Returns
    -------
    str
        The complete URL to the image resource.

    Examples
    --------
    >>> from marvelrivalsapi.utility import image
    >>> image("/heroes/spider-man/icon.png")
    'https://marvelrivalsapi.com/rivals/heroes/spider-man/icon.png'
    """
    return f"{Endpoints.BASE_IMAGE_URL()}{url.split('rivals')[1]}"

Bases: Exception

Base class for all exceptions raised by the MarvelRivalsAPI.

This exception is raised when an API request fails due to an error returned by the server.

Parameters:

Name Type Description Default
res Response

The HTTP response that resulted in the error.

required

Attributes:

Name Type Description
response Response

The HTTP response object containing error details.

Source code in marvelrivalsapi\utility.py
class MarvelRivalsAPIError(Exception):
    """
    Base class for all exceptions raised by the MarvelRivalsAPI.

    This exception is raised when an API request fails due to an error
    returned by the server.

    Parameters
    ----------
    res : httpx.Response
        The HTTP response that resulted in the error.

    Attributes
    ----------
    response : httpx.Response
        The HTTP response object containing error details.
    """

    def __init__(self, res: httpx.Response) -> None:
        self.response = res
        try:
            message = f"{res.status_code}: {res.json()['error']}"
        except:
            message = f"{res.status_code}: {res.text}"
        super().__init__(message)