# Python Heartbeat Library
A lightweight utility for sending regular “pulses” (heartbeats) to an HTTP endpoint. These pulses confirm that your main script is running. If the main script stops, the heartbeat halts too—making it easy to detect failures. In addition to the original always-on mode, you can now schedule heartbeats to run only during configurable business hours via APScheduler.
# Installation
You can install the Python Heartbeat Library using pip:
```python
pip install pyheartbeat
```
Note: APScheduler is already included as a dependency, so business-hours scheduling works out of the box.
# Example
1. Legacy Mode (Always On)
Use this mode when you want a heartbeat thread that simply runs at a fixed interval, 24/7.
```python
======================================================================================================
from pyheartbeat import setUrl, heartbeat, killHeartbeat
# 1. Point to your monitoring endpoint
setUrl("https://your-endpoint/heartbeat")
# 2. Start the heartbeat thread
heartbeat(
interval=600, # seconds between pulses
name="scrapper-x", # logical process name
description="process monitor", # human-readable description
additional_info="production", # any extra metadata
show_response=True, # print HTTP status codes
show_logs=True, # print thread start/stop logs
api_token="YOUR_API_TOKEN" # optional authentication token
)
# ... your main application logic ...
# 3. Stop the heartbeat when you’re done
killHeartbeat(disable_schedule = False)
======================================================================================================
```
2. Business-Hours Mode (New)
Schedule heartbeats to start and stop automatically each day within a configurable business-hours window.
```python
======================================================================================================
from pyheartbeat import (
setUrl, setBusinessHours, businessHeartbeat,
killHeartbeat
)
# 1. Configure the endpoint
setUrl("https://your-endpoint/heartbeat")
# 2. Set business hours window (09:00–18:00 Mon–Fri)
setBusinessHours(
start_hour=9,
end_hour=18,
days='mon-fri',
tz='America/Sao_Paulo'
)
# 3. Schedule the heartbeat to run only during business hours
businessHeartbeat(
interval=600, # send a pulse every 600 seconds
name="scrapper-x", # logical name of the process
description="process monitor", # human-readable description
additional_info="production", # any extra metadata
show_response=True, # print HTTP status codes
show_logs=True, # print thread start/stop logs
show_scheduler_logs=False, # print scheduler logs
api_token="YOUR_API_TOKEN" # optional authentication token
)
# ... your main script runs here ...
# 4a. Stop only the heartbeat thread (it will automatically restart tomorrow)
killHeartbeat()
# 4b. Stop the heartbeat thread and disable automatic restart tomorrow
killHeartbeat(disable_schedule=True)
======================================================================================================
```
# License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "pyheartbeat",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "pyheartbeat, heartbeat_library, heartbeat, heartbeat-library, heartbeat-api, heartbeat-wrapper, heartbeat-python, heartbeat-python-wrapper, heartbeat-python-api, heartbeat-python-wrapper-api, heartbeat-python-api-wrapper, multithreading, threading, requests, python-requests, python-threading, python-multithreading, python-heartbeat, python-heartbeat-api, python-heartbeat-wrapper, python-heartbeat-python, python-heartbeat-python-wrapper, python-heartbeat-python-api, python-heartbeat-python-wrapper-api, python-heartbeat-python-api-wrapper",
"author": "Pedro Ferreira Braz",
"author_email": "pbraz.pedrof@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ce/c2/2394004c5899dce56a66546a3646bda84dd950d779e35ff0137241d52a22/pyheartbeat-0.0.9.tar.gz",
"platform": null,
"description": "# Python Heartbeat Library\r\n\r\nA lightweight utility for sending regular \u201cpulses\u201d (heartbeats) to an HTTP endpoint. These pulses confirm that your main script is running. If the main script stops, the heartbeat halts too\u2014making it easy to detect failures. In addition to the original always-on mode, you can now schedule heartbeats to run only during configurable business hours via APScheduler.\r\n\r\n# Installation\r\n\r\nYou can install the Python Heartbeat Library using pip:\r\n\r\n```python\r\npip install pyheartbeat\r\n```\r\n\r\nNote: APScheduler is already included as a dependency, so business-hours scheduling works out of the box.\r\n\r\n# Example\r\n\r\n1. Legacy Mode (Always On)\r\nUse this mode when you want a heartbeat thread that simply runs at a fixed interval, 24/7.\r\n```python\r\n======================================================================================================\r\nfrom pyheartbeat import setUrl, heartbeat, killHeartbeat\r\n\r\n# 1. Point to your monitoring endpoint\r\nsetUrl(\"https://your-endpoint/heartbeat\")\r\n\r\n# 2. Start the heartbeat thread\r\nheartbeat(\r\n interval=600, # seconds between pulses\r\n name=\"scrapper-x\", # logical process name\r\n description=\"process monitor\", # human-readable description\r\n additional_info=\"production\", # any extra metadata\r\n show_response=True, # print HTTP status codes\r\n show_logs=True, # print thread start/stop logs\r\n api_token=\"YOUR_API_TOKEN\" # optional authentication token\r\n)\r\n\r\n# ... your main application logic ...\r\n\r\n# 3. Stop the heartbeat when you\u2019re done\r\nkillHeartbeat(disable_schedule = False)\r\n======================================================================================================\r\n```\r\n\r\n2. Business-Hours Mode (New)\r\nSchedule heartbeats to start and stop automatically each day within a configurable business-hours window.\r\n```python\r\n======================================================================================================\r\nfrom pyheartbeat import (\r\n setUrl, setBusinessHours, businessHeartbeat,\r\n killHeartbeat\r\n)\r\n\r\n# 1. Configure the endpoint\r\nsetUrl(\"https://your-endpoint/heartbeat\")\r\n\r\n# 2. Set business hours window (09:00\u201318:00 Mon\u2013Fri)\r\nsetBusinessHours(\r\n start_hour=9,\r\n end_hour=18,\r\n days='mon-fri',\r\n tz='America/Sao_Paulo'\r\n)\r\n\r\n# 3. Schedule the heartbeat to run only during business hours\r\nbusinessHeartbeat(\r\n interval=600, # send a pulse every 600 seconds\r\n name=\"scrapper-x\", # logical name of the process\r\n description=\"process monitor\", # human-readable description\r\n additional_info=\"production\", # any extra metadata\r\n show_response=True, # print HTTP status codes\r\n show_logs=True, # print thread start/stop logs\r\n show_scheduler_logs=False, # print scheduler logs\r\n api_token=\"YOUR_API_TOKEN\" # optional authentication token\r\n)\r\n\r\n# ... your main script runs here ...\r\n\r\n# 4a. Stop only the heartbeat thread (it will automatically restart tomorrow)\r\nkillHeartbeat()\r\n\r\n# 4b. Stop the heartbeat thread and disable automatic restart tomorrow\r\nkillHeartbeat(disable_schedule=True)\r\n======================================================================================================\r\n```\r\n\r\n# License\r\n\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Library for sending pulses to a process monitoring server",
"version": "0.0.9",
"project_urls": null,
"split_keywords": [
"pyheartbeat",
" heartbeat_library",
" heartbeat",
" heartbeat-library",
" heartbeat-api",
" heartbeat-wrapper",
" heartbeat-python",
" heartbeat-python-wrapper",
" heartbeat-python-api",
" heartbeat-python-wrapper-api",
" heartbeat-python-api-wrapper",
" multithreading",
" threading",
" requests",
" python-requests",
" python-threading",
" python-multithreading",
" python-heartbeat",
" python-heartbeat-api",
" python-heartbeat-wrapper",
" python-heartbeat-python",
" python-heartbeat-python-wrapper",
" python-heartbeat-python-api",
" python-heartbeat-python-wrapper-api",
" python-heartbeat-python-api-wrapper"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ae029a7410c28eec9702593e07726f611c5d02350f7da750383da7d30e202ed0",
"md5": "a9ee0a01710af15dcef51e1ca0842f28",
"sha256": "a6cf067179826fe9b50959f3e590b4c84d346d0d3c128c90e42d08be1633b00b"
},
"downloads": -1,
"filename": "pyheartbeat-0.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a9ee0a01710af15dcef51e1ca0842f28",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6322,
"upload_time": "2025-07-22T13:46:59",
"upload_time_iso_8601": "2025-07-22T13:46:59.562498Z",
"url": "https://files.pythonhosted.org/packages/ae/02/9a7410c28eec9702593e07726f611c5d02350f7da750383da7d30e202ed0/pyheartbeat-0.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "cec22394004c5899dce56a66546a3646bda84dd950d779e35ff0137241d52a22",
"md5": "0be55e6616f8c674ae7836224573921a",
"sha256": "1a2fdc466e43c9082d2d0c22851babbf051275620c1354bb2619b187ec667d87"
},
"downloads": -1,
"filename": "pyheartbeat-0.0.9.tar.gz",
"has_sig": false,
"md5_digest": "0be55e6616f8c674ae7836224573921a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5970,
"upload_time": "2025-07-22T13:47:01",
"upload_time_iso_8601": "2025-07-22T13:47:01.514032Z",
"url": "https://files.pythonhosted.org/packages/ce/c2/2394004c5899dce56a66546a3646bda84dd950d779e35ff0137241d52a22/pyheartbeat-0.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-22 13:47:01",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pyheartbeat"
}