Skip to main content

A simple Discord webhook wrapper for Python

Project description

Cordhook

Cordhook is a clean, lightweight Python wrapper around the Discord Webhook API.
It provides a developer-friendly way to send rich messages, embeds, and file attachments with built-in validation, retry logic, and error handling.


PyPi Project Page

Features

  • Simple interface for sending messages and embeds
  • Full support for Discord embed customization
  • File attachment support
  • Auto retry logic with exponential backoff
  • Custom exception handling for common issues
  • Utility functions for formatting, truncating, and validating payloads

Quick Start

pip install cordhook
from cordhook import Webhook

wh = Webhook("https://discord.com/api/webhooks/...")
wh.set_content("Hello, world!")\\
  .add_embed("Embed Title", "This is a test")\\
  .send()

Embed Creation

You can use the create_embed() helper for more control:

from cordhook import create_embed

embed = create_embed(
    title="Sample Embed",
    description="Generated with Cordhook",
    footer_text="Sent via Python",
    timestamp=True
)

Utilities

  • retry_request(func, retries=3) – retries any function with optional backoff
  • validate_url(url) – checks if a webhook URL is valid
  • json_pretty_print(obj) – nicely formats any JSON or dict
  • truncate_text(text, limit=1024) – prevents hitting Discord text limits

Exceptions

Cordhook raises specific exceptions so you can catch and handle errors cleanly:

  • WebhookException
  • InvalidPayloadException
  • RateLimitException
  • FileAttachmentException

Example with File

Webhook("url")  
    .set_content("With a file!")  
    .attach_file("cat.png")  
    .send()

License

MIT License — free to use, modify, and distribute


Feedback or Contributions

Open an issue or PR to suggest improvements or fix bugs.

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

cordhook-1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

cordhook-1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file cordhook-1.0.tar.gz.

File metadata

  • Download URL: cordhook-1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cordhook-1.0.tar.gz
Algorithm Hash digest
SHA256 ff9e9c1e4e9432bba7a75b7a6b8c2bfd98b33da89bd07bb071fca490c4ad3b74
MD5 94f2812f85c3c32651fba6419bf76f43
BLAKE2b-256 0f7c85bdeef87b33b1b115716a30a780b4afc04b2ba3b568dafdf15207ed3b5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cordhook-1.0.tar.gz:

Publisher: python-publish.yml on mochathehuman/cordhook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cordhook-1.0-py3-none-any.whl.

File metadata

  • Download URL: cordhook-1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cordhook-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65c8b90e5687de3fdc7a14cfe5fb4daa20123ad70cc20e3bb342ccfdfc48c344
MD5 fdffc2ff396051fa648836f081486624
BLAKE2b-256 825611c22daab5c01eedf0f0ab011e9d6aae468a40d03b658f5e3e2a2c6555b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for cordhook-1.0-py3-none-any.whl:

Publisher: python-publish.yml on mochathehuman/cordhook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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