'Construct a ShardedSession.
:param shard_chooser: A callable which, passed a Mapper, a mapped
instance, and possibly a SQL clause, returns a shard ID.  This id
may be based off of the attributes present within the object, or on
some round-robin scheme. If the scheme is based on a selection, it
should set whatever state on the instance to mark it in the future as
participating in that shard.
:param id_chooser: A callable, passed a query and a tuple of identity
values, which should return a list of shard ids where the ID might
reside.  The databases will be queried in the order of this listing.
:param query_chooser: For a given Query, returns the list of shard_ids
where the query should be issued.  Results from all shards returned
will be combined together into a single listing.
:param shards: A dictionary of string shard names
to :class:`~sqlalchemy.engine.Engine` objects.'

def __init__(self, shard_chooser, id_chooser, query_chooser, shards=None, query_cls=ShardedQuery, **kwargs):

    super(ShardedSession, self).__init__(query_cls=query_cls, **kwargs)
    self.shard_chooser = shard_chooser
    self.id_chooser = id_chooser
    self.query_chooser = query_chooser
    self.__binds = {}
    self.connection_callable = self.connection
    if (shards is not None):
        for k in shards:
            self.bind_shard(k, shards[k])
