Skip to content

MangaDex

Proxymiity edited this page Dec 28, 2021 · 9 revisions

MangaDexPy.MangaDex

Represents the MangaDex API Client.

Yields:

  • api str
    The URL of the MangaDex API.
  • net_api str
    The URL of the MangaDex Network API.
  • session Requests.Session
    The Session object used to store cookies and headers.
  • login_success bool
    Whether or not login has succeeded.
  • session_token str
    The Session token used by the MangaDex API to authenticate the user.
  • refresh_token str
    The Refresh token used to regenerate a Session token after it has expired.
  • rate_limit float
    The rate limit to apply to for loops. 0.2 means a request every 0.2 seconds, meaning 5 rqps. 0.25 is the default to stay safe.

login(username: str, password: str)

Logs in to MangaDex using an username and a password.
You might need to verify your email address in order to use the API or certain API calls, so bear that in mind if it isn't verified.
Logging in isn't required, but some features requires that you do.
Please note that the wrapper only sends credentials to MangaDex. Your credentials are never stored locally.

Returns: True if successful.
Raises: LoginError if credentials are invalid, APIError if something went wrong.
Arguments:

  • username: Your MangaDex username.
  • password: Your MangaDex password.

login_token(token: str)

Logs in to MangaDex using a refresh token.

Returns: True if successful.
Raises: LoginError if credentials are invalid, APIError if something went wrong.
Arguments:

  • token: A valid MangaDex refresh token.

logout()

Resets the MangaDex object.

Returns: Nothing


refresh_session(token: str = None)

Refreshes the session using the refresh token.

Returns: True if successful.
Raises: LoginError if token has expired, APIError if something went wrong.
Arguments:

  • token: The refresh token.

check_session()

Checks if the stored Authorization token is still valid.

Returns: True if the token is valid, False if it has expired
Raises: APIError if something went wrong.


get_manga(uuid: str, includes: list = None)

Gets a manga with the specified UUID.

Returns: Manga
Raises:

Arguments:

  • uuid: The UUID of the Manga.
  • includes: Relationships to populate (e.g. ['author', 'artist'] will give direct reference for Author and Artist in the Manga object)

get_chapter(uuid: str, includes: list = None)

Gets a chapter with the specified UUID.

Returns: Chapter
Raises:

Arguments:

  • uuid: The UUID of the Chapter.
  • includes: Relationships to populate (e.g. ['scanlation_group', 'user'] will give direct reference for Group and User in the Chapter object)

get_chapters(ids: Array[str], includes: list = None)

Gets a chapter with the specified UUID.

Returns: Array[Chapter]
Raises:

Arguments:

  • ids: A list of Chapter UUIDs.
  • includes: Relationships to populate (e.g. ['scanlation_group', 'user'] will give direct reference for Group and User in Chapters objects)

get_manga_chapters(mg: Manga, params: dict = None, includes: list = None)

Gets all chapters associated with a specific Manga.

Returns: Array[Chapter]
Raises:

Arguments:

  • mg: Manga
  • params: Custom dictionary of parameters to pass to the search utility.
  • includes: Relationships to populate (e.g. ['scanlation_group', 'user'] will give direct reference for Group and User in Chapters objects)

get_manga_covers(mg: Manga, params: dict = None)

Gets all covers associated with a specific Manga.

Returns: Array[Cover]
Raises:

Arguments:

  • mg: Manga
  • params: Custom dictionary of parameters to pass to the search utility.

get_cover(uuid: str)

Gets a cover with the specified UUID.

Returns: Cover
Raises:

Arguments:

  • uuid: The UUID of the Cover.

read_chapter(ch: Chapter, force_443: bool = False)

Pulls a chapter from the MD@H Network. more info

Returns: NetworkChapter
Raises: APIError
Arguments:

  • ch: Chapter
  • force_443: Forces the backend to get a node with the standard HTTPS port

network_report(url: str, success: bool, cache_header: bool, req_bytes: int, req_duration: int)

Reports statistics for a chapter pulled from the MD@H Network. more info

Returns: True on success
Raises: APIError
Arguments:

  • url: The full URL of the retrieved image.
  • success: Whether or not the image was retrieved successfully.
  • cache_header: Whether or not the X-Cache header returned HIT.
  • req_bytes: Bytes transferred during the request.
  • req_duration: The duration of the request.

get_group(uuid: str, includes: list = None)

Gets a group with the specified UUID.

Returns: Group
Raises:

Arguments:

  • uuid: The UUID of the Group.
  • includes: Relationships to populate (e.g. ['scanlation_group', 'user'] will give direct reference for Group and User in Chapters objects)

get_user(uuid: str = 'me')

Gets an user with the specified UUID.

Returns: User
Raises:

Arguments:

  • uuid: The UUID of the User. Leave empty to select the currently logged in user.

get_user_list(limit: int = 100)

Gets the current user's list.
You must be logged in to use this call.

Returns: Array[Manga, ...]
Raises:

Arguments:

  • limit: How much Mangas to retrieve. Note that each multiple of 100 will make a new request to the API, bear that in mind when it comes to ratelimiting.

get_user_updates(limit: int = 100, params: dict = None)

Gets the current user's manga feed.
You must be logged in to use this call.

Returns: Array[Chapter, ...]
Raises:

Arguments:

  • limit: How much Chapters to retrieve. Note that each multiple of 100 will make a new request to the API, bear that in mind when it comes to ratelimiting.
  • params: Custom dictionary of parameters to pass to the search utility.

get_author(uuid: str)

Gets an author/artist with the specified UUID.
Note: authors and artists are the same API-wise

Returns: Author
Raises:

Arguments:

  • uuid: The UUID of the Author.

get_artist(uuid: str)

Alias for get_author() above.


transform_ids(obj: str, content: Array[str])

Transforms legacy IDs to UUIDs.

Returns: Array{int: str, ...}
Raises: APIError
Arguments:

  • obj: What to convert (can be either 'manga', 'chapter', 'group', 'tag').
  • content: An array of legay IDs.

search(obj: str, params: dict, limit: int = 100)

Searches an object through the API.

Returns: Array[Object]
Raises:

Arguments:

  • obj: Object to search (can be either 'manga', 'chapter', 'group', 'author', 'cover', 'user').
  • params: Parameters to pass to the search utility.
  • limit: How much objects to retrieve. Note that each multiple of 100 will make a new request to the API, bear that in mind when it comes to ratelimiting.

MangaDexPy.MDException

Base class for exceptions.

MangaDexPy.APIError -> MDException

Represents an API Error.

Yields:

  • status int
    The HTTP code returned by the request made to the API.
  • data dict(Response)/str
    Data representing what happened with the API. Can be a dictionary.

Underlying errors:

  • MangaDexPy.NoContentError -> APIError

    Represents a 404 NOT FOUND status returned by the API.

  • MangaDexPy.LoginError -> APIError

    'Logging in failed'-type error.

MangaDexPy.NotLoggedInError -> MDException

'Logging in failed'-type error.

MangaDexPy.NoResultsError -> MDException

A search request returned nothing.