Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade aiohttp #9348

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions frameworks/Python/aiohttp/aiohttp-pg-raw.dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM python:3.8
FROM python:3.13

ADD ./ /aiohttp

WORKDIR aiohttp

RUN pip3 install cython==0.29.23 && \
RUN pip3 install cython==3.0.11 && \
pip3 install -r /aiohttp/requirements.txt

ENV CONNECTION=RAW

EXPOSE 8080

CMD gunicorn app.gunicorn:app -c gunicorn_conf.py
CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py
6 changes: 3 additions & 3 deletions frameworks/Python/aiohttp/aiohttp.dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM python:3.8
FROM python:3.13

ADD ./ /aiohttp

WORKDIR aiohttp

RUN pip3 install cython==0.29.23 && \
RUN pip3 install cython==3.0.11 && \
pip3 install -r /aiohttp/requirements.txt

WORKDIR /aiohttp

EXPOSE 8080

CMD gunicorn app.gunicorn:app -c gunicorn_conf.py
CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py
11 changes: 6 additions & 5 deletions frameworks/Python/aiohttp/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import asyncpg
from aiohttp import web
from sqlalchemy.engine.url import URL
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine

from .views import (
json,
Expand Down Expand Up @@ -48,15 +47,17 @@ async def db_ctx(app: web.Application):
print(f'connection pool: min size: {min_size}, max size: {max_size}, orm: {CONNECTION_ORM}')
if CONNECTION_ORM:
dsn = pg_dsn('asyncpg')
engine = create_async_engine(dsn, future=True, pool_size=max_size)
app['db_session'] = sessionmaker(engine, class_=AsyncSession)
engine = create_async_engine(dsn, pool_size=max_size)
app['db_session'] = async_sessionmaker(engine)
else:
dsn = pg_dsn()
app['pg'] = await asyncpg.create_pool(dsn=dsn, min_size=min_size, max_size=max_size, loop=app.loop)

yield

if not CONNECTION_ORM:
if CONNECTION_ORM:
await app['db_session'].dispose()
else:
await app['pg'].close()


Expand Down
14 changes: 7 additions & 7 deletions frameworks/Python/aiohttp/app/models.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

Base = declarative_base()
class Base(DeclarativeBase):
"""Base for models."""


class World(Base):
__tablename__ = 'world'
id = Column(Integer, primary_key=True)
randomnumber = Column(Integer)
id: Mapped[int] = mapped_column(primary_key=True)
randomnumber: Mapped[int]

sa_worlds = World.__table__


class Fortune(Base):
__tablename__ = 'fortune'
id = Column(Integer, primary_key=True)
message = Column(String)
id: Mapped[int] = mapped_column(primary_key=True)
message: Mapped[str]

sa_fortunes = Fortune.__table__
17 changes: 8 additions & 9 deletions frameworks/Python/aiohttp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
aiohttp==3.10.2
asyncpg==0.25.0
cchardet==2.1.7
gunicorn==20.1
jinja2==3.1.4
psycopg2==2.9.2
SQLAlchemy==1.4.29
ujson==5.4.0
uvloop==0.16
aiohttp==3.11.11
asyncpg==0.30.0
gunicorn==23.0.0
jinja2==3.1.5
psycopg2==2.9.10
SQLAlchemy==2.0.37
ujson==5.10.0
uvloop==0.21.0
Loading