One of the several places I have my genealogy data is in gramps (see http://gramps-project.org/), an open source program written in python (a very easy to learn computer language for those interested). I have written several programs of my own playing with my data, starting with either gedcom or csv exported from either gramps or one of the other programs I use (eg myheritage). Gramps uses a more pythonic data model (eg people are python objects - see http://www.gramps-project.org/docs/gen/gen_lib.html#module-gen.lib.person). Is there a file somewhere that has this data in it then I can just copy and use in other programs? Or is there an easy way to extract the data in it's native python format?

I have tried to figure this out by reading the source but I don't understand the overall design well enough to find the hook I'm looking for. I'm hoping someone more familiar with gramps can point me in the right direction.

I've looked at the db api, but did not understand well enough so I (erroneously now that I've read the answers to this questions) thought that it would not be applicable.

  • 2
    +1 I did not know that Gramps was written in Python - it just became a lot more interesting :-)
    – PolyGeo
    Commented Oct 16, 2012 at 0:23
  • @PolyGeo - It's been great for me, except for performance on large-ish data sets. (E.g. full-database analysis on 10s of thousands of individuals.) :(
    – bstpierre
    Commented Oct 16, 2012 at 12:20
  • 1
    @bstpierre - Have you seen the Gramps wiki page called "Tips for large databases" gramps-project.org/wiki/…
    – Sam
    Commented Oct 18, 2012 at 3:42

4 Answers 4


This simple program will print out the internal representation for each person in your database. Doing something interesting is left as an exercise for the reader...


import DbState
import gen.db.read as read
from gen.db import DbBsddb
from gen.lib import Person

def callback(value):

dbclass = DbBsddb
dbstate = DbState.DbState()
dbstate.db.load('/home/brian/.gramps/grampsdb/4fcdfec9/', callback, 'r')

for handle, person in dbstate.db.get_person_cursor():
    p = Person(person)
    name = p.get_primary_name()
    print name.get_name()

See also /usr/share/gramps/cli/grampscli.py in your distribution, which is where I looked when I cobbled together the code above.

  • 2
    @Duncan: I just revised it to show the creation of a Person object from the raw data in the person cursor.
    – bstpierre
    Commented Oct 16, 2012 at 13:27
  • As of 2015 and gramps 4.2.1, the above script does not seem to function any longer, bstpierre, would you be so kind as to update if possible? Would be awesome! Thank you very much in advance!
    – Til Hund
    Commented Dec 26, 2015 at 15:41

Surely, you do need not be reminded that GEDCOM is useful, that if your chart app reads GEDCOM, it is not restricted to Gramps. You are specifically interested in getting Gramps data in its Python format, for easy processing by your own Python apps.

Gramps is Open Source, so the quick & easy answer is the RTSL: Read the Source, Luke. Once you've figured out how Gramps does it, you may be able to adapt that code to your use.

There are a few things worth pointing out in addition to that obvious advice:

  1. Gramps supports plug-ins. Turning your app into a Gramps plug-in might well be the easiest way to get direct access to the internal data model.
  2. Gramps features fan charts already. Looking through that code may be particularly helpful in figuring out how to do it the Gramps way.
  3. Others Gramps developers had to learn about how it all works too. Contacting them may help you get up to speed.
  4. ...but you should probably start by reading the Gramps Developer Portal section of the Gramps Wiki, particularly Using database API. There is helpful information about the relation between Python objects and the database there.

On a final note, Gramps blog posts have revealed that Gramps 4.0 will include a much-improved fan chart.

  • Oops. I guess I was wrong. As shown in the other answer, it is the db api that pulls them in native format. I apologize.
    – Duncan
    Commented Oct 16, 2012 at 13:23
  • Yes, I noticed that, so thought I would direct you to the database API documentation, which you seemed to have missed. Don't you just love getting a correct answer to a wrong question? ;-) Commented Oct 16, 2012 at 14:05
  • Point#4 answers the question. Why obscure that answer with all the other stuff?
    – Tom Morris
    Commented Oct 16, 2012 at 15:09
  • 1
    @TomMorris, point 4 answers part of the question. Commented Oct 16, 2012 at 16:26

GRAMPS uses the Berkeley database as its native format.

Over at Stack Overflow was the question Examining Berkeley DB files from the CLI from someone who wanted to view the contents without having to write scripts.

A couple of answers included the db-utils package and the db_hotbackup utility.

  • 1
    This would be a hard way to go, because there is no schema, in database parlance. In other words, you could get at the data, but you wouldn't know what it was. The Python interface decodes that for you.
    – Doug Blank
    Commented Jan 30, 2013 at 1:34

Here's my solution that works on Ubuntu 15.04 using python3.

import sys, os

# Add the home directory to sys.path

from gramps.gen.dbstate import DbState
from gramps.gen.db import DbBsddb
import gramps.gen.db.read as read
from gramps.gen.lib import Person

def callback(value):

dbclass = DbBsddb
dbstate = DbState()
dbstate.db.load('/home/arwillis/.gramps/grampsdb/5738def6/', callback, 'r')

for handle, person in dbstate.db.get_person_cursor():
    p = Person(person)
    name = p.get_primary_name()

  • I follow this, but since people on this site are not as used to just code segments can you also accompany it with some brief English explanation at the top.
    – CRSouser
    Commented Jun 1, 2016 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.