# Rpmdb Class Reference
[PYTHON API.]

A python rpm.db object represents an RPM database. More...

## Detailed Description

A python rpm.db object represents an RPM database.

Instances of the rpmdb object provide access to the records of a RPM database. The records are accessed by index number. To retrieve the header data in the RPM database, the rpmdb object is subscripted as you would access members of a list.

The rpmdb class contains the following methods:

- firstkey() Returns the index of the first record in the database.
  Deprecated:
    Use mi = ts.dbMatch() (or db.match()) instead.
  - nextkey(index) Returns the index of the next record after "index" in the database.
  Parameters:

    | index | current rpmdb location

  Deprecated:
    Use hdr = mi.next() instead.
  - findbyfile(file) Returns a list of the indexes to records that own file "file".
  Parameters:

    | file | absolute path to file

  Deprecated:
    Use mi = ts.dbMatch('basename') instead.
  - findbyname(name) Returns a list of the indexes to records for packages named "name".
  Parameters:

    | name | package name

  Deprecated:
    Use mi = ts.dbMatch('name') instead.
  - findbyprovides(dep) Returns a list of the indexes to records for packages that provide "dep".
  Parameters:

    | dep | provided dependency string

  Deprecated:
    Use mi = ts.dbMmatch('providename') instead.
  To obtain a db object explicitly, the opendb function in the rpm module can be called. The opendb function takes two optional arguments. The first optional argument is a boolean flag that specifies if the database is to be opened for read/write access or read-only access. The second argument specifies an alternate root directory for RPM to use.

Note that in most cases, one is interested in querying the default database in /var/lib/rpm and an rpm.mi match iterator derived from an implicit open of the database from an rpm.ts transaction set object:

            import rpm
            ts = rpm.TransactionSet()
            mi = ts.dbMatch()
            ...

is simpler than explicitly opening a database object:

            import rpm
            db = rpm.opendb()
            mi = db.match()

An example of opening a database and retrieving the first header in the database, then printing the name of the package that the header represents:

            import rpm
            db = rpm.opendb()
            mi = db.match()
            if mi:
                h = mi.next()
                if h:
                    print h['name']

To print all of the packages in the database that match a package name, the code will look like this:

            import rpm
            db = rpm.opendb()
            mi = db.match('name', "foo")
            while mi:
                h = mi.next()
                if not h:
                    break
                print "%s-%s-%s" % (h['name'], h['version'], h['release'])

The documentation for this class was generated from the following file:

- python/rpmdb-py.c