messenger-logger-callback
messenger-logger-callback (messenger_logger_callback) — a Python library for sending training logs to a remote server with real-time Telegram notifications. Works as a standalone logger for any training loop (PyTorch, Lightning, custom) or as a Hugging Face Trainer Callback.
Pairs with telegram-log-service for real-time Telegram bot alerts, metric monitoring, and stalled run detection.
Installation
pip install messenger-logger-callback
Or equivalently:
pip install messenger_logger_callback
This installs everything including Hugging Face Transformers Trainer support. If you only need the standalone logger and want to avoid the transformers dependency, install with --no-deps and add requests and python-dotenv manually.
Quick Start: Standalone Logger
Use MessengerLogger in any training loop — plain PyTorch, Lightning, or anything else.
from messenger_logger import MessengerLogger
logger = MessengerLogger(
server_url="http://your-server:5000/api/logs",
project_name="resnet_experiment",
run_id="run_v3",
author_username="riko",
)
logger.start()
for epoch in range(num_epochs):
for step, batch in enumerate(dataloader):
loss = train_step(batch)
global_step += 1
logger.log(step=global_step, epoch=epoch, metrics={"loss": loss.item()})
logger.epoch_end(epoch)
logger.finish()
Available Methods
| Method | Description |
|---|---|
start() |
Signal training start. Begins heartbeat. |
log(step, metrics, epoch=None) |
Log training metrics at a given step. |
epoch_end(epoch) |
Signal end of an epoch. |
log_custom(data) |
Send arbitrary custom data. |
finish() |
Signal training end. Stops heartbeat. |
Quick Start: Hugging Face Trainer
Use MessengerLoggerCallback as a drop-in Trainer callback.
from transformers import Trainer, TrainingArguments
from messenger_logger.callback import MessengerLoggerCallback
logger = MessengerLoggerCallback(
server_url="http://your-server:5000/api/logs",
project_name="bert_finetune",
run_id="experiment_v2",
auth_token="your_secret_token",
author_username="riko",
metadata={"model": "bert-large", "dataset": "squad"},
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
callbacks=[logger],
)
trainer.train()
The callback automatically captures on_log, on_train_begin, on_train_end, and on_epoch_end events.
You can also send custom data at any point:
logger.send_custom_log({
"event": "evaluation_complete",
"accuracy": 0.95,
"f1": 0.93,
})
Heartbeat
A background thread sends a lightweight heartbeat signal to the server every 60 seconds by default. This allows the server to detect crashed or stalled runs much faster than waiting for missing log events.
- On by default with a 60-second interval.
- Starts when training begins, stops when training ends.
- If the training process crashes, the heartbeat stops automatically.
To change the interval or disable:
# Custom interval (30 seconds)
logger = MessengerLogger(server_url="...", heartbeat_interval=30)
# Disable heartbeat
logger = MessengerLogger(server_url="...", heartbeat_interval=None)
ClearML Integration
If ClearML is active in your training script, the library automatically detects the current task and includes a link to the ClearML dashboard in every payload sent to the server. No configuration needed — if clearml is installed and a task is running, the link is captured.
Configuration
Settings can be provided via constructor arguments, environment variables, or a .env file. Constructor arguments take highest precedence, then environment variables, then .env file values.
| Constructor Argument | Environment Variable | Description |
|---|---|---|
server_url |
MESSENGER_LOGGER_SERVER_URL |
HTTP endpoint to send logs to. Required. |
project_name |
— | Project identifier. Default: "default_project". |
run_id |
— | Unique run identifier. Auto-generated if omitted. |
auth_token |
MESSENGER_LOGGER_AUTH_TOKEN |
Bearer token for the Authorization header. |
author_username |
MESSENGER_LOGGER_AUTHOR_USERNAME |
Who started the run. Default: "anonymous". |
metadata |
MESSENGER_LOGGER_METADATA |
Static metadata dict. Env var should be a JSON string. |
dotenv_path |
MESSENGER_LOGGER_DOTENV |
Path to a .env file to load config from. |
heartbeat_interval |
— | Seconds between heartbeats. Default: 60. Set to None to disable. |
Error Handling
Network errors (timeouts, connection failures, HTTP errors) are caught and printed as warnings. They never crash your training. Example messages:
Warning: Request to http://... timed out for step 10.
Error: Could not connect to server at http://... for step 20.
Error: HTTP error occurred while sending logs for step 30. Status: 401.
Related Projects
- telegram-log-service — the server that receives logs from this library and forwards them as Telegram bot alerts.
License
MIT
messenger-logger-callback · messenger_logger_callback · pip install messenger-logger-callback · pip install messenger_logger_callback · Telegram training logger · Hugging Face Trainer callback logger · ML training Telegram notifications
Metadata
Release files for messenger-logger-callback 0.3.3
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 |
|---|---|---|---|---|
| messenger_logger_callback-0.3.3.tar.gz | 14.5 kB | Without provenance | Details for messenger_logger_callback-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| messenger_logger_callback-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for messenger_logger_callback-0.3.3-py3-none-any.whl |
Total release size: 25.6 kB
Release files / messenger_logger_callback-0.3.3.tar.gz
| Download URL | messenger_logger_callback-0.3.3.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6fce6c80c0e890bd9c77d9867d59391c11e3bec428bb672de093dd1ce1993c9
|
|
BLAKE2b-256 checksum How to use checksums |
dc36ebffd3512f17a3259bd19826a5db1af7c8ec96ac96b97d158602d82a9d08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / messenger_logger_callback-0.3.3-py3-none-any.whl
| Download URL | messenger_logger_callback-0.3.3-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c7f90d91a603e392abdac4dea734314b3042c5c20998430f665f894dab381dd
|
|
BLAKE2b-256 checksum How to use checksums |
b5ffd294555356a47f813915d9e8a258a1351e5e7d1705d8634eff5231fbc179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for messenger-logger-callback 0.3.3
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.