class documentation

class Bundle(ORMColumnsClauseRole, SupportsCloneAnnotations, sql_base.MemoizedHasCacheKey, InspectionAttr):

Known subclasses: sqlalchemy.orm.properties.CompositeProperty.CompositeBundle

View In Hierarchy

A grouping of SQL expressions that are returned by a .Query under one namespace.

The .Bundle essentially allows nesting of the tuple-based results returned by a column-oriented _query.Query object. It also is extensible via simple subclassing, where the primary capability to override is that of how the set of expressions should be returned, allowing post-processing as well as custom return types, without involving ORM identity-mapped classes.

New in version 0.9.0.

See Also

:ref:`bundles`

Method __clause​_element__ Undocumented
Method __init__ Construct a new .Bundle.
Method ​_clone Undocumented
Method ​_gen​_cache​_key return an optional cache key.
Method create​_row​_processor Produce the "row processing" function for this .Bundle.
Method label Provide a copy of this .Bundle passing a new label.
Class Variable ​_propagate​_attrs Undocumented
Class Variable is​_aliased​_class True if this object is an instance of .AliasedClass.
Class Variable is​_bundle True if this object is an instance of .Bundle.
Class Variable is​_clause​_element True if this object is an instance of _expression.ClauseElement.
Class Variable is​_mapper True if this object is an instance of _orm.Mapper.
Instance Variable ​_label Undocumented
Instance Variable c An alias for .Bundle.columns.
Instance Variable columns A namespace of SQL expressions referred to by this .Bundle.
Instance Variable exprs Undocumented
Instance Variable name Undocumented
Instance Variable single​_entity If True, queries for a single Bundle will be returned as a single entity, rather than an element within a keyed tuple.
Property clauses Undocumented
Property entity Undocumented
Property entity​_namespace Undocumented
Property mapper Undocumented

Inherited from ORMColumnsClauseRole:

Class Variable ​_role​_name Undocumented

Inherited from ColumnsClauseRole (via ORMColumnsClauseRole):

Property ​_select​_iterable Undocumented

Inherited from AllowsLambdaRole (via ORMColumnsClauseRole, ColumnsClauseRole):

Class Variable allows​_lambda Undocumented

Inherited from UsesInspection (via ORMColumnsClauseRole, ColumnsClauseRole):

Class Variable ​_post​_inspect Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SQLRole (via ORMColumnsClauseRole, ColumnsClauseRole, ColumnListRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SupportsCloneAnnotations:

Method ​_annotate return a copy of this ClauseElement with annotations updated by the given dictionary.
Method ​_deannotate return a copy of this _expression.ClauseElement with annotations removed.
Method ​_with​_annotations return a copy of this ClauseElement with annotations replaced by the given dictionary.
Class Variable ​_clone​_annotations​_traverse​_internals Undocumented

Inherited from SupportsAnnotations (via SupportsCloneAnnotations):

Property ​_annotations​_cache​_key Undocumented

Inherited from MemoizedHasCacheKey:

Method ​_generate​_cache​_key return a cache key.

Inherited from HasCacheKey (via MemoizedHasCacheKey):

Class Variable inherit​_cache Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.
Class Method ​_generate​_cache​_attrs generate cache key dispatcher for a new class.
Class Method ​_generate​_cache​_key​_for​_object Undocumented
Class Variable __slots__ Undocumented
Class Variable ​_hierarchy​_supports​_caching private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses.
Class Variable ​_is​_has​_cache​_key Undocumented

Inherited from InspectionAttr:

Class Variable __slots__ Undocumented
Class Variable ​_is​_internal​_proxy True if this object is an internal proxy object.
Class Variable is​_attribute True if this object is a Python :term:`descriptor`.
Class Variable is​_instance True if this object is an instance of .InstanceState.
Class Variable is​_property True if this object is an instance of .MapperProperty.
Class Variable is​_selectable Return True if this object is an instance of _expression.Selectable.
def __clause_element__(self):

Undocumented

def __init__(self, name, *exprs, **kw):

Construct a new .Bundle.

e.g.:

bn = Bundle("mybundle", MyClass.x, MyClass.y)

for row in session.query(bn).filter(
        bn.c.x == 5).filter(bn.c.y == 4):
    print(row.mybundle.x, row.mybundle.y)
Parameters
namename of the bundle.
*exprscolumns or SQL expressions comprising the bundle.
**kwUndocumented
single_entity=​Falseif True, rows for this .Bundle can be returned as a "single entity" outside of any enclosing tuple in the same manner as a mapped entity.
def _clone(self):

Undocumented

def _gen_cache_key(self, anon_map, bindparams):

return an optional cache key.

The cache key is a tuple which can contain any series of objects that are hashable and also identifies this object uniquely within the presence of a larger SQL expression or statement, for the purposes of caching the resulting query.

The cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key.

If a structure cannot produce a useful cache key, the NO_CACHE symbol should be added to the anon_map and the method should return None.

def create_row_processor(self, query, procs, labels):

Produce the "row processing" function for this .Bundle.

May be overridden by subclasses.

See Also

:ref:`bundles` - includes an example of subclassing.

def label(self, name):
Provide a copy of this .Bundle passing a new label.
_propagate_attrs =

Undocumented

is_aliased_class: bool =
True if this object is an instance of .AliasedClass.
is_bundle: bool =
True if this object is an instance of .Bundle.
is_clause_element: bool =
True if this object is an instance of _expression.ClauseElement.
is_mapper: bool =
True if this object is an instance of _orm.Mapper.
_label =

Undocumented

c =
An alias for .Bundle.columns.
columns =

A namespace of SQL expressions referred to by this .Bundle.

e.g.:

bn = Bundle("mybundle", MyClass.x, MyClass.y)

q = sess.query(bn).filter(bn.c.x == 5)

Nesting of bundles is also supported:

b1 = Bundle("b1",
        Bundle('b2', MyClass.a, MyClass.b),
        Bundle('b3', MyClass.x, MyClass.y)
    )

q = sess.query(b1).filter(
    b1.c.b2.c.a == 5).filter(b1.c.b3.c.y == 9)

See Also

.Bundle.c

exprs =

Undocumented

name =

Undocumented

single_entity =
If True, queries for a single Bundle will be returned as a single entity, rather than an element within a keyed tuple.
@property
clauses =

Undocumented

@property
entity =

Undocumented

@property
entity_namespace =

Undocumented

@property
mapper =

Undocumented