Skip to content

Commit 5fad73e

Browse files
committed
Merge branch 'release/4.0.3'
2 parents 9e585d8 + 5c2b126 commit 5fad73e

File tree

8 files changed

+340
-300
lines changed

8 files changed

+340
-300
lines changed

fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ readme = "README.md"
1212

1313
[tool.poetry.dependencies]
1414
python = "^3.9"
15-
fastapi = "^0.85.0"
16-
uvicorn = { version = "^0.18.3", extras = ["standard"] }
17-
pydantic = {version = "^1.10.2", extras = ["dotenv"]}
18-
yarl = "^1.8.1"
19-
ujson = "^5.5.0"
15+
fastapi = "^0.89.1"
16+
uvicorn = { version = "^0.20.0", extras = ["standard"] }
17+
pydantic = {version = "^1.10.4", extras = ["dotenv"]}
18+
yarl = "^1.8.2"
19+
ujson = "^5.7.0"
2020
{%- if cookiecutter.orm == "piccolo" %}
2121
{%- if cookiecutter.db_info.name == "postgresql" %}
22-
piccolo = {version = "^0.91.0", extras = ["postgres"]}
22+
piccolo = {version = "^0.105.0", extras = ["postgres"]}
2323
{%- elif cookiecutter.db_info.name == "sqlite" %}
24-
piccolo = {version = "^0.91.0", extras = ["sqlite"]}
24+
piccolo = {version = "^0.105.0", extras = ["sqlite"]}
2525
{%- endif %}
2626
{%- endif %}
2727
{%- if cookiecutter.orm == "sqlalchemy" %}
28-
SQLAlchemy = {version = "^1.4.41", extras = ["mypy", "asyncio"]}
28+
SQLAlchemy = {version = "^2.0.0", extras = ["asyncio"]}
2929
{%- if cookiecutter.enable_migrations == "True" %}
30-
alembic = "^1.8.1"
30+
alembic = "^1.9.2"
3131
{%- endif %}
3232
{%- if cookiecutter.db_info.name == "postgresql" %}
33-
asyncpg = {version = "^0.26.0", extras = ["sa"]}
33+
asyncpg = {version = "^0.27.0", extras = ["sa"]}
3434
{%- elif cookiecutter.db_info.name == "sqlite" %}
35-
aiosqlite = "^0.17.0"
35+
aiosqlite = "^0.18.0"
3636
{%- elif cookiecutter.db_info.name == "mysql" %}
3737
aiomysql = "^0.1.1"
3838
mysqlclient = "^2.1.1"
@@ -44,52 +44,52 @@ tortoise-orm = "^0.19.2"
4444
aerich = "^0.7.1"
4545
{%- endif %}
4646
{%- if cookiecutter.db_info.name == "postgresql" %}
47-
asyncpg = "^0.26.0"
47+
asyncpg = "^0.27.0"
4848
{%- elif cookiecutter.db_info.name == "sqlite" %}
49-
aiosqlite = "^0.17.0"
49+
aiosqlite = "<0.18.0"
5050
{%- elif cookiecutter.db_info.name == "mysql" %}
5151
aiomysql = "^0.1.1"
5252
mysqlclient = "^2.1.1"
53-
cryptography = "^38.0.1"
53+
cryptography = "^39.0.0"
5454
{%- endif %}
5555
{%- endif %}
5656
{%- if cookiecutter.orm == "ormar" %}
57-
ormar = "^0.11.3"
57+
ormar = "^0.12.0"
5858
{%- if cookiecutter.enable_migrations == "True" %}
59-
alembic = "^1.8.1"
59+
alembic = "^1.9.2"
6060
{%- endif %}
6161
{%- if cookiecutter.db_info.name == "postgresql" %}
62-
asyncpg = "^0.26.0"
63-
psycopg2-binary = "^2.9.3"
62+
asyncpg = "^0.27.0"
63+
psycopg2-binary = "^2.9.5"
6464
{%- elif cookiecutter.db_info.name == "sqlite" %}
65-
aiosqlite = "^0.17.0"
65+
aiosqlite = "^0.18.0"
6666
{%- elif cookiecutter.db_info.name == "mysql" %}
6767
aiomysql = "^0.1.1"
6868
mysqlclient = "^2.1.1"
6969
{%- endif %}
7070
{%- endif %}
7171
{%- if cookiecutter.enable_redis == "True" %}
72-
redis = {version = "^4.3.4", extras = ["hiredis"]}
72+
redis = {version = "^4.4.2", extras = ["hiredis"]}
7373
{%- endif %}
7474
{%- if cookiecutter.self_hosted_swagger == 'True' %}
7575
aiofiles = "^22.1.0"
7676
{%- endif %}
7777
{%- if cookiecutter.orm == "psycopg" %}
78-
psycopg = { version = "^3.1.2", extras = ["binary", "pool"] }
78+
psycopg = { version = "^3.1.8", extras = ["binary", "pool"] }
7979
{%- endif %}
8080
httptools = "^0.5.0"
8181
{%- if cookiecutter.api_type == "graphql" %}
82-
strawberry-graphql = { version = "^0.133.2", extras = ["fastapi"] }
82+
strawberry-graphql = { version = "^0.155.2", extras = ["fastapi"] }
8383
{%- endif %}
8484
{%- if cookiecutter.enable_rmq == "True" %}
85-
aio-pika = "^8.2.3"
85+
aio-pika = "^8.3.0"
8686
{%- endif %}
8787
{%- if cookiecutter.prometheus_enabled == "True" %}
88-
prometheus-client = "^0.14.1"
88+
prometheus-client = "^0.16.0"
8989
prometheus-fastapi-instrumentator = "5.9.1"
9090
{%- endif %}
9191
{%- if cookiecutter.sentry_enabled == "True" %}
92-
sentry-sdk = "^1.9.9"
92+
sentry-sdk = "^1.14.0"
9393
{%- endif %}
9494
{%- if cookiecutter.otlp_enabled == "True" %}
9595
opentelemetry-api = "^1.15.0"
@@ -117,32 +117,29 @@ opentelemetry-instrumentation-aio-pika = "^0.36b0"
117117
loguru = "^0.6.0"
118118
{%- endif %}
119119
{%- if cookiecutter.enable_kafka == "True" %}
120-
aiokafka = "^0.7.2"
120+
aiokafka = "^0.8.0"
121121
{%- endif %}
122122

