Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thadeshammer/boilerplate-sqlalch-fastapi
A light skeleton to get you up and moving with SQLAlchemy and FastAPI. Uses Docker. Features a small SlowAPI example as well.
https://github.com/thadeshammer/boilerplate-sqlalch-fastapi
docker fastapi postgres python slowapi sqlalchemy uvicorn
Last synced: 5 days ago
JSON representation
A light skeleton to get you up and moving with SQLAlchemy and FastAPI. Uses Docker. Features a small SlowAPI example as well.
- Host: GitHub
- URL: https://github.com/thadeshammer/boilerplate-sqlalch-fastapi
- Owner: thadeshammer
- License: mit
- Created: 2024-05-19T17:59:10.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-05-19T23:39:14.000Z (6 months ago)
- Last Synced: 2024-05-20T21:16:47.369Z (6 months ago)
- Topics: docker, fastapi, postgres, python, slowapi, sqlalchemy, uvicorn
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Boilerplate Python for FastAPI and SQLAlchemy
A simplistic and thoroughly commented example to get you up and moving with minimal fuss. There's a SlowAPI rate-limiting example you can trim out if you don't need it.
## Quick Start
Clone, start docker, and run:
```
docker-compose build && docker-compose up
```
Then open up the Swagger UI via `localhost/docs`There are only three VERY simple endpoints in this example.
* `/` the root just returns 'Ready.' if it did in fact start okay.
* `/addname` takes a string 'name' and sticks it into the DB along with a generated UUID.
* `/getnames` will spit out everything in that table.**NOTE the DB is not persisted outside of its container** so if you destroy/rebuild the container, that data is gone. If you don't want that, you'll need to mount a volume for it.
## What's Inside
### Docker
**DB** This example uses postgres but I also tested it against mysql and sqlite3.
**SERVER** FastAPI on uvicorn, see `requirements.txt` for libraries you'll need. Runs on port 80.
### Python
I'm using 3.11 in this example, but since FastAPI has a dependency on `wheel`, you might find that your IDE (looking at you VSCode) will always be unhappy with FastAPI; this is because - I've learned - the maintainers of wheel deprioritize Windows. (Personally, I don't blame them, but it is a factor.) Since the app itself runs dockerized, it will work. You just have to deal with the red squigglies.
* **fastapi** run on uvicorn with hot-reload.
* **slowapi** with a simplistic example of rate-limiting
* **sqlalchemy** ORM with:
* a test model that creates an associated table in the db if it doesn't exist.
* bare minimum setup to get python and the db talking
* **pydantic** for the SQLAlchemy to FastAPI communication. (I learned about SQLModel later.)