Skip to content

Quick start

After installing HMR, create these two files in one directory.

greet.py
def message():
    return "Hello, World!"
main.py
from greet import message

print(message())

Run from that directory:

hmr main.py

The first message prints immediately. The process then waits for changes. Change the return value in greet.py to "Hello, HMR!" and save: main.py runs again and prints the new message, without starting a new Python process. Stop with Ctrl+C.

The import reads greet.message, so HMR records a dependency. Changing that function invalidates the dependent entry module. This does not mean arbitrary existing references or every object in memory are automatically updated.

Running a module

hmr -m mypackage

As with python -m mypackage, a package needs a __main__.py. Arguments following the entry path or module name are passed to the program.

Servers need an integration

The plain hmr command executes the entry file before it starts watching. A blocking app.run() or infinite loop at module scope prevents that watcher from starting.

  • ASGI / FastAPI: uvicorn-hmr main:app
  • MCP: mcp-hmr main:app
  • Flask: use the example's threaded start.py, then hmr start.py

Start with the plain-module demo to inspect dependency propagation without a server. See reactive programming for explicit reactive state.