Skip to main content

Python typings of payloads that Discord sends

Project description

discord-typings

Python typings of all payloads that Discord sends as TypedDicts.

Quickstart

The library requires no setup except for installation. The easiest way to install it is through PyPI where it is similarly named discord-typings:

pip install discord-typings

Now, start importing the relevant typings directly from the library:

from discord_typings import UserData


def print_author(user: UserData) -> None:
    print(f"Created by {user['username']}#{user['discriminator']}")


print_author({
    'id': '344404945359077377',
    'username': 'Bluenix',
    'discriminator': '7543',
    'avatar': None
})

It is also possible to import the library inside of a TYPE_CHECKING-clause:

from typing import Any, TYPE_CHECKING

if TYPE_CHECKING:
    from discord_typings import Snowflake


class Data:
    id: 'Snowflake'
    value: Any

Note It is not recommended to import the library this way, as it does not allow you to introspect the annotations in other code. It is merely pointed out for completeness.

Naming and Usage

There is no documentation or API reference as this provides no value on top of the Discord developer documentation the types are based on. Typings are named after the object they represent, and there are little to no exceptions to this rule.

Typings use suffixes to differentiate between potential wrapping objects in user code - such as importing UserData to parse into a custom User class. These are Data, Event, and Command. Event refers to a gateway event received over the gateway while Command refers to a gateway command sent over the gateway. Data is used for any general objects like UserData.

Exceptions

To differentiate between the data for complete application commands, and the data Discord expects to receive to create an application command, there is a special-cased ApplicationCommandPayload.

Codestyle and Contributing

Discord-typings is a relatively simple library with little code, but unfortunately needs to be constantly maintained with Discord's API. The purpose of this library is for this to be a community effort; any help with maintenance is greatly appreciated.

Structure

The library follows the API docs both in terms of naming, structure, and order inside of individual files. This should hopefully make it easier to find the code to change when you have the documentation entry at hand.

All internal imports should be done by importing the entire module, then accessing the typing as an attribute. If from ... import ..., or specific things are imported, that is likely to create complicated circular imports. Inside of annotations, wrap the attribute access (discord_typings.X) in quotes to make it a string and defer its evaluation.

All typings which directly represent a Discord payload (excluding typings created for the purpose of a Union) should be added to the file's __all__, then be added to the module's __init__ and its __all__.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord_typings-0.6.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

discord_typings-0.6.0-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file discord_typings-0.6.0.tar.gz.

File metadata

  • Download URL: discord_typings-0.6.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for discord_typings-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d65ac8c83c690135b5e12c5b43382b4a0ffc459c0e2a696536d0db542e051858
MD5 367117f0b15417ce796f704d399a0560
BLAKE2b-256 5bc0cc874a754fe3f2d36b9887c30f6b62210a1c3bd33e391ce017b02a71badc

See more details on using hashes here.

Provenance

File details

Details for the file discord_typings-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for discord_typings-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 506cd96524571a311db541a0f5a802c35a58aba9fe46e1e51c5bcf1c5bef96ec
MD5 5fb941f76cbf2ca35a385654142fbf4b
BLAKE2b-256 5600339a19c1102cd2b2fd91f301fa4e83d611646cd7428f514ae66e4e0338b5

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page