Skip to main content

Discord API wrapper in Python

Project description

Hata

Hata is an async Discord API wrapper written in Python named after Hata no Kokoro.

If naming a Discord API wrapper after a Touhou character is not enough to convince you to try it, it has got some real stuff:

  • Fast and simple asynchronous framework to write concurrent code using async/await syntax, but also great for embedding into a threaded system.
  • Running more clients from the same instance.
  • Shared entity cache between shards and clients.
  • Feature rich API for common use cases.
  • Fast rate limit handling.
  • No member objects associated with guilds. Hata uses guild -> user -> guild relation enabling implementing cross-guild features more easily.
  • Optimized dispatch event parsers depending on intents, client count and on handled events as well.
  • Option to disable user presences or even user caching, although disabling user cache is not recommended.
  • Command and extension loader extension.
  • Audio sending and receiving.
  • Can interacting with the Discord API without gateway connection.
  • Switching between api version with environmental variable.

Usage

The following example answers on ping message.

from hata import Client

Nue = Client('TOKEN')

@Nue.events
async def ready(client):
    print(f'{client:f} logged in.')

@Nue.events
async def message_create(client, message):
    if message.author.is_bot:
        return

    if message.content == 'ping':
        await client.message_create(message.channel, 'pong')

Nue.start()

An improved example using the commands extension to handle common use cases.

from hata import Client
from hata.ext.commands import setup_ext_commands

Saki = Client('TOKEN')
setup_ext_commands(Saki, 's!')

@Saki.events
async def ready(client):
    print(f'{client:f} logged in.')

@Saki.commands
async def ping(client, message):
    return 'pong'

Saki.start()

If you wonder, how to run up more clients, just put the two code snippet into the same file.

Hata leaves the main thread free, client.start() blocks it only till the client logs in (or fails it), although you can still use the start_clients function, what as it says, starts up all the non-running clients parallelly, so go ahead and start python with -i option, then interact with the clients from your interactive console in runtime.

Installing guide

To install the package use:

# Linux/OS X
$ python3 -m pip install hata

# Windows
$ python -m pip install hata

Hata has native pypy support as well if you need some more speed!

Requirements

Optional requirements

Join our server

If you have issues, suggestions, want to contribute, or just want to send cute neko pictures, join our discord server.

Acknowledgement

Shout-Outs for our brave testers, who are helping the most improving the library:

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

hata-1.1.30.tar.gz (730.3 kB view hashes)

Uploaded Source

Built Distribution

hata-1.1.30-py3-none-any.whl (1.2 MB view hashes)

Uploaded Python 3

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