Skip to content

Commit 4034cbf

Browse files
committed
Updated config.py with Pydantic base settings class. Created startup.sh and startup.ps1 to provide easy way to start Uvicorn. Added engine and client constructor in hugs.py router.
1 parent a73ed9b commit 4034cbf

File tree

8 files changed

+29
-20
lines changed

8 files changed

+29
-20
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Thanks to [Sebastián Ramírez @tiangolo](https://github.com/tiangolo) we have t
1414

1515
While learning and using FastAPI I have often needed/wanted lightweight project scaffolding. The project generators and scaffolding projects in the FastAPI ecosystem have been either too deterministic and too big or not deterministic enough for me.
1616

17-
This uis how I set up a new FastAPI project. I hope this is helpful.
17+
This is how I set up a new FastAPI project. I hope this is helpful.
1818

1919
## Dependencies:
2020

@@ -27,6 +27,7 @@ This uis how I set up a new FastAPI project. I hope this is helpful.
2727
|[Docker](https://www.docker.com/products/docker-desktop) | (Optional) I use it to startup DBs instead of installing directly. Will make your life easier. There are also images for bundled FastAPI environmets on Docker Hub.
2828
|[ODMantic](https://art049.github.io/odmantic/) | (Optional) ORM for MongoDB with great model and document support. |
2929
|[TortoiseORM](https://tortoise-orm.readthedocs.io/en/latest/) | (Optional) ASYNC ORM that works well with FastAPI and Postgres/MySQL
30+
|[dnsPython](https://www.dnspython.org/) | (Optional) Used for querrying remote DBs etc.
3031

3132

3233
## Get Started
@@ -58,21 +59,30 @@ This uis how I set up a new FastAPI project. I hope this is helpful.
5859
```bash
5960
pip install -r requirements.txt
6061
```
61-
8. (Optional) Pull latest Mongo image and create mongo container for dev purposes
62+
8. (Optional) If you want to use Mongo then edit fastapi-scaffold-base\app\config\config.py to add Mongo URI.
63+
64+
9. (Optional) Pull latest Mongo image and create mongo container for dev purposes
6265
```docker
6366
docker pull mongo:latest
6467
docker run --rm --net=host mongo
6568
```
66-
9. Set execute permissions on either win-start-FastApi.ps1 or nix-start-FastAPI
69+
10. Set execute permissions on either startup.ps1 or startup.sh
70+
71+
11. Run the start-FastAPI for your system
6772
68-
10. Run the start-FastAPI for your system
73+
12. Go to https://localhost:8000 to see a basic HTML page with sections for content. You can edit the Jinja placeholders to add content as you see fit in fastapi-scaffold-base\templates\indeix.html. This is a responsive template based on CSS Grid without using Javacript. Add any static assets to static.
6974
70-
11. Go to https://localhost:8000/docs to see your FastAPI documentation and explore the sample docs.
75+
12. Go to https://localhost:8000/docs to see your FastAPI documentation and explore the sample docs.
7176
7277
73-
12. Close your FastAPI terminal and your Mongo Terminal.
78+
13. Close your FastAPI terminal and your Mongo Terminal.
7479
7580
11. To get out of venv
7681
```bash
7782
deactivate
7883
```
84+
85+
--TODO--
86+
1) Add unit tests and Integrate Pytest
87+
2) Add implicit support for Relational data
88+
3) Add plug and play content through API calls

app/config/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pydantic import BaseSettings
2+
class Settings(BaseSettings):
3+
uri: MONGO_URL
4+
5+
6+
7+
settings = Settings()

app/routers/hugs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
from app.data import models
33
from typing import List
44
from odmantic import AIOEngine, ObjectId
5+
from motor.motor_asyncio import AsyncIOMotorClient
6+
from app.config import config
57

68
router = APIRouter()
9+
settings = config.Settings()
710

811
Hug = models.Hug
9-
engine = AIOEngine()
12+
client = AsyncIOMotorClient(settings.uri)
13+
engine = AIOEngine(motor_client=client)
1014

1115
@router.put("/hugs/", response_model=Hug, tags=["hugs"])
1216
async def new_hug(hug: Hug):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ Rx==1.6.1
5050
six==1.15.0
5151
starlette==0.13.6
5252
uvicorn==0.12.2
53+
dnspython
File renamed without changes.
File renamed without changes.

static/js/main.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)