Skip to content

Commit dfbe518

Browse files
committed
refactor '__main__' block and update README
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
1 parent a37e3d3 commit dfbe518

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Run the server using `Uvicorn`:
4848
uvicorn main:app --reload
4949
```
5050

51+
> You can also run the server by just executing the `main.py` file:
52+
>
53+
> ```console
54+
> python main.py
55+
> ```
56+
5157
Then open your browser at [http://localhost:8000](http://localhost:8000).
5258
5359
There is only one endpoint available: `/users`. It returns a list of all users

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""An example of using FastAPI with Async SQLAlchemy 2."""
2-
import subprocess
32
from contextlib import asynccontextmanager
43

4+
import uvicorn
55
from fastapi import Depends, FastAPI
66
from sqlalchemy import select
77

@@ -42,4 +42,4 @@ async def get_users(session=Depends(get_db)):
4242

4343

4444
if __name__ == "__main__":
45-
subprocess.call(["uvicorn", "main:app", "--reload"])
45+
uvicorn.run("main:app", reload=True)

0 commit comments

Comments
 (0)