Hot module reload for python
Project description
Python Hot Module Reload
Automatic reload your project when files are modified.
No need to modify your source code.
Supported Syntax:
- ✅
import X
- ✅
import X as Y
- ✅
from X import Y
- ✅
from X import Y as A
Supported Types:
- ✅
Module
- ✅
Function
- ✅
Class
Installation
pip install python-hmr
Usage
Just import your developing package and replace it with Reloader
.
Then you can use it exactly like how you use a module before.
import my_pkg
from hmr import Reloader
my_pkg = Reloader(my_pkg)
my_pkg.func()
# >>> "Hi from func"
Or you can manually reload it
my_pkg.reload()
To stop the reloading
my_pkg.stop()
Module/Submodule reload
import my_pkg.sub_module as sub
from hmr import Reloader
sub = Reloader(sub)
If your application contains submodule that handle state, you can exclude it from reloading.
excluded
only works with module type
Make sure you know what you are doing. This could lead to unexpected behavior and unreproducible bugs.
import my_pkg
from hmr import Reloader
my_pkg = Reloader(my_pkg, excluded=['my_pkg.state'])
Function/Class reload
No difference to reloading module
from my_pkg import func, Class
from hmr import Reloader
func = Reloader(func)
Class = Reloader(Class)
@Decorated Function reload
Use functools.wraps to preserve signature of your function, or the function information will be replaced by the decorator itself.
Acknowledgement
Inspired from the following package.
Project details
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
Hashes for python_hmr-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 472ba60f7648e85118f69c3c8f061aab318b6340fbba47c18c406ed485a45dab |
|
MD5 | b502d29446a95ee932b40b11bfa4849f |
|
BLAKE2b-256 | ce4a07da0f5e8e8428cbc0b6069f7713ec474269a7c1f8af86456356e725d5d3 |