The transaction set will open the RPM database as needed so in most case you will not need to explicitly open the database. The transaction set is the workhorse of RPM.
import rpm ts=rpm.TransactionSet()
As well as using macros to select the installation path that RPM will use. RPM will effectivel chroot to that path and use the default database, usually located in /var/lib/rpm within the chroot. This comes in useful with installers, etc.
import rpm # rpm.ts is an abbreviation for rpm.TransactionSet ts=rpm.ts("/mnt/sysimage")