123123
[tool.poetry.dev-dependencies]
124-
pytest = "^7.1.3"
124+
pytest = "^7.2.1"
125125
flake8 = "~4.0.1"
126-
mypy = "^0.981"
127-
isort = "^5.10.1"
128-
pre-commit = "^2.20.0"
126+
mypy = "^0.991"
127+
isort = "^5.11.4"
128+
pre-commit = "^3.0.1"
129129
wemake-python-styleguide = "^0.17.0"
130-
black = "^22.8.0"
130+
black = "^22.12.0"
131131
autoflake = "^1.6.1"
132-
{%- if cookiecutter.orm == "sqlalchemy" %}
133-
SQLAlchemy = {version = "^1.4.41", extras = ["mypy"]}
134-
{%- endif %}
135132
pytest-cov = "^4.0.0"
136-
anyio = "^3.6.1"
137-
pytest-env = "^0.6.2"
133+
anyio = "^3.6.2"
134+
pytest-env = "^0.8.1"
138135
{%- if cookiecutter.enable_redis == "True" %}
139-
fakeredis = "^2.2.0"
136+
fakeredis = "^2.5.0"
140137
{%- endif %}
141138
{%- if cookiecutter.orm == "tortoise" %}
142139
asynctest = "^0.13.0"
143140
nest-asyncio = "^1.5.6"
144141
{%- endif %}
145-
httpx = "^0.23.0"
142+
httpx = "^0.23.3"
146143

147144
[tool.isort]
148145
profile = "black"
@@ -161,9 +158,6 @@ allow_untyped_decorators = true
161158
warn_unused_ignores = false
162159
warn_return_any = false
163160
namespace_packages = true
164-
{%- if cookiecutter.orm == "sqlalchemy" %}
165-
plugins = ["sqlalchemy.ext.mypy.plugin"]
166-
{%- endif %}
167161

