Python 3.9 is now generally available.

google.appengine.ext.ndb.in_transaction

Return whether a transaction is currently active.