You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package provides hot module reloading (HMR) for [`uvicorn`](https://github.com/encode/uvicorn).
4
+
5
+
It uses [`watchfiles`](https://github.com/samuelcolvin/watchfiles) to detect FS modifications,
6
+
re-executes the corresponding modules and restart the server (in the same process).
7
+
8
+
Since the reload is on-demand and the server is not restarted on every request, it is much faster than the built-in `--reload` option provided by `uvicorn`.
9
+
10
+
## Installation
11
+
12
+
```sh
13
+
pip install uvicorn-hmr
14
+
```
15
+
16
+
## Usage
17
+
18
+
Replace
19
+
20
+
```sh
21
+
uvicorn main:app --reload
22
+
```
23
+
24
+
with
25
+
26
+
```sh
27
+
uvicorn-hmr main:app
28
+
```
29
+
30
+
> [!NOTE]
31
+
> Since this package is a proof-of-concept yet, there is no configuration available. But contributions are welcome!
32
+
33
+
## Why?
34
+
35
+
1. Restarting process on every request is not always necessary, and is rather expensive. With `hmr`, 3-party packages imports are memoized.
36
+
2.`hmr` track dependencies on runtime, and only rerun necessary modules. If you changed a python file not used by the server entrypoint, it won't be reloaded.
37
+
38
+
## What this package is not?
39
+
40
+
> [!CAUTION]
41
+
> `hmr` are sometimes refer to a feature that updates the page in the browser on the client side when the server code changes. This is not that. This package is a server-side HMR, that reloads the server code when it changes.
0 commit comments