gino.bakery module

class gino.bakery.BakedQuery(elem, metadata, hash_=None)

Bases: gino.api.GinoExecutor

Represents a pre-compiled and possibly prepared query for faster execution.

BakedQuery is created by Bakery.bake(), and can be executed by GinoEngine or GinoConnection. If there is a proper bind in the baked query, contextual execution APIs inherited from GinoExecutor can also be used.

New in version 1.1.

property bind

Internal API to provide a proper bind if found.

property compiled_sql

Internal API to get the SQLAlchemy compiled sql context.


Set execution options on a shadow query of this baked query.

The execution options set in this method won’t affect the execution options in the baked query.

Read execution_options() for more information.


options – Multiple execution options.


A shadow of the baked query with new execution options but still functions as a baked query.


Internal API to get the compiled_sql.


_ – Ignored.

property query

Internal API to get the query instance before compilation.

property sql

Internal API to get the compiled raw SQL.

class gino.bakery.Bakery

Bases: object

Factory and warehouse of baked queries.

You may provide a bakery to a GinoEngine during creation as the bakery keyword argument, and the engine will bake the queries and create corresponding prepared statements for each of the connections in the pool.

A Gino instance has a built-in bakery, it’s automatically given to the engine during set_bind() or with_bind().

New in version 1.1.

bake(func_or_elem=None, **execution_options)

Bake a query.

You can bake raw SQL strings or SQLAlchemy Core query instances. This method adds the given query into a queue in the bakery, and bakes it only when the bakery is set to an GinoEngine from which the bakery could learn about the SQL dialect and compile the queries into SQL. Once done, the bakery is “closed”, you can neither give it to another engine, nor use it to bake more queries.

  • func_or_elem – A str or a SQLAlchemy Core query instance, or a function that returns such results.

  • execution_options – Shortcut to add SQLAlchemy execution options to the query.


A BakedQuery instance.


alias of gino.bakery.BakedQuery