Skip to main content

SQLAlchemy >= 1.4 support for aiohttp.

Project description

SQLAlchemy >= 1.4 support for aiohttp.

Install

pip install aiohttp-sqlalchemy

Example

Install aiosqlite for work with sqlite3:

pip install aiosqlite

Run this code:

from aiohttp import web
import aiohttp_sqlalchemy
from aiohttp_sqlalchemy import sa_engine, sa_middleware
from datetime import datetime
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.ext.asyncio import create_async_engine


metadata = sa.MetaData()
Base = orm.declarative_base(metadata=metadata)


class Request(Base):
    __tablename__ = 'requests'
    id = sa.Column(sa.Integer, primary_key=True)
    timestamp = sa.Column(sa.DateTime(), default=datetime.now)


async def main(request):
    async with request.app['sa_main'].begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

    async with request['sa_main'].begin():
        request['sa_main'].add_all([Request()])
        result = await request['sa_main'].execute(sa.select(Request))
        data = {r.id: r.timestamp.isoformat() for r in result.scalars()}
        return web.json_response(data)


app = web.Application(middlewares=[sa_middleware()])
engine = create_async_engine('sqlite+aiosqlite:///')
aiohttp_sqlalchemy.setup(app, [sa_engine(engine)])
app.add_routes([web.get('/', main)])
web.run_app(app)

Documentation

See: https://aiohttp-sqlalchemy.readthedocs.io/

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-sqlalchemy-0.1b1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_sqlalchemy-0.1b1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-sqlalchemy-0.1b1.tar.gz.

File metadata

  • Download URL: aiohttp-sqlalchemy-0.1b1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.4.0-70-generic

File hashes

Hashes for aiohttp-sqlalchemy-0.1b1.tar.gz
Algorithm Hash digest
SHA256 b72e537823e302eab174d1a6b4bed7dc8b4e6c8cf19c031ff995b6d12e007e74
MD5 140ecc49a89241b688e69504609ead0f
BLAKE2b-256 be3449d5f66db1f1023e14ec1cfab757a0c2b1b64bde412fea140ccfece4e815

See more details on using hashes here.

File details

Details for the file aiohttp_sqlalchemy-0.1b1-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_sqlalchemy-0.1b1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.4.0-70-generic

File hashes

Hashes for aiohttp_sqlalchemy-0.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b05e3940f034a68af61101d4e1d6ef4d57e0d38d44ac6bcc4e960d6e4c9d4cc
MD5 4c640fccddec82df6523008748002549
BLAKE2b-256 03494612cffa0f39be99eeff891a3071a1ce9157d337cc3c081814d90970a305

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page