    def groups_for_user(username):
        """Get set of group names for a given username"""
        # if we need a group lookup, the result is not cacheable
        nonlocal needs_db
        needs_db = True
        group_query = (
            db.query(orm.Group.name)
            .join(orm.User.groups)
            .filter(orm.User.name == username)
        )
        return {row[0] for row in group_query}
Get set of group names for a given username
jupyterhub/scopes.py