https://github.com/leosimoes/dio-python-fastapi-workout
Project "Developing your First API with FastAPI, Python and Docker" by DIO.
https://github.com/leosimoes/dio-python-fastapi-workout
fastapi python rest-api sqlalchemy
Last synced: 2 months ago
JSON representation
Project "Developing your First API with FastAPI, Python and Docker" by DIO.
- Host: GitHub
- URL: https://github.com/leosimoes/dio-python-fastapi-workout
- Owner: leosimoes
- Created: 2024-05-26T14:25:06.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-27T16:00:49.000Z (about 2 years ago)
- Last Synced: 2024-05-29T02:46:37.158Z (about 2 years ago)
- Topics: fastapi, python, rest-api, sqlalchemy
- Language: Python
- Homepage:
- Size: 373 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DIO - Python - FastAPI - Workout
Project "Developing your First API with FastAPI, Python and Docker" by DIO.
## Development steps
The project development steps were:
1. Create project (in PyCharm):

2. Run the application and open the browser at `http://127.0.0.1:8000/`:


3. Check if the dependencies `fastapi`, `uvicorn`, `sqlalchemy`, `pydantic`, `alembic` and `asyncpg` are in `requirements.txt`.
4. Create `contrib` package with the files:
- `__init__.py`;
- `schemas.py` which implements the `BaseSchema` class:
```python
from pydantic import BaseModel
class BaseSchema(BaseModel):
class Config:
extra = 'forbid'
from_attributes=True
```
- `models.py` which implements the `BaseModel` class:
```python
from uuid import uuid4
from sqlalchemy import UUID
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy.dialects.postgresql import UUID as PG_UUID
class BaseModel(DeclarativeBase):
id: Mapped[UUID] = mapped_column(PG_UUID(as_uuid=True), default=uuid4, nullable=False)
```
Note: The classes in other packages will inherit from the classes in the corresponding files in the contrib package.
5. Create a package for each entity in MER, with the files `__init__.py`, `schemas.py` and `models.py`:
- athlete package with classes `Athlete` and `AthleteModel`
- category package with classes `Category` and `CategoryModel`
- training_center package with classes `TrainingCenter` and `TrainingCenterModel`
6. Run the `alembic init` command.
7. Create the `docker-compose.yml` file.
## References
DIO - Desenvolvendo sua Primeira API com FastAPI, Python e Docker:
https://web.dio.me/lab/desenvolvendo-uma-api-assincrona-com-fastapi/learning/4058b4b5-1716-43fb-9bf6-121139c16227
| https://github.com/digitalinnovationone/workout_api/tree/main/workout_api
FastAPI - Documentation:
https://fastapi.tiangolo.com/