Skip to content

Commit 3c173d5

Browse files
committed
Merge branch 'development'
2 parents 2f0a9ac + eb5edaf commit 3c173d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+31
-35380
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Async configuration for FastAPI and SQLModel
22

3-
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)
3+
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).
4+
5+
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).
6+
7+
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).
48

59
## Why Use This Template?
610

@@ -416,7 +420,6 @@ To begin experimenting with the basic chatbot, follow these steps:
416420
- [x] Add static code analysis using SonarQube
417421
- [x] Function return type annotations to declare the response_model (fastapi > 0.89.0)
418422
- [x] Add export report api in csv/xlsx files using StreamingResponse
419-
- [x] Add production deployment orchestation using terraform + Elastic Beanstalk - AWS
420423
- [x] Add Github actions automation for deploy on Elastic Beanstalk - AWS
421424
- [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)
422425
- [x] Add Enum sample column
@@ -437,11 +440,12 @@ To begin experimenting with the basic chatbot, follow these steps:
437440
- [ ] Add AuthZ using oso
438441
- [ ] Add SSL to reverse proxy on prod
439442
- [ ] Add instructions on doc for production deployment using github actions and dockerhub (CI/CD)
443+
- [ ] Add production deployment orchestation using terraform + Elastic Beanstalk - AWS
440444
- [ ] Convert repo into template using cookiecutter
441445

442446
### Support and Maintenance
443447

444-
`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).
448+
`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).
445449

446450

447451
PR are welcome ❤️

backend/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim-2022-11-25
1+
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
22
ENV PYTHONUNBUFFERED=1
3+
ENV PIP_DEFAULT_TIMEOUT=100
34
WORKDIR /code
45
# Install Poetry
56
RUN apt clean && apt update && apt install curl -y
@@ -13,7 +14,7 @@ COPY app/pyproject.toml app/poetry.lock* /code/
1314

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

1819
ENV PYTHONPATH=/code
1920
EXPOSE 8000

backend/app/app/db/session.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from app.core.config import ModeEnum, settings
44
from sqlalchemy.ext.asyncio import create_async_engine
55
from sqlmodel.ext.asyncio.session import AsyncSession
6-
from sqlalchemy.pool import NullPool, QueuePool
6+
from sqlalchemy.pool import NullPool, AsyncAdaptedQueuePool
77

88
DB_POOL_SIZE = 83
99
WEB_CONCURRENCY = 9
@@ -14,12 +14,11 @@
1414
engine = create_async_engine(
1515
str(settings.ASYNC_DATABASE_URI),
1616
echo=False,
17-
future=True,
18-
# pool_size=POOL_SIZE,
19-
# max_overflow=64,
2017
poolclass=NullPool
2118
if settings.MODE == ModeEnum.testing
22-
else QueuePool, # Asincio pytest works with NullPool
19+
else AsyncAdaptedQueuePool, # Asincio pytest works with NullPool
20+
# pool_size=POOL_SIZE,
21+
# max_overflow=64,
2322
)
2423

2524
SessionLocal = sessionmaker(
@@ -32,8 +31,10 @@
3231

3332
engine_celery = create_async_engine(
3433
str(settings.ASYNC_CELERY_BEAT_DATABASE_URI),
35-
# echo=True,
36-
future=True,
34+
echo=False,
35+
poolclass=NullPool
36+
if settings.MODE == ModeEnum.testing
37+
else AsyncAdaptedQueuePool, # Asincio pytest works with NullPool
3738
# pool_size=POOL_SIZE,
3839
# max_overflow=64,
3940
)

backend/app/app/main.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from jwt import DecodeError, ExpiredSignatureError, MissingRequiredClaimError
2121
from langchain.chat_models import ChatOpenAI
2222
from langchain.schema import HumanMessage
23-
from sqlalchemy.pool import NullPool, QueuePool
23+
from sqlalchemy.pool import NullPool, AsyncAdaptedQueuePool
2424
from starlette.middleware.cors import CORSMiddleware
2525
from transformers import pipeline
2626

@@ -117,12 +117,12 @@ async def lifespan(app: FastAPI):
117117
db_url=str(settings.ASYNC_DATABASE_URI),
118118
engine_args={
119119
"echo": False,
120+
"poolclass": NullPool
121+
if settings.MODE == ModeEnum.testing
122+
else AsyncAdaptedQueuePool
120123
# "pool_pre_ping": True,
121124
# "pool_size": settings.POOL_SIZE,
122125
# "max_overflow": 64,
123-
"poolclass": NullPool
124-
if settings.MODE == ModeEnum.testing
125-
else QueuePool, # Asincio pytest works with NullPool
126126
},
127127
)
128128
app.add_middleware(GlobalsMiddleware)

0 commit comments

Comments
 (0)