Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonra1993 committed Apr 1, 2024
2 parents 2f0a9ac + eb5edaf commit 3c173d5
Show file tree
Hide file tree
Showing 61 changed files with 31 additions and 35,380 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Async configuration for FastAPI and SQLModel

This is a project template which uses [FastAPI](https://fastapi.tiangolo.com/), [Alembic](https://alembic.sqlalchemy.org/en/latest/) and async [SQLModel](https://sqlmodel.tiangolo.com/) as ORM which already is compatible with [Pydantic V2](https://docs.pydantic.dev/2.5/) and [SQLAlchemy V2.0](https://docs.sqlalchemy.org/en/20/). It shows a complete async CRUD template using authentication. Our implementation utilizes the newest version of FastAPI and incorporates typing hints that are fully compatible with **Python >=3.10**. If you're looking to build modern and efficient web applications with Python, this template will provide you with the necessary tools to get started quickly. You can read a short article with the motivations of starting this project in [Our Journey Using Async FastAPI](https://medium.com/allient/our-journey-using-async-fastapi-to-harnessing-the-power-of-modern-web-apis-90301827f14c?source=friends_link&sk=9006b3f2a4137a28a8576a69546c8c18). If you are looking for a started template CLI, I recommend you to use [create-fastapi-project](https://github.com/allient/create-fastapi-project)
This is a project template which uses [FastAPI](https://fastapi.tiangolo.com/), [Alembic](https://alembic.sqlalchemy.org/en/latest/) and async [SQLModel](https://sqlmodel.tiangolo.com/) as ORM which already is compatible with [Pydantic V2](https://docs.pydantic.dev/2.5/) and [SQLAlchemy V2.0](https://docs.sqlalchemy.org/en/20/). It shows a complete async CRUD template using authentication. Our implementation utilizes the newest version of FastAPI and incorporates typing hints that are fully compatible with **Python >=3.10**. If you're looking to build modern and efficient web applications with Python, this template will provide you with the necessary tools to get started quickly. You can read a short article with the motivations of starting this project in [Our Journey Using Async FastAPI](https://medium.com/allient/our-journey-using-async-fastapi-to-harnessing-the-power-of-modern-web-apis-90301827f14c?source=friends_link&sk=9006b3f2a4137a28a8576a69546c8c18).

If you are looking to create new a project from zero, I recommend you to use [create-fastapi-project](https://github.com/allient/create-fastapi-project).

Do you need assistance, trainning or support for your newxt project using fastapi?. Please don't hesitate to get in touch with our team at [[email protected]](mailto:[email protected]) or schedule a meeting with us [here](https://calendly.com/jonathanvargas).

## Why Use This Template?

Expand Down Expand Up @@ -416,7 +420,6 @@ To begin experimenting with the basic chatbot, follow these steps:
- [x] Add static code analysis using SonarQube
- [x] Function return type annotations to declare the response_model (fastapi > 0.89.0)
- [x] Add export report api in csv/xlsx files using StreamingResponse
- [x] Add production deployment orchestation using terraform + Elastic Beanstalk - AWS
- [x] Add Github actions automation for deploy on Elastic Beanstalk - AWS
- [x] Database query optimization. Many-Many use "selectin" and One-One and One-Many use "joined" [issue](https://github.com/jonra1993/fastapi-alembic-sqlmodel-async/issues/20)
- [x] Add Enum sample column
Expand All @@ -437,11 +440,12 @@ To begin experimenting with the basic chatbot, follow these steps:
- [ ] Add AuthZ using oso
- [ ] Add SSL to reverse proxy on prod
- [ ] Add instructions on doc for production deployment using github actions and dockerhub (CI/CD)
- [ ] Add production deployment orchestation using terraform + Elastic Beanstalk - AWS
- [ ] Convert repo into template using cookiecutter

### Support and Maintenance

`fastapi-alembic-sqlmodel-async` is supported by the [Allient development team](https://www.allient.io/). Our team is composed by a experienced professionals specializing in FastAPI projects and NLP. If you need assistance or support for your project, please don't hesitate to get in touch with us at [[email protected]](mailto:[email protected]) or schedule a meeting with us [here](https://calendly.com/jonathanvargas).
`fastapi-alembic-sqlmodel-async` is supported by the [Allient development team](https://www.allient.io/). Our team is composed by a experienced professionals specializing in FastAPI projects and NLP. Please don't hesitate to get in touch with our team at [[email protected]](mailto:[email protected]) or schedule a meeting with us [here](https://calendly.com/jonathanvargas).


PR are welcome ❤️
Expand Down
5 changes: 3 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim-2022-11-25
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
ENV PYTHONUNBUFFERED=1
ENV PIP_DEFAULT_TIMEOUT=100
WORKDIR /code
# Install Poetry
RUN apt clean && apt update && apt install curl -y
Expand All @@ -13,7 +14,7 @@ COPY app/pyproject.toml app/poetry.lock* /code/

# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"

ENV PYTHONPATH=/code
EXPOSE 8000
15 changes: 8 additions & 7 deletions backend/app/app/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from app.core.config import ModeEnum, settings
from sqlalchemy.ext.asyncio import create_async_engine
from sqlmodel.ext.asyncio.session import AsyncSession
from sqlalchemy.pool import NullPool, QueuePool
from sqlalchemy.pool import NullPool, AsyncAdaptedQueuePool

DB_POOL_SIZE = 83
WEB_CONCURRENCY = 9
Expand All @@ -14,12 +14,11 @@
engine = create_async_engine(
str(settings.ASYNC_DATABASE_URI),
echo=False,
future=True,
# pool_size=POOL_SIZE,
# max_overflow=64,
poolclass=NullPool
if settings.MODE == ModeEnum.testing
else QueuePool, # Asincio pytest works with NullPool
else AsyncAdaptedQueuePool, # Asincio pytest works with NullPool
# pool_size=POOL_SIZE,
# max_overflow=64,
)

SessionLocal = sessionmaker(
Expand All @@ -32,8 +31,10 @@

engine_celery = create_async_engine(
str(settings.ASYNC_CELERY_BEAT_DATABASE_URI),
# echo=True,
future=True,
echo=False,
poolclass=NullPool
if settings.MODE == ModeEnum.testing
else AsyncAdaptedQueuePool, # Asincio pytest works with NullPool
# pool_size=POOL_SIZE,
# max_overflow=64,
)
Expand Down
8 changes: 4 additions & 4 deletions backend/app/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from jwt import DecodeError, ExpiredSignatureError, MissingRequiredClaimError
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage
from sqlalchemy.pool import NullPool, QueuePool
from sqlalchemy.pool import NullPool, AsyncAdaptedQueuePool
from starlette.middleware.cors import CORSMiddleware
from transformers import pipeline

Expand Down Expand Up @@ -117,12 +117,12 @@ async def lifespan(app: FastAPI):
db_url=str(settings.ASYNC_DATABASE_URI),
engine_args={
"echo": False,
"poolclass": NullPool
if settings.MODE == ModeEnum.testing
else AsyncAdaptedQueuePool
# "pool_pre_ping": True,
# "pool_size": settings.POOL_SIZE,
# "max_overflow": 64,
"poolclass": NullPool
if settings.MODE == ModeEnum.testing
else QueuePool, # Asincio pytest works with NullPool
},
)
app.add_middleware(GlobalsMiddleware)
Expand Down
Loading

0 comments on commit 3c173d5

Please sign in to comment.