When I started using Gramps (older versions 3 & 4) for my family tree, I chose to use the Title field to store their occupation information. Gramps since version 5 offers the capability to print the last occupation event in the relationship graph so I decided to migrate my existing data to a proper occupation event. As I have 900+ persons in my family tree, I would like to automate the process. Here is how I plan to do things:

  1. query the persons database to get the title field data as well as the person id
  2. process this data to a nice input file (I need to reformat the title information as sometimes I recorded several jobs at once)
  3. create occupation events from my input file

I am familiar with python and programming in general but I don't know how to interact with Gramps files. Are there example code or documentation I could use to understand how data is organised?

Better ideas accepted.

EDIT Note : I am currently using v5.0.1

After some research, I know how to do the step 1 above: by using the export menu I can generate a csv where I can find the title and the person id straigth-away. Step 2 is just me cleaning the data so that's ok. However for step 3, I am stuck. It looks like I could use the import feature if I was able to generate an xml file in the same format as Gramps. The problem is that Gramps expects something like this:

<person handle="_cd284dd52627d55ab80" change="1554508105" id="I0010">
  <eventref hlink="_e235f0096da3481aebdc5bf0138" role="Primary"/>
<event handle="_e235f0096da3481aebdc5bf0138" change="1554508051" id="E1346">
  <dateval val="1892"/>

And I have no clue on how to generate the handle, change and hlink values so that they don't break Gramps database. I also don't know what happens if I import partial information, does it break the other data?

  • 1
    For the sake of clarity for readers in the future, please add to your question exactly which version of Gramps 5 you have installed. If the Gramps Wiki: gramps-project.org/wiki/index.php and the Wikipedia article: en.wikipedia.org/wiki/Gramps did not have enough information to answer your question, please let us know why. If you solve the problem, feel free to post a self-answer. Thanks.
    – Jan Murphy
    Commented Apr 6, 2019 at 21:10

1 Answer 1


You could find examples of GRAMP xml files here : https://github.com/gramps-project/gramps/blob/maintenance/gramps50/example/gramps/example.gramps

For details about handle, hlink, etc. They have a great wiki. In particular, for the handle (time+random number used to identify event), you can look here: https://www.gramps-project.org/wiki/index.php/Using_database_API#Handles

P.S.: In particular, I would start looking here https://www.gramps-project.org/wiki/index.php?title=Using_database_API

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.