Skip to main content

Hot module reload for python

Project description

Python Hot Module Reload

Test status codecov pypi license-mit

Automatic reload your project when files are modified.

No need to modify your source code.

reload

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

python-hmr-0.1.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

python_hmr-0.1.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page