# Nextcord Health Check
A small Python 3 library and command line app to automate Docker health checks for [nextcord](https://docs.nextcord.dev/en/stable/index.html) bots.
## Installation
`pip install nextcordhealthcheck`
This will install both the Python library and the command line app, the python library is importable using `import nextcordhealthcheck` and the CLI app by using the command `nextcordhealthcheck`.
## How It Works & Usage Examples
### Python Library (Server)
The library has 1 function, `start`.
`start` takes a `nextcord.Client` object as well as optional parameters, and returns an awaitable that produces a `asyncio.base_events.Server`:
```python
def start(
client: nextcord.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 nextcord 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.
```python
import nextcord
import nextcordhealthcheck
class CustomClient(nextcord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.healthcheck_server = None
async def on_ready(self):
if self.healthcheck_server is None:
self.healthcheck_server = await nextcordhealthcheck.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 nextcordhealthcheck
# The `|| exit 1` isn't required but it's good practice anyway.
HEALTHCHECK CMD nextcordhealthcheck || exit 1
CMD ["python", "/path/to/bot.py"]
```
Raw data
{
"_id": null,
"home_page": "https://github.com/I-dan-mi-I/NextcordHealthCheck",
"name": "nextcordhealthcheck",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "nextcord docker healthcheck health check bot",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/cb/93/11be4c004f56a2128d040f4be448181b6ea8236a7283eaaa4bec0ada6d8f/nextcordhealthcheck-0.1.3.tar.gz",
"platform": null,
"description": "# Nextcord Health Check\r\n\r\nA small Python 3 library and command line app to automate Docker health checks for [nextcord](https://docs.nextcord.dev/en/stable/index.html) bots.\r\n\r\n## Installation\r\n\r\n`pip install nextcordhealthcheck`\r\n\r\nThis will install both the Python library and the command line app, the python library is importable using `import nextcordhealthcheck` and the CLI app by using the command `nextcordhealthcheck`.\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 `nextcord.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: nextcord.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 nextcord 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\n```python\r\nimport nextcord\r\nimport nextcordhealthcheck\r\n\r\nclass CustomClient(nextcord.Client):\r\n def __init__(self, *args, **kwargs):\r\n super().__init__(*args, **kwargs)\r\n self.healthcheck_server = None\r\n\r\n async def on_ready(self):\r\n if self.healthcheck_server is None:\r\n self.healthcheck_server = await nextcordhealthcheck.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 nextcordhealthcheck\r\n\r\n# The `|| exit 1` isn't required but it's good practice anyway.\r\nHEALTHCHECK CMD nextcordhealthcheck || 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 nextcord bots.",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/I-dan-mi-I/NextcordHealthCheck"
},
"split_keywords": [
"nextcord",
"docker",
"healthcheck",
"health",
"check",
"bot"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5e8febea95900cde3c863d706f30aa70063e5e07619f70b0e09ef8b81b6fecc5",
"md5": "20c0649fa467913d653cae5ca1e07896",
"sha256": "8cfb3f1215bbcf1beca5d7ad5b5f0690ad73505047f56a3e2a837f4deac51522"
},
"downloads": -1,
"filename": "nextcordhealthcheck-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "20c0649fa467913d653cae5ca1e07896",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5231,
"upload_time": "2023-12-30T14:34:46",
"upload_time_iso_8601": "2023-12-30T14:34:46.044438Z",
"url": "https://files.pythonhosted.org/packages/5e/8f/ebea95900cde3c863d706f30aa70063e5e07619f70b0e09ef8b81b6fecc5/nextcordhealthcheck-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cb9311be4c004f56a2128d040f4be448181b6ea8236a7283eaaa4bec0ada6d8f",
"md5": "df97db68a74f997f7d1c3b027f4587f8",
"sha256": "0e507a536d77afa870e240e5b9ff412241fddcef56f3be40254321ed3d2e6130"
},
"downloads": -1,
"filename": "nextcordhealthcheck-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "df97db68a74f997f7d1c3b027f4587f8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4624,
"upload_time": "2023-12-30T14:34:47",
"upload_time_iso_8601": "2023-12-30T14:34:47.486650Z",
"url": "https://files.pythonhosted.org/packages/cb/93/11be4c004f56a2128d040f4be448181b6ea8236a7283eaaa4bec0ada6d8f/nextcordhealthcheck-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-30 14:34:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "I-dan-mi-I",
"github_project": "NextcordHealthCheck",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "nextcordhealthcheck"
}