A Python library to notify when a script has finished running and providing insights such as run time, CPU and RAM usage, and more.
Project description
scriptime
Python library to notify when a script has finished running and providing insights such as run time, CPU and RAM usage, and more.
About
This project will send you an email or text message notifying you when a script has completed running. Configurable thorugh a config file, environment variables, or hardcoding the email credentials, this project has little overhead to get started.
Getting Started
The first step to using scriptime is setting up the email that will be sending the notifications. scriptime uses the built-in Python SMTP to send emails which requires an email address, said email's password, and an SMTP SSL server and port. Therfore,
- Choose how you will pass your email credential into scriptime:
-
JSON config file
To set up, create a .json file with the following contents:
{ "scriptime_email": "example@email.com", "scriptime_password": "superSecure1", "scriptime_server": "smtp.email.com" "scriptime_port": 123> } -
Environment variables
Recommended -- if you plan to use scriptime more than once this will be the simplest method over time.
Set the following environment variales:
SCRIPTIME_EMAIL=example@email.comSCRIPTIME_PASSWORD=superSecure1SCRIPTIME_SERVER=smtp.email.comSCRIPTIME_PORT=123 -
Hard coding
If you choose to go the hard code route, when creating the
Timerobject, you will need to pass in extra arguments. Your constructor call should look something like:timer = Timer(method="hardcode", email="example@email.com", password="superSecure1", server="smtp.email.com", port=123)
Note that if you are using Gmail, you may have to create an app password. Your normal password will likely not work. Other email services may have similar catches.
-
Using scriptimer
The use of scriptimer is very straightforward:
-
In a terminal,
pip install scriptime -
In a Python (.py) or Jupyter Notebook (.ipynb) file, add
from scriptime import Timer
to your imports.
-
Create an instance of a timer, which could be done in three ways dependant on what you did in Getting Started:
-
JSON config file
timer = Timer(method="json", config_file="path/to/config.json")
-
Environment variables
timer = Timer(method="env")
-
Hard coding
(This may look famiiliar):
timer = Timer(method="hardcode", email="example@email.com", password="superSecure1", server="smtp.email.com", port=123)
-
-
Start the timer
timer.start()
-
Then, at the end of the script (or wherever you would like a notification), add one of or both of the following:
-
Email notification
To get an email notification, simply call the send_email function:
timer.send_email("receiver@email.com")
You can also send a text using your carrier's email-to-SMS address. You can find your carrier at: list of carrier SMS emails
timer.send_email("0123456789@text.att.net")
Multiple email addresses, phone numbers, or any combination thereof can be passed in as a list:
timer.send_email(["receiver@email.com", "0123456789@text.att.net"])
Lastly, if you would like to see the output of the body in order to have the statistics persistent or just because you're curious, simply use the
print_bodyflag:timer.send_email("receiver@email.com", print_body=True)
-
Play sound
If you would like an audible notification that your script has finished, simply:
timer.play_sound()
If the time measurement aspect of this program is important to you, be sure to run the play sound after sending the email (if you are sending the email at the end of the script) as it takes ~5 seconds to play the sound.
-
Output
The subject of the email will be:
[MM-DD-YYYY HH:MM:SS] <name of file> Finished
The email/text body will look like the following:
Your script has finished.
Elapsed Time: 00:00:01
Max RAM Usage: 74.00%
Max CPU Usage: 40.90%
Remaining RAM Available: 2.08 GB
System information: Darwin
Processor: arm
Python Version: 3.11.4
Packages Used:
Package: numpy, Version: 1.24.2
Package: scikit-learn, Version: 1.2.2
...
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
File details
Details for the file scriptime-0.1.4.tar.gz.
File metadata
- Download URL: scriptime-0.1.4.tar.gz
- Upload date:
- Size: 573.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
883d6d44633e4c00554097f4733c0a4517ccfb4060be9f18939a9cf5df2905dd
|
|
| MD5 |
dac3b6beb90c787a97478dd5c14afb63
|
|
| BLAKE2b-256 |
49ce5542ad308a3ff6fd0b03ade28ac762790869f5799959f7ce151de5879b5d
|