A simple package to send notifications of script execution status.
Project description
Notist: A Simple Package to Send Notifications of Script Execution Status
Notist (Notify State) is a lightweight Python package that lets you keep track of your scripts by sending real-time notifications when they start, finish, or encounter errors. When you're executing long-running jobs or background tasks, Notist helps you stay informed without constantly checking your terminal.
✨ Key Features ✨
For the detailed usage and quick start guide, please refer to the document:
⌛ Real-time Notifications
Get instant updates on the status of your scripts. You can receive notifications when your script:
- starts running;
- completes successfully; or
- encounters an error.
🛠️ Easy Integration with Simple API
Watch Your Functions, Blocks of Code, or Iterations
You can use notist.watch to monitor the execution of your functions, blocks of code, or iterations.
Monitor functions:
import notist
# You can also optionally specify params to include in the notification
# The values passed to these parameters are also reported
@notist.watch(send_to="slack", chennal="my-channel", params=["arg1", "arg2"])
def long_task(arg1: int, arg2: str, arg3: bool) -> None:
# This function will be monitored
# You can receive notifications when it starts, ends, or encounters an error
...
# Your long-running code here
# You can also use it to monitor async functions
@notist.watch()
async def long_task_async() -> None:
# This async function will be monitored
# You can receive notifications when it starts, ends, or encounters an error
...
# Your long-running code here
Monitor blocks of code:
import notist
with notist.watch():
# Code inside this block will be monitored
# You can receive notifications when it starts, ends, or encounters an error
...
# Your long-running code here
Monitor iterations (e.g., for loops):
import notist
for i in notist.watch(range(100), step=10):
# This loop will be monitored, and you'll receive notifications every 10 iterations.
...
# Your long-running code here
This code example send the following notifications:
-
When the function starts running:
Start watching <function `__main__.without_error`> ▷ Defined at: /home/kaito47802/workspace/notist/sample.py:21 ▷ Called from: `__main__` @ /home/kaito47802/workspace/notist/sample.py:28
-
When the function completes successfully:
End watching <function `__main__.without_error`> ▷ Defined at: /home/kaito47802/workspace/notist/sample.py:21 ▷ Called from: `__main__` @ /home/kaito47802/workspace/notist/sample.py:28 ⦿ Execution time: 0s
-
When the function encounters an error:
@kAIto47802 Error while watching <function `__main__.with_error`> ▷ Defined at: /home/kaito47802/workspace/notist/sample.py:15 ▷ Called from: `__main__` @ /home/kaito47802/workspace/notist/sample.py:30 29 │ print("Example function that raises an error") 30 │ with_error() ╭───────┄┄ ──────────── │ 31 │ print("You will see a Slack notification for the error above") │ 32 │ print( │ 33 │ "You can use the watch() helper as a function decorator or as a context manager" ╰─❯ Exception: This is an error ⦿ Execution time: 0s > Traceback (most recent call last): > File "/home/kaito47802/.pyenv/versions/3.12.0/lib/python3.12/contextlib.py", line 81, in inner > return func(*args, **kwds) > ^^^^^^^^^^^^^^^^^^^ > File "/home/kaito47802/workspace/notist/sample.py", line 18, in with_error > raise Exception("This is an error") > Exception: This is an error
[!NOTE] The above example for monitoring iterations does not catch exceptions automatically, since exceptions raised inside the for loop cannot be caught by the iterator in Python. If you also want to be notified when an error occurs, wrap your code in the monitoring context:
with notist.watch(range(100), step=10) as it: for i in it: # This loop will be monitored, and you'll receive notifications every 10 iterations. # If an error occurs inside this context, you'll be notified immediately. ... # Your long-running code here
Register Existing Functions or Methods to be Monitored
You can also use notist.register to register an existing function or method to be monitored.
Monitor existing functions from libraries:
import notist
import requests
# Register the `get` function from the `requests` library
notist.register(requests, "get")
# Now any time you call `requests.get`, it will be monitored
response = requests.get("https://example.com/largefile.zip")
Monitor existing methods of classes:
import notist
from transformers import Trainer
# Register the `train` method of the `Trainer` class
notist.register(Trainer, "train")
# Now any time you call `trainer.train()`, it will be monitored
trainer = Trainer(model=...)
trainer.train()
Monitor existing methods of specific class instances:
import notist
from transformers import Trainer
# Create a Trainer instance
trainer = Trainer(model=...)
# Register the `train` method of the `trainer` instance
# This will not affect other instances of Trainer
notist.register(trainer, "train")
# Now any time you call `trainer.train()`, it will be monitored
trainer.train()
🔔 Multiple Notifiers
Currently supports Slack and Discord. If you need another notifier, feel free to open an issue or a pull request!
📦 Installation 📦
You can install Notist from our GitHub:
uv add notist
# If you're using pip:
# pip install notist
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 notist-0.2.0.tar.gz.
File metadata
- Download URL: notist-0.2.0.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd1f18e97a69632359e4512baabd23449b931666bc6807eadff75871c05c787b
|
|
| MD5 |
e6d70a70d7373d00177c370085a18bd6
|
|
| BLAKE2b-256 |
003b42493328fc70a14a8bffdd9787c2bb639918dba9f154f914032ebd80fbd6
|
File details
Details for the file notist-0.2.0-py3-none-any.whl.
File metadata
- Download URL: notist-0.2.0-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a12b93de28b7acc46685bf8a7ff1063424b8895431ee0d1797a2e40f0a4625a
|
|
| MD5 |
f2635a83e80b8ef545fa4997d6e93eee
|
|
| BLAKE2b-256 |
23fd64a6189d0d5c339e1ed0ebc8aa8122fec96c2afe5749f213055397f16e9a
|