Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 9 additions & 7 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 All @@ -28,14 +27,15 @@ def pg_dsn(dialect=None) -> str:
"""
:return: DSN url suitable for sqlalchemy and aiopg.
"""
return str(URL.create(
url = URL.create(
database='hello_world',
password=os.getenv('PGPASS', 'benchmarkdbpass'),
host='tfb-database',
port='5432',
username=os.getenv('PGUSER', 'benchmarkdbuser'),
drivername='postgresql+{}'.format(dialect) if dialect else 'postgresql',
))
)
return url.render_as_string(hide_password=False)


async def db_ctx(app: web.Application):
Expand All @@ -48,15 +48,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.14
asyncpg==0.30.0
gunicorn==23.0.0
jinja2==3.1.5
psycopg2==2.9.10
SQLAlchemy==2.0.39
ujson==5.10.0
uvloop==0.21.0
Loading