Skip to main content

Hot module reload for python

Project description

python-hmr logo

Python Hot Module Reload

Test status pypi license-mit

Automatic reload your project when files are modified.

No need to modify your source code. Works at any environment.

reload

Supported Syntax:

  • import X
  • from X import Y

Supported Types:

  • Module
  • Function
  • Class

Installation

pip install python-hmr

Quick Start

Import your dev package as usual.

import my_pkg

Add 2 lines to automatically reload your source code.

import my_pkg

import hmr
my_pkg = hmr.reload(my_pkg)

Now you are ready to go!

Usage Manual

Module/Submodule reload

import my_pkg.sub_module as sub

import hmr
sub = hmr.reload(sub)

Function/Class reload

No difference to reloading module

from my_pkg import func, Class

import hmr
func = hmr.reload(func)
Class = hmr.reload(Class)

If your have multiple class instance, they will all be updated. Both a and b will be updated.

a = Class()
b = Class()

@Decorated Function reload

Use functools.wraps to preserve signature of your function, or the function information will be replaced by the decorator itself.

State handling

If your application is not stateless, it's suggested that you 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 my_pkg

import hmr
my_pkg = hmr.reload(my_pkg, excluded=["my_pkg.state"])

The my_pkg/state.py will not be reloaded, the state will persist.

The same apply when reloading a function or class.

from my_pkg import func

import hmr
func = hmr.reload(func, excluded=["my_pkg.state"])

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.2.0.tar.gz (516.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_hmr-0.2.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file python-hmr-0.2.0.tar.gz.

File metadata

  • Download URL: python-hmr-0.2.0.tar.gz
  • Upload date:
  • Size: 516.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for python-hmr-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ad81b053d07740b924af3ef90de2b121a28706d6cc13b28d809354239a81d7a6
MD5 fdc704cf30ea6bc36df85c6adc0277b7
BLAKE2b-256 ed1ff2aadbcfaf93789bd0a576e26bf56e5d5c8d9c3319ea6b667248fae5f63e

See more details on using hashes here.

File details

Details for the file python_hmr-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: python_hmr-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for python_hmr-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a35df72246d49ad24930049b26234711d9695f305f9716df88a8ecfdc32bed95
MD5 fd26b4a0e9149d3e25918c9ca12f926d
BLAKE2b-256 51b144e38e478283beeeaf8a07672b0c5d55c55599be3ec50c0aefbc17bcc90a

See more details on using hashes here.

Supported by

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