Skip to content

Repository files navigation

gino-quart

test

Introduction

An extension for GINO to support quart server.

Usage

The common usage looks like this:

fromquartimportQuartfromgino.ext.quartimportGinoapp=Quart()
db=Gino(app, **kwargs)

Configuration

GINO adds a before_request, after_request and before_first_request hook to the Quart app to setup and cleanup database according to the configurations that passed in the kwargs parameter.

The config includes:

NameDescriptionDefault
driverthe database driverasyncpg
hostdatabase server hostlocalhost
portdatabase server port5432
userdatabase server userpostgres
passworddatabase server passwordempty
databasedatabase namepostgres
dsna SQLAlchemy database URL to create the engine, its existence will replace all previous connect arguments.N/A
retry_timesthe retry times when database failed to connect20
retry_intervalthe interval in seconds between each time of retry5
pool_min_sizethe initial number of connections of the db pool.N/A
pool_max_sizethe maximum number of connections in the db pool.N/A
echoenable SQLAlchemy echo mode.N/A
sslSSL context passed to asyncpg.connectNone
use_connection_for_requestflag to set up lazy connection for requests.N/A
retry_limitthe number of retries to connect to the database on start up.1
retry_intervalseconds to wait between retries.1
kwargsother parameters passed to the specified dialects, like asyncpg. Unrecognized parameters will cause exceptions.N/A

Lazy Connection

If use_connection_for_request is set to be True, 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:

awaitrequest['connection'].release(permanent=False)

Contributing

You're welcome to contribute to this project. It's really appreciated. Please fork this project and create a pull request to the dev branch.

  • Dependency management is done via poetry
  • Pull request for new features must include the appropriate tests integrated in tests/test_gino_quart.py
  • You should format your code. Recommended is black

Older Quart Versions

gino-quart requires a quart version higher or equal to quart 0.15.1 after the 1.1.2 release. This is caused by multiple breaking changes with, amongst other things, exception handling. You can still use gino-quart0.1.1b5 for older Quart versions.

Attribution

The license holder of this extension is Tony Wang.

This project is an extension to GINO and part of the python-gino community.

About

An extension for GINO to support Quart server.

Topics

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages