discordhealthcheck


Namediscordhealthcheck JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/psidex/discordhealthcheck
SummaryA small Python 3 library and command line app to automate Docker health checks for discord.py bots.
upload_time2022-12-14 01:25:56
maintainer
docs_urlNone
author
requires_python
license
keywords discord discord.py docker healthcheck health check bot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Discord Health Check

[![CI](https://github.com/psidex/discordhealthcheck/workflows/CI/badge.svg)](https://github.com/psidex/discordhealthcheck/actions)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/discordhealthcheck?colorA=35383d)](https://pypi.org/project/discordhealthcheck/)
[![PyPI](https://img.shields.io/pypi/v/discordhealthcheck?colorA=35383d)](https://pypi.org/project/discordhealthcheck/)
[![Black formatter](https://img.shields.io/badge/Code%20Style-Black-000000.svg?colorA=35383d)](https://github.com/psf/black)

A small Python 3 library and command line app to automate Docker health checks for [discord.py](https://discordpy.readthedocs.io/en/latest/) 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`:

```python
def start(
    client: discord.client,
    port: int = 40404,
    bot_max_latency: float = 0.5
) -> Awaitable[asyncio.base_events.Server]
```

`start` calls [`asyncio.start_server`](https://docs.python.org/3/library/asyncio-stream.html#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`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.setup_hook) method:

```python
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:

```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"]
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/psidex/discordhealthcheck",
    "name": "discordhealthcheck",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "discord discord.py docker healthcheck health check bot",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/95/53/6bfb908bcde047e0b010f850e3b0dddd63965de61118824b0bf195634bd4/discordhealthcheck-0.1.1.tar.gz",
    "platform": null,
    "description": "# Discord Health Check\r\n\r\n[![CI](https://github.com/psidex/discordhealthcheck/workflows/CI/badge.svg)](https://github.com/psidex/discordhealthcheck/actions)\r\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/discordhealthcheck?colorA=35383d)](https://pypi.org/project/discordhealthcheck/)\r\n[![PyPI](https://img.shields.io/pypi/v/discordhealthcheck?colorA=35383d)](https://pypi.org/project/discordhealthcheck/)\r\n[![Black formatter](https://img.shields.io/badge/Code%20Style-Black-000000.svg?colorA=35383d)](https://github.com/psf/black)\r\n\r\nA small Python 3 library and command line app to automate Docker health checks for [discord.py](https://discordpy.readthedocs.io/en/latest/) bots.\r\n\r\n## Installation\r\n\r\n`pip install discordhealthcheck`\r\n\r\nThis 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`.\r\n\r\n## How It Works & Usage Examples\r\n\r\n### Python Library (Server)\r\n\r\nThe library has 1 function, `start`.\r\n\r\n`start` takes a `discord.Client` object as well as optional parameters, and returns an awaitable that produces a `asyncio.base_events.Server`:\r\n\r\n```python\r\ndef start(\r\n    client: discord.client,\r\n    port: int = 40404,\r\n    bot_max_latency: float = 0.5\r\n) -> Awaitable[asyncio.base_events.Server]\r\n```\r\n\r\n`start` calls [`asyncio.start_server`](https://docs.python.org/3/library/asyncio-stream.html#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.\r\n\r\nThe returned `Server` object can be used to stop the server (e.g. `healthcheck_server.close()`)\r\n\r\nThe 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.\r\n\r\nCall `start` once your event loop is running, generally a good place to call from is inside your [`setup_hook`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.setup_hook) method:\r\n\r\n```python\r\nimport discord\r\nimport discordhealthcheck\r\n\r\nclass CustomClient(discord.Client):\r\n    def __init__(self, *args, **kwargs):\r\n        super().__init__(*args, **kwargs)\r\n\r\n    async def setup_hook(self):\r\n        self.healthcheck_server = await discordhealthcheck.start(self)\r\n        # Later you can close or check on self.healthcheck_server\r\n```\r\n\r\n### CLI App (Client)\r\n\r\nThe CLI app is a simple client that connects to the server and determines its exit code from what the server sends; `0`\r\nfor healthy, `1` for unhealthy.\r\n\r\nHere's an example of using in a Dockerfile:\r\n\r\n```dockerfile\r\nFROM python:3.11-slim-buster\r\n\r\n# Copy files, install requirements, setup bot, etc.\r\n\r\nRUN pip install discordhealthcheck\r\n\r\n# The `|| exit 1` isn't required but it's good practice anyway.\r\nHEALTHCHECK CMD discordhealthcheck || exit 1\r\n\r\nCMD [\"python\", \"/path/to/bot.py\"]\r\n```\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A small Python 3 library and command line app to automate Docker health checks for discord.py bots.",
    "version": "0.1.1",
    "split_keywords": [
        "discord",
        "discord.py",
        "docker",
        "healthcheck",
        "health",
        "check",
        "bot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "8fbb13ab9a468076ef7a00d2d4dcb2b2",
                "sha256": "94f4b380dd7942a28dc99bb559ffe4b48285b4fd5cb8f3a553fe05de7c127c54"
            },
            "downloads": -1,
            "filename": "discordhealthcheck-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8fbb13ab9a468076ef7a00d2d4dcb2b2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5415,
            "upload_time": "2022-12-14T01:25:53",
            "upload_time_iso_8601": "2022-12-14T01:25:53.871947Z",
            "url": "https://files.pythonhosted.org/packages/f7/7e/0f067c2af8586ebd4d280bb1d68b387afd4062dce2e8a8fa8abbf10d4499/discordhealthcheck-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "e783d42929a1b4a60af5cc365ca1c166",
                "sha256": "6772cfb9ce4437773b5ce1bdfb018c2bd380ae2ead49d7f07ed789a92f79b7fc"
            },
            "downloads": -1,
            "filename": "discordhealthcheck-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e783d42929a1b4a60af5cc365ca1c166",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4841,
            "upload_time": "2022-12-14T01:25:56",
            "upload_time_iso_8601": "2022-12-14T01:25:56.282359Z",
            "url": "https://files.pythonhosted.org/packages/95/53/6bfb908bcde047e0b010f850e3b0dddd63965de61118824b0bf195634bd4/discordhealthcheck-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-14 01:25:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "psidex",
    "github_project": "discordhealthcheck",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "discordhealthcheck"
}
        
Elapsed time: 0.01797s