@ezyang Maybe look at SQLAlchemy for inspiration?