Python Hot Module Reload
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 X - ✅
from X import Y
Supported Types:
- ✅
Module - ✅
Function - ✅
Class
Installation
pip install python-hmr
Quick Start
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.
Detailed Usage
Function/Class instance
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()
@Decorated Function
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
Stateful application
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"])
Acknowledgement
Inspired from the following package.
Metadata
Release files for python-hmr 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_hmr-0.3.0.tar.gz | 831.3 kB | Without provenance | Details for python_hmr-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_hmr-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for python_hmr-0.3.0-py3-none-any.whl |
Total release size: 838.3 kB
Release files / python_hmr-0.3.0.tar.gz
| Download URL | python_hmr-0.3.0.tar.gz |
|---|---|
| Size | 831.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ac20308904d0aa4fe2ef9d48a2e90537b9140490861917e62e63fb76bdc1543
|
|
BLAKE2b-256 checksum How to use checksums |
4882772e678f85da8a9dd44b9999a40eba64888e47fec86eec2b198f37462730
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / python_hmr-0.3.0-py3-none-any.whl
| Download URL | python_hmr-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9c70f6890b6fa9ca03ec8cae08ef93017ce2b4ab908d7989ab1986a78677164
|
|
BLAKE2b-256 checksum How to use checksums |
ed850378d09e062e3769761d8ca4880c2f98196385b9f1d4c255d71686690ab9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for python-hmr 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.