Skip to main content

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:

  1. modules: A list of modules to watch for changes. The function will monitor all Python files in the directories containing these modules.
  2. 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

Metadata

Release files for simple-reload 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-reload 0.1.0
File Size Uploaded
simple_reload-0.1.0.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-reload 0.1.0
File Interpreter ABI Platform
simple_reload-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / simple_reload-0.1.0.tar.gz

Download URL simple_reload-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e1c0068957596c4cca9073b062d93c28ffb9684ed97e2709175fce34d9b98b41
BLAKE2b-256 checksum
How to use checksums
f7447e00191e7768b136bd787de5a0fa1637fba2fef651be94ccc87308cc896b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.2

Release files / simple_reload-0.1.0-py3-none-any.whl

Download URL simple_reload-0.1.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02f092287aeb4332e89ada336503e97aff5fe97601ad105bf61500230afb902a
BLAKE2b-256 checksum
How to use checksums
747f7853d26f74453077ad68722ede068a314e6f26669bea2d6480277ab7e3ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page