A module reloader for Python
Project description
Module Reloader
module_reloader is a Python package that provides functionality to track and reload
modules dynamically. It helps you manage module reloading in a controlled manner,
making it useful for development environments where you need to reload modules frequently.
Why module_reloader?
This package was created to facilitate REPL-driven development in Python, similar to the
workflow experienced in languages like Clojure. In such a workflow, developers often modify
their code and want to see the changes reflected immediately without restarting their
entire application. module_reloader aims to provide an efficient and easy way to reload
modules dynamically, enabling a more interactive and productive development experience.
Features
- Track loaded modules and their load times.
- Reload specific modules by name or by file path.
- Identify and reload stale modules (modules that have been modified since they were last loaded).
Installation
You can install the package directly from the source directory:
pip install .
Or install it in editable mode (useful for development):
pip install -e .
Usage
Application startup
When your program starts up, import module_reloader before importing any other application-level modules. module_reloader will then keep track of these loaded modules automatically.
import module_reloader
Reloading a single module
When you're working within a single module and wants to reload it, you can simply send the full path of the module you're trying to reload:
module_reloader.reload_module_by_path("full/path/to/module/here")
It should be fairly straightforward to configure your favorite editor to send that string along with the path of the module/file you're working with directly to the REPL.
Reloading multiple modules
If you're working with multiple modules all at once, you can also simply choose to do:
module_reloader.reload_stale_modules()
module_reloader will then look through all modules it has been tracking and reload any
module that has been changed since it was last loaded.
Caveat
Avoid from ... import ...
Creating references to functions and variables using from ... import ... can be
problematic because these references will not be updated when the module is reloaded.
Instead, it is recommended to use import ... as ... to alias the module name and
access its contents through the module object. This ensures that you always access
the updated functions and variables.
Class instances
Module reloading will have no effect on classes that have already been instantiated. If you need to update instances of a class after reloading the module, you will need to recreate those instances.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file module_reloader-0.1.0.tar.gz.
File metadata
- Download URL: module_reloader-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c876741ce86a8e80b9d8ff4e0e348069d88cd16bf3e7a5f933ef362adc0b2949
|
|
| MD5 |
450b5a65e251f6e215eb2982177f2ea8
|
|
| BLAKE2b-256 |
f666425a828e6cb6e6c50e2b823140a9cb8d79b5ace4458c09bf38aac290f332
|
File details
Details for the file module_reloader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: module_reloader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c080934b1cce48b75eb29250053260ae753909b3b542b2c662eb6269b40e0332
|
|
| MD5 |
df5e3378821c80c451ac3b83abfb095b
|
|
| BLAKE2b-256 |
7500fbab39c1be483cbf02f633d21348ff93bca44f292d4addccc2aa4059ccac
|