Skip to main content

hot-reload for python packages

Project description

HOW TO USE?

STEP 1

Import hot_import into your python file with import hot_import or from hot_import import EasyImport

STEP 2

Import the desired module as following import module_name

/!\ It will not work if you do from module_name import * or from module_name import function /!\

STEP 3

Create an object EasyImport that you will use to manage your modules

# main.py
from hot_import import EasyImport

import module


mods = EasyImport([module], auto_update=True)

module = mods.get_module(module)

STEP 4

Check if it's working, to proceed, you have to edit module.py while your code is running

# module.py
def hello():
    return "Hello world!"
# main.py
from hot_import import EasyImport
import time

import module


mods = EasyImport([module], auto_update=True)

module = mods.get_module(module)

while True:
    print(module.hello())
    time.sleep(1)

STEP 5 (optional)

You can add an event on_update to help you debugging

# main.py
from hot_import import EasyImport
import time

import module


mods = EasyImport([module], auto_update=True)

module = mods.get_module(module)


@mods.on_update()
def on_update(module):
    print(f"The module {module.module_name} has been updated!")


while True:
    print(module.hello())
    time.sleep(1)

DISCLAIMER

This library is new and may contain some errors

Otherwise, have fun with it as long as you declare my work

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

hot-import-1.0.1.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

hot_import-1.0.1-py3-none-any.whl (4.4 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