
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
python-hmr
Advanced tools
Better debugging experience with HMR
Automatic reload your project when files are modified.
No need to modify your source code. Works in any environment.

Supported Syntax:
import Xfrom X import YSupported Types:
ModuleFunctionClasspip install python-hmr
[!CAUTION] From v0.3.0, there is only one API,
hmr.reload.
Import your dev packages as usual. And add 2 lines for automatically reloading.
import dev
import hmr
dev = hmr.reload(dev)
If you have multiple modules to reload, you can do it like this.
from dev import run1, run2
import hmr
run1, run2 = hmr.reload(run1, run2)
Now you are ready to go! Try to modify the run1 or run2
and see the magic happen.
When you try to add HMR for a function or class, remember to pass the name of the function or class instance without parenthesis.
from dev import Runner
import hmr
Runner = hmr.reload(Runner)
a = Runner()
b = Runner()
[!IMPORTANT] Here, when both
aandbwill be updated after reloading. This may be helpful if you have an expansive state store within the class instance.However, it's suggested to reinitialize the class instance after reloading.
Use functools.wraps to preserve signature of your function, or the function information will be replaced by the decorator itself.
import functools
def work(f):
@functools.wraps(f)
def args(*arg, **kwargs):
return f(*arg, **kwargs)
return args
If your application is stateful, you can exclude the state from being reloaded.
For simplicity, you can group all your state variable into the same .py file like state.py
and exclude that from being reloaded.
Make sure you know what you are doing. This could lead to unexpected behavior and unreproducible bugs.
import dev
import hmr
dev = hmr.reload(dev, exclude=["dev.state"])
In this way dev/state.py will not be reloaded, the state will persist.
This also apply when reloading a function or class.
from dev import run
import hmr
run = hmr.reload(run, exclude=["dev.state"])
Inspired from the following package.
FAQs
Hot module reload for python
We found that python-hmr demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.