Discord Health Check
A small Python 3 library and command line app to automate Docker health checks for discord.py bots.
Installation
pip install discordhealthcheck
This will install both the Python library and the command line app, the python library is importable using import discordhealthcheck and the CLI app by using the command discordhealthcheck.
How It Works & Usage Examples
Python Library (Server)
The library has 1 function, start.
start takes a discord.Client object as well as optional parameters, and returns an awaitable that produces a asyncio.base_events.Server:
def start(
client: discord.client,
port: int = 40404,
bot_max_latency: float = 0.5
) -> Awaitable[asyncio.base_events.Server]
start calls asyncio.start_server, creating an asyncio TCP socket server which listens for connections. Once a client connects, it tests the discord client for various things that indicate its health (latency, login status, etc.), and the result of this health check is then sent to the healthcheck client.
The returned Server object can be used to stop the server (e.g. healthcheck_server.close())
The default port for the socket server is 40404, if you change it you will need to use the --port flag on the client as well.
Call start once your event loop is running, generally a good place to call from is inside your setup_hook method:
import discord
import discordhealthcheck
class CustomClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
async def setup_hook(self):
self.healthcheck_server = await discordhealthcheck.start(self)
# Later you can close or check on self.healthcheck_server
CLI App (Client)
The CLI app is a simple client that connects to the server and determines its exit code from what the server sends; 0
for healthy, 1 for unhealthy.
Here's an example of using in a Dockerfile:
FROM python:3.11-slim-buster
# Copy files, install requirements, setup bot, etc.
RUN pip install discordhealthcheck
# The `|| exit 1` isn't required but it's good practice anyway.
HEALTHCHECK CMD discordhealthcheck || exit 1
CMD ["python", "/path/to/bot.py"]
Metadata
Release files for discordhealthcheck 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| discordhealthcheck-0.1.1.tar.gz | 4.8 kB | Without provenance | Details for discordhealthcheck-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| discordhealthcheck-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for discordhealthcheck-0.1.1-py3-none-any.whl |
Total release size: 10.3 kB
Release files / discordhealthcheck-0.1.1.tar.gz
| Download URL | discordhealthcheck-0.1.1.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6772cfb9ce4437773b5ce1bdfb018c2bd380ae2ead49d7f07ed789a92f79b7fc
|
|
BLAKE2b-256 checksum How to use checksums |
95536bfb908bcde047e0b010f850e3b0dddd63965de61118824b0bf195634bd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Release files / discordhealthcheck-0.1.1-py3-none-any.whl
| Download URL | discordhealthcheck-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94f4b380dd7942a28dc99bb559ffe4b48285b4fd5cb8f3a553fe05de7c127c54
|
|
BLAKE2b-256 checksum How to use checksums |
f77e0f067c2af8586ebd4d280bb1d68b387afd4062dce2e8a8fa8abbf10d4499
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Security for discordhealthcheck 0.1.1
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.