Sessions Reference

Structures to make several calls to the Kemono API with persistent cookies and pooling connections.

Session

class pykemo.sessions.session.KemoSession

Kemono HTTP session.

async close()

A wrapper for closing the async session.

Return type:

None

async delete(endpoint, *, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges a DELETE request.

Parameters:
  • endpoint (UrlLike) – The endpoint to map to.

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

async get(endpoint, *, params=None, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges a GET request.

Parameters:
  • endpoint (UrlLike) – The endpoint to map to.

  • params (Optional[dict]) – A dict with the parameters of the request. Usually of type dict[str, int | str | None]

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

async head(endpoint, *, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges a HEAD request.

Parameters:
  • endpoint (UrlLike) – The endpoint to map to.

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

async options(endpoint, *, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges an OPTIONS request.

Parameters:
  • endpoint (UrlLike) – The endpoint to map to.

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

async patch(endpoint, *, data=None, json=None, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges a PATCH request.

Warning

data and json cannot be used both at once.

Parameters:
  • endpoint (UrlLike) – The endpoint to map to.

  • data (Optional[Any]) – Dictionary, list of file-like object to send in the body of the request, defaults to None

  • json (Optional[dict]) – JSON-like to send in the body of the request, defaults to None.

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

async post(endpoint, *, data=None, json=None, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges a POST request.

Warning

data and json cannot be used both at once.

Parameters:
  • endpoint (UrlLike) – The endpoint to map to.

  • data (Optional[Any]) – Dictionary, list of file-like object to send in the body of the request.

  • json (Optional[dict]) – JSON-like to send in the body of the request.

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

async put(endpoint, *, data=None, json=None, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges a PUT request.

Warning

data and json cannot be used both at once.

Parameters:
  • endpoint (UrlLike) – The endpoint to map to.

  • data (Optional[Any]) – Dictionary, list of file-like object to send in the body of the request, defaults to None

  • json (Optional[dict]) – JSON-like to send in the body of the request, defaults to None.

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

async request(method, endpoint, *, base_url=UrlType.API, api_version=APIVersion.V1, data_sv=3, **kwargs)

Overcharges the request to include the session cookie.

Parameters:
  • method (str) – The HTTP method to use.

  • endpoint (UrlLike) – The endpoint to map to.

  • base_url (Optional[UrlType]) – The root URL to use.

  • api_version (Optional[APIVersion]) – The internal version of the API to use for the endpoints, defaults to APIVersion.V1

  • data_sv (int, optional) – The server number to format the base URL with, in case it is of type UrlType.DATA

Returns:

The HTTP response.

Return type:

ClientResponse

Parameters:

cookie_auth (TokenValue) – The new session cookie.

Return type:

None

classmethod with_token(cookie_auth)

Creates a session instace, with the session cookie set.

Parameters:

cookie_auth (TokenValue) – The session cookie that can be found after a successful login. Pykemo cannot find this on its own, the user must provide it.

Returns:

An instance of the session.

Return type:

KemoSession