Skip to content

HTTP

Internal API

These classes are for internal use only.

Users should interact with Client and other public API classes instead.


R = request
EP = endpoint
L = Lock
Q = Queue
H = header
B = Bucket
A + B = {A:B}

[R + EP]--|L|-->[Q + EP]--|send R|-->[add/update H + B]
    1. request by endpoint
    2. push request to queue with lock
    3. add/update header by bucket ID with send request

    * Queue by ENDPOINT/REQUEST
    * Bucket by HEADER

http

logger = logging.getLogger('scurrypy.http') module-attribute

RequestItem dataclass

method: str instance-attribute

endpoint: str instance-attribute

data: Serialized instance-attribute

params: JSON | None instance-attribute

files: list[str] | None instance-attribute

assets: Serialized | None instance-attribute

future: asyncio.Future[HTTPResponse] instance-attribute

Bucket dataclass

remaining: int instance-attribute

reset_after: float instance-attribute

reset_on: float instance-attribute

sleep_task: asyncio.Task[Any] | None = None class-attribute instance-attribute

HTTPClientProtocol

Bases: Protocol


              flowchart TD
              scurrypy.core.http.HTTPClientProtocol[HTTPClientProtocol]

              

              click scurrypy.core.http.HTTPClientProtocol href "" "scurrypy.core.http.HTTPClientProtocol"
            

Internal contract for the HTTPClient used by the Client. Meant for testing.

start async

close async

request async

HTTPClient

Bases: HTTPClientProtocol


              flowchart TD
              scurrypy.core.http.HTTPClient[HTTPClient]
              scurrypy.core.http.HTTPClientProtocol[HTTPClientProtocol]

                              scurrypy.core.http.HTTPClientProtocol --> scurrypy.core.http.HTTPClient
                


              click scurrypy.core.http.HTTPClient href "" "scurrypy.core.http.HTTPClient"
              click scurrypy.core.http.HTTPClientProtocol href "" "scurrypy.core.http.HTTPClientProtocol"
            

BASE = 'https://discord.com/api/v10' class-attribute instance-attribute

MAX_RETRIES = 3 class-attribute instance-attribute

session: aiohttp.ClientSession | None = None instance-attribute

queues: dict[str, asyncio.Queue[Any]] = {} instance-attribute

queues_lock = asyncio.Lock() instance-attribute

workers: dict[str, asyncio.Task[Any]] = {} instance-attribute

buckets: dict[str, Bucket] = {} instance-attribute

bucket_lock: dict[str, asyncio.Lock] = {} instance-attribute

buckets_lock = asyncio.Lock() instance-attribute

global_lock: asyncio.Lock = asyncio.Lock() instance-attribute

global_reset: float = 0.0 instance-attribute

start async

Start the HTTP session.

close async

Gracefully stop all workers and close the HTTP session.

request async

Queue a request for the given endpoint.

Parameters:

  • method (str) –

    HTTP method (e.g., POST, GET, DELETE, PATCH, etc.)

  • endpoint (str) –

    Discord endpoint (e.g., /channels/123/messages)

  • data (Serialized, default: None ) –

    relevant data

  • params (JSON | None, default: None ) –

    relevant query params

  • files (list[str] | None, default: None ) –

    relevant files

  • assets (Serialized, default: None ) –

    relevant assets

Raises:

Returns:

  • HTTPResponse

    result or promise of request or None if failed