168162
{%- if cookiecutter.enable_redis == "True" %}
169163

fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535

3636
{%- if cookiecutter.orm == "sqlalchemy" %}
37-
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, AsyncEngine, AsyncConnection
38-
from sqlalchemy.orm import sessionmaker
37+
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, AsyncEngine, AsyncConnection, async_sessionmaker
3938
from {{cookiecutter.project_name}}.db.dependencies import get_db_session
4039
from {{cookiecutter.project_name}}.db.utils import create_database, drop_database
4140
{%- elif cookiecutter.orm == "tortoise" %}
@@ -114,8 +113,9 @@ async def dbsession(
114113
connection = await _engine.connect()
115114
trans = await connection.begin()
116115

117-
session_maker = sessionmaker(
118-
connection, expire_on_commit=False, class_=AsyncSession,
116+
session_maker = async_sessionmaker(
117+
connection,
118+
expire_on_commit=False,
119119
)
120120
session = session_maker()
121121

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
from typing import Any, Tuple
2-
3-
from sqlalchemy import Table
4-
from sqlalchemy.orm import as_declarative
1+
from sqlalchemy.orm import DeclarativeBase
52

63
from {{cookiecutter.project_name}}.db.meta import meta
74

85

9-
@as_declarative(metadata=meta)
10-
class Base:
11-
"""
12-
Base for all models.
6+
class Base(DeclarativeBase):
7+
"""Base for all models."""
138

14-
It has some type definitions to
15-
enhance autocompletion.
16-
"""
9+
metadata = meta
1710

18-
__tablename__: str
19-
__table__: Table
20-
__table_args__: Tuple[Any, ...]

fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/dao/dummy_dao.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def get_all_dummies(self, limit: int, offset: int) -> List[DummyModel]:
3333
select(DummyModel).limit(limit).offset(offset),
3434
)
3535

36-
return raw_dummies.scalars().fetchall()
36+
return list(raw_dummies.scalars().fetchall())
3737

3838
async def filter(
3939
self,
@@ -49,4 +49,4 @@ async def filter(
4949
if name:
5050
query = query.where(DummyModel.name == name)
5151
rows = await self.session.execute(query)
52-
return rows.scalars().fetchall()
52+
return list(rows.scalars().fetchall())
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from sqlalchemy.sql.schema import Column
2-
from sqlalchemy.sql.sqltypes import Integer, String
1+
from sqlalchemy.orm import Mapped, mapped_column
2+
from sqlalchemy.sql.sqltypes import String
33

44
from {{cookiecutter.project_name}}.db.base import Base
55

@@ -9,5 +9,5 @@ class DummyModel(Base):
99

1010
__tablename__ = "dummy_model"
1111

12-
id = Column(Integer(), primary_key=True, autoincrement=True)
13-
name = Column(String(length=200)) # noqa: WPS432
12+
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
13+
name: Mapped[str] = mapped_column(String(length=200)) # noqa: WPS432

fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/lifetime.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ async def _setup_db(app: FastAPI) -> None:
7979
{%- if cookiecutter.orm == "sqlalchemy" %}
8080
from asyncio import current_task
8181
from sqlalchemy.ext.asyncio import (
82-
AsyncSession,
8382
async_scoped_session,
8483
create_async_engine,
84+
async_sessionmaker,
8585
)
8686
from sqlalchemy.orm import sessionmaker
8787

@@ -103,10 +103,9 @@ def _setup_db(app: FastAPI) -> None: # pragma: no cover
103103
"""
104104
engine = create_async_engine(str(settings.db_url), echo=settings.db_echo)
105105
session_factory = async_scoped_session(
106-
sessionmaker(
106+
async_sessionmaker(
107107
engine,
108108
expire_on_commit=False,
109-
class_=AsyncSession,
110109
),
111110
scopefunc=current_task,
112111
)

0 commit comments

Comments
 (0)