def child_count_ex(self, stime, etime):
    return len([_child for _child in self.children if stime <= _child.time <=
        etime])

@child_count_ex.expression
def child_count_ex(cls, stime, etime):
    return select([func.count(Child.child_id)]).where(Child.parent_id ==
        cls.parent_id).where(Child.time >= stime).where(Child.time <= etime
        ).label('child_count')
stime, etime = datetime.datetime(2012, 1, 1), datetime.datetime(2012, 1, 31)
qry = session.query(Parent)
qry = qry.filter(Parent.child_count_ex(stime, etime) > 0)
SQLAlchemy — Написание гибридного метода для подсчета дочерних элементов