Skip to main content

dhooks-lite

Another simple class wrapper for interacting with Discord webhooks.

release python CI/CD Pipeline codecov Documentation Status license pre-commit Code style: black chat

Contents

Overview

dhooks-lite is a library with a set of classes for interacting with Discord webhooks written in Python 3.

This library aims to differentiate itself from similar libraries with the following properties:

  • is fully tested
  • simple to use (only one way of doing things, same name of attributes and objects as in the official Discord documentation)
  • has logging
  • requests are automatically retried and have sensible timeouts
  • works with older Python versions

Functionality

This library provides following functionality:

  • Posting messages in Discord channels via webhooks (synchronous calls only)
  • Attaching Embeds to messages
  • Retrieve send reports and from Discord
  • Retrieve HTTP status and headers from Discord, e.g. for implementing rate limit handling

Examples

Here are some examples on how to use dhooks-lite in your Python scripts.

Note that you also find the source code of all examples in the /examples folder of this repo.

Hello World

Minimal example for posting a message.

from dhooks_lite import Webhook

hook = Webhook(DISCORD_WEBHOOK_URL)
hook.execute('Hello, World!')

example1

Posting with custom avatar

In this example we are setting username and avatar.

from dhooks_lite import Webhook

hook = Webhook(
    DISCORD_WEBHOOK_URL,
    username='Bruce Wayne',
    avatar_url='https://i.imgur.com/thK8erv.png'
)
hook.execute('I am Batman!')

example2

Complete example with embeds

Finally, here is an example for posting a message with two embeds and using all available features (shortened):

import datetime
from dhooks_lite import Webhook, Embed, Footer, Image, Thumbnail, Author, Field

hook = Webhook(DISCORD_WEBHOOK_URL)
e1 = Embed(
    description='Only a few years ago, scientists stumbled upon an electrical current of cosmic proportions.(...)',
    title='Universe\'s highest electric current found',
    url='https://www.newscientist.com/article/mg21028174-900-universes-highest-electric-current-found/',
    timestamp=datetime.datetime.now(),
    color=0x5CDBF0,
    footer=Footer(
        'Science Department',
        'https://i.imgur.com/Bgsv04h.png'
    ),
    image=Image('https://i.imgur.com/eis1Y0P.jpg'),
    thumbnail=Thumbnail('https://i.imgur.com/2A4k28x.jpg'),
    author=Author(
        'John Scientist',
        url='https://en.wikipedia.org/wiki/Albert_Einstein',
        icon_url='https://i.imgur.com/1JoHDw1.png'
    ),
    fields=[
        Field('1st Measurement', 'Failed'),
        Field('2nd Measurement', 'Succeeded')
    ]
)
e2 = Embed(description="TOP SECRET - Do not distribute!")

hook.execute(
    'Checkout this new report from the science department:',
    username='Bruce Wayne',
    avatar_url='https://i.imgur.com/thK8erv.png',
    embeds=[e1, e2],
    wait_for_response=True
)

example2

Installation

You can install this library directly from PyPI:

pip install dhooks-lite

Documentation

For a full documentation of all classes please see the official docs.

Contribution

We welcome any contribution!

If you found a bug or have a feature request please raise an issue.

If you want to help further improve this library please feel free to issue a merge request. Please adhere to the following requirements in your change:

  • Code should be compliant with PEP8
  • Full overage by unit tests
  • All classes should be immutable
  • All classes and their public methods must have docstring documentation
  • All changes must be documented in the Change Log

Download files

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

Source Distribution

dhooks_lite-2.0.1.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dhooks_lite-2.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file dhooks_lite-2.0.1.tar.gz.

File metadata

  • Download URL: dhooks_lite-2.0.1.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.34.2

File hashes

Hashes for dhooks_lite-2.0.1.tar.gz
Algorithm Hash digest
SHA256 5b468d39e2d76f70263f14abb8799fba397d1df4dba5a455862360f52cc88865
MD5 26c7d633a0478522ce62694ed1a62099
BLAKE2b-256 e914f780fc956d4fa35b819b567ca1234b20c3d081281db0676dd25f2e3d18e8

See more details on using hashes here.

File details

Details for the file dhooks_lite-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: dhooks_lite-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.34.2

File hashes

Hashes for dhooks_lite-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6be86891d0c7c8f88c631a4206c921252110e858a1c294758072dcbf56a5f94e
MD5 c9c064e995878eefb0308c7656982944
BLAKE2b-256 9a214b8194cf2ddcce93941769cfe2927011caf3355accfea0be82f1453e6095

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 files

2.0.0

2 files

1.1.0

2 files

1.0.0

2 files

0.6.1

1 file

0.6.0

1 file

0.5.1

1 file

0.5.0

1 file

0.4.1

1 file

0.4.0

1 file

0.3.2

1 file

0.3.1

1 file

0.3.0

1 file

0.2.0

2 files

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