Module gedcom
A Python module for parsing, analyzing, and manipulating GEDCOM files.
Installation
The module can be installed via pipenv or simply pip.
Run pip3 install python-gedcom
to install or pip3 install python-gedcom --upgrade
to upgrade to the newest version uploaded to the PyPI repository.
Tip
Using pipenv simplifies the installation and maintenance of dependencies.
Pre-releases
If you want to use the latest pre-release of the python-gedcom
package,
simply append the --pre
option to pip3
: pip3 install python-gedcom --pre
Important classes and modules
Parser
: The actual GEDCOM parser.gedcom.tags
: GEDCOM tags likeGEDCOM_TAG_INDIVIDUAL
(INDI
) orGEDCOM_TAG_NAME
(NAME
)gedcom.element
: Contains all relevant elements generated by aParser
.
Example usage
When successfully installed you may import the gedcom
package and use it like so:
from gedcom.element.individual import IndividualElement
from gedcom.parser import Parser
# Path to your ".ged" file
file_path = ''
# Initialize the parser
gedcom_parser = Parser()
# Parse your file
gedcom_parser.parse_file(file_path)
root_child_elements = gedcom_parser.get_root_child_elements()
# Iterate through all root child elements
for element in root_child_elements:
# Is the "element" an actual "IndividualElement"? (Allows usage of extra functions such as "surname_match" and "get_name".)
if isinstance(element, IndividualElement):
# Get all individuals whose surname matches "Doe"
if element.surname_match('Doe'):
# Unpack the name tuple
(first, last) = element.get_name()
# Print the first and last name of the found individual
print(first + " " + last)
Tip
Please have a look at the test files found in the
tests/
directory in the source code on GitHub.
Strict parsing
Large sites like Ancestry and MyHeritage (among others) don't always produce perfectly formatted GEDCOM files. If you encounter errors in parsing, you might consider disabling strict parsing which is enabled by default:
from gedcom.parser import Parser
file_path = '' # Path to your `.ged` file
gedcom_parser = Parser()
gedcom_parser.parse_file(file_path, False) # Disable strict parsing
Disabling strict parsing will allow the parser to gracefully handle the following quirks:
- Multi-line fields that don't use
CONC
orCONT
- Handle the last line not ending in a CRLF (
\r\n
)
License
Licensed under the GNU General Public License v2
Python GEDCOM Parser
Copyright (C) 2018 Damon Brodie (damon.brodie at gmail.com)
Copyright (C) 2018-2019 Nicklas Reincke (contact at reynke.com)
Copyright (C) 2016 Andreas Oberritter
Copyright (C) 2012 Madeleine Price Ball
Copyright (C) 2005 Daniel Zappala (zappala at cs.byu.edu)
Copyright (C) 2005 Brigham Young University
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Expand source code
# -*- coding: utf-8 -*-
# Python GEDCOM Parser
#
# Copyright (C) 2018 Damon Brodie (damon.brodie at gmail.com)
# Copyright (C) 2018-2019 Nicklas Reincke (contact at reynke.com)
# Copyright (C) 2016 Andreas Oberritter
# Copyright (C) 2012 Madeleine Price Ball
# Copyright (C) 2005 Daniel Zappala (zappala at cs.byu.edu)
# Copyright (C) 2005 Brigham Young University
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Further information about the license: http://www.gnu.org/licenses/gpl-2.0.html
"""
A Python module for parsing, analyzing, and manipulating GEDCOM files.
.. include:: ./gedcom.md
"""
__all__ = [
# Subpackages
"element",
# Modules
"helpers",
"parser",
"tags"
]
Sub-modules
gedcom.element
-
Module containing all relevant elements generated by a
Parser
. An element represents a line within GEDCOM data. gedcom.helpers
-
Helper methods.
gedcom.parser
-
Module containing the actual
Parser
used to generate elements - out of each line - which can in return be manipulated. gedcom.tags
-
GEDCOM tags.