Simple library to automatically restart Python scripts on source changes
Project description
Simple Reload
Simple library to automatically restart Python scripts on source changes
A lightweight utility that monitors Python files for changes and automatically restarts your script when changes are detected. Perfect for development workflows where you want to see immediate results without manually restarting your application.
import mymodule
from simple_reload import run_simple_reload
def main():
run_simple_reload([mymodule])
print('Hello, running my CLI.')
# Main logic
from time import sleep
try:
while True: sleep(1)
except KeyboardInterrupt:
print('Exiting program (potentially due to file change)')
if __name__ == "__main__":
main()
Installation
pip install simple-reload
Detailed Usage
run_simple_reload takes two main parameters:
modules: A list of modules to watch for changes. The function will monitor all Python files in the directories containing these modules.on_change: Optional callback function that gets called when files change. It receives a set of tuples with the change type and file path.
You can conditionally call run_simple_reload if you'd like to only enable it in debug mode. You can also the auto-reload feature by setting the environment variable SIMPLE_RELOAD_DISABLE=1.
Detailed example:
import myapp
from simple_reload import run_simple_reload, Change
from contextlib import suppress
def main():
if myapp.is_debug_enabled():
run_simple_reload([myapp], on_change=print)
with supress(KeyboardInterrupt):
myapp.start()
if __name__ == "__main__":
main()
When a file changes, the child process is cleanly shutdown (via SIGINT) and a new child is spawned with the same command line arguments that were used to start it originally.
Development
Simple Reload uses Rye for dependency management and the development workflow. To get started with development, ensure you have Rye installed and then clone the repository and set up the environment:
git clone https://github.com/MatthewScholefield/simple-reload.git
cd simple-reload
rye sync
rye run pre-commit install
# Run tests
rye test
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 simple_reload-0.1.0.tar.gz.
File metadata
- Download URL: simple_reload-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1c0068957596c4cca9073b062d93c28ffb9684ed97e2709175fce34d9b98b41
|
|
| MD5 |
7ca1d25f190d81c08156a4526128b181
|
|
| BLAKE2b-256 |
f7447e00191e7768b136bd787de5a0fa1637fba2fef651be94ccc87308cc896b
|
File details
Details for the file simple_reload-0.1.0-py3-none-any.whl.
File metadata
- Download URL: simple_reload-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02f092287aeb4332e89ada336503e97aff5fe97601ad105bf61500230afb902a
|
|
| MD5 |
cae83fcd581a0ab0aaf9979534ba83c4
|
|
| BLAKE2b-256 |
747f7853d26f74453077ad68722ede068a314e6f26669bea2d6480277ab7e3ce
|