Python SQLAlchemy Query: AttributeError: 'Connection' object has no attribute 'contextual_connect'

You must bind the session to a SQLAlchemy engine, not directly to a MySQLDb connection object.

engine = create_engine("mysql://user:password@host/dbname")
Session.configure(bind=engine)

(You can remove your db1 variable.)

From the tutorial:

The return value of create_engine() is an instance of Engine, and it represents the core interface to the database, adapted through a dialect that handles the details of the database and DBAPI in use.

See also https://docs.sqlalchemy.org/en/latest/orm/tutorial.html