PublicQuery class from https://github.com/ods/sa_public_query combined.py