Library for sending pulses to a process monitoring server
Project description
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:
pip install pyheartbeat
Note: APScheduler is already included as a dependency, so business-hours scheduling works out of the box.
Example
- Legacy Mode (Always On) Use this mode when you want a heartbeat thread that simply runs at a fixed interval, 24/7.
======================================================================================================
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)
======================================================================================================
- Business-Hours Mode (New) Schedule heartbeats to start and stop automatically each day within a configurable business-hours window.
======================================================================================================
from pyheartbeat import (
setUrl, setBusinessHours, businessHeartbeat,
killHeartbeat, shutdownScheduler
)
# 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
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyheartbeat-0.0.8.tar.gz.
File metadata
- Download URL: pyheartbeat-0.0.8.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ed38c3e932ec929694dbc662ae88a9e0dbe642aa2ac8f7a9cbbe4aea3eb230d
|
|
| MD5 |
a5b3df2dc59a133cab6dc2aa28b84711
|
|
| BLAKE2b-256 |
521e36d9a20b8c985b2afad9e0b08188c3016ff1843ae767e97a64f0ff39dacb
|
File details
Details for the file pyheartbeat-0.0.8-py3-none-any.whl.
File metadata
- Download URL: pyheartbeat-0.0.8-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ccfc1dcccf0bb8421729b48370e6cb61c95765122030d213fee07f99cf0a307
|
|
| MD5 |
3d68a24389bf1e60e3bdb8f1619cdfc3
|
|
| BLAKE2b-256 |
2ed2c7bebf8c0519d7b1d0ee2429ad13736752168721991b93531971da37f980
|