Skip to main content

Wumpy-rest

Richly and accurately typed wrapper around the Discord REST API.

Usage

The best way to use wumpy-rest is to import APIClient:

import anyio
from wumpy.rest import APIClient


TOKEN = 'ABC123.XYZ789'


async def main():
    async with APIClient(TOKEN) as api:
        print(await api.fetch_my_user())


anyio.run(main)

APIClient is a class that implements all routes of the Discord API. This is made up of multiple route classes. You can create your own class with the routes you use:

from wumpy.rest import (
    ApplicationCommandRequester, InteractionRequester,
    HTTPXRequester
)


class MyAPIClient(ApplicationCommandRequester, InteractionRequester, HTTPXRequester):

    __slots__ = ()  # Save some memory for this class

Files

Some endpoints support uploading files, for these a file-like object is expected that's been opened in binary-mode (for example 'rb').

For the message/interaction endpoints, remember to include a matching attachment object with 'id' set to the index of the file.

Ratelimiter

You can pass a custom ratelimiter to the requester if you want to customize that behaviour. For more, read the documentation. Here's an example of a ratelimiter that does no ratelimiting and does not handle any kind of 429-responses.

from contextlib import asynccontextmanager
from typing import (
    Any, AsyncContextManager, AsyncGenerator, Awaitable, Callable, Coroutine,
    Mapping
)

import anyio
from wumpy.rest import APIClient


class NoOpRatelimiter:
    """Ratelimiter implementation that does nothing; a no-op implementation."""

    async def __aenter__(self):
        return self

    async def __aexit__(
        self,
        exc_type: Optional[Type[BaseException]],
        exc_val: Optional[BaseException],
        exc_tb: Optional[TracebackType]
    ) -> object:
        pass

    @asynccontextmanager
    async def __call__(self, route: Route) -> AsyncGenerator[
        Callable[[Mapping[str, str]], Coroutine[Any, Any, object]],
        None
    ]:
        # The return type may look a little weird, but this is how
        # @asynccontextmanager works. You pass it a function that returns an
        # async generator (which yields what the asynchronous context manager
        # then returns).
        yield self.update

    async def update(self, headers: Mapping[str, str]) -> object:
        pass


async def main():
    async with APIClient(TOKEN, ratelimiter=NoOpRatelimiter()) as api:
        print(await api.fetch_my_user())


anyio.run(main)

Metadata

Release files for wumpy-rest 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wumpy-rest 0.3.0
File Size Uploaded Provenance Actions
wumpy-rest-0.3.0.tar.gz 41.5 kB Without provenance Details for wumpy-rest-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wumpy-rest 0.3.0
File Interpreter ABI Platform Actions
wumpy_rest-0.3.0-py3-none-any.whl Python 3 none any Details for wumpy_rest-0.3.0-py3-none-any.whl

Total release size: 90.7 kB

Release files / wumpy-rest-0.3.0.tar.gz

Download URL wumpy-rest-0.3.0.tar.gz
Size 41.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2cbc1ea04321b76a2c9fa7bd369ad4624fd646f0769c0b3ef22478a8b095b7b5
BLAKE2b-256 checksum
How to use checksums
1c4cd35d9d4a56d49f54c6d3e205222c76b5e6b13a777afebe93832ae9f50367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release files / wumpy_rest-0.3.0-py3-none-any.whl

Download URL wumpy_rest-0.3.0-py3-none-any.whl
Size 49.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6bcbfe08064475bdc2b80ad2ee8ae91d8a383a7cc582363d12aefed4b9bea24
BLAKE2b-256 checksum
How to use checksums
7cdbaf88c32aede19c3958129c0b4052e62cea1955ffd98c253f872dd260e112
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Security for wumpy-rest 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page