gino.ext.aiohttp module

class gino.ext.aiohttp.AiohttpModelMixin[source]

Bases: object

classmethod coroutine get_or_404(*args, **kwargs)[source]
class gino.ext.aiohttp.AiohttpStrategy[source]

Bases: gino.strategies.GinoStrategy

engine_cls

alias of GinoEngine

name = 'aiohttp'
class gino.ext.aiohttp.Gino(bind=None, model_classes=None, query_ext=True, schema_ext=True, ext=True, **kwargs)[source]

Bases: gino.api.Gino

Support aiohttp.web server.

The common usage looks like this:

from aiohttp import web
from gino.ext.aiohttp import Gino

db = Gino()
app = web.Application(middlewares=[db])
db.init_app(app)

By init_app() GINO subscribes to a few signals on aiohttp, so that GINO could use database configuration to initialize the bound engine.

The configuration can be passed in the config parameter of init_app, or if that is not set, in app[‘config’][‘gino’], both of which should be a dictionary.

The config includes:

  • driver - the database driver, default is asyncpg.

  • host - database server host, default is localhost.

  • port - database server port, default is 5432.

  • user - database server user, default is postgres.

  • password - database server password, default is empty.

  • database - database name, default is postgres.

  • dsn - a SQLAlchemy database URL to create the engine, its existence will replace all previous connect arguments.

  • pool_min_size - the initial number of connections of the db pool.

  • pool_max_size - the maximum number of connections in the db pool.

  • echo - enable SQLAlchemy echo mode.

  • ssl - SSL context passed to asyncpg.connect, default is None.

  • kwargs - other parameters passed to the specified dialects, like asyncpg. Unrecognized parameters will cause exceptions.

If the db is set as an aiohttp middleware, then a lazy connection is available at request['connection']. By default, a database connection is borrowed on the first query, shared in the same execution context, and returned to the pool on response. If you need to release the connection early in the middle to do some long-running tasks, you can simply do this:

await request['connection'].release(permanent=False)
Parameters
  • bind – A GinoEngine instance to bind. Also accepts string or URL, which will be passed to create_engine() when this Gino instance is awaited. Default is None.

  • model_classes – A tuple of base class and mixin classes to create the Model class. Default is (CRUDModel, ).

  • query_ext – Boolean value to control the installation of the gino extension on Executable for implicit execution. Default is to install (True).

  • schema_ext – Boolean value to control the installation of the gino extension on SchemaItem for implicit execution. Default is to install (True).

  • ext – Boolean value to control the installation of the two gino extensions. False for no extension at all, while it depends on the two individual switches when this is set to True (default).

  • kwargs – Other arguments accepted by MetaData.

init_app(app, config=None, *, db_attr_name='db')[source]
model_base_classes = (<class 'gino.crud.CRUDModel'>, <class 'gino.ext.aiohttp.AiohttpModelMixin'>)
query_executor

alias of GinoExecutor

class gino.ext.aiohttp.GinoConnection(dialect, sa_conn, stack=None)[source]

Bases: gino.engine.GinoConnection

class gino.ext.aiohttp.GinoEngine(dialect, pool, loop, logging_name=None, echo=None, execution_options=None)[source]

Bases: gino.engine.GinoEngine

connection_cls

alias of GinoConnection

class gino.ext.aiohttp.GinoExecutor(query)[source]

Bases: gino.api.GinoExecutor