Package: python-gedcom
Python GEDCOM ParserA Python module for parsing, analyzing, and manipulating GEDCOM files.GEDCOM files contain ancestry data. The parser is currently supporting
the GEDCOM 5.5 format which is detailedhere.For the latest changes please have a look at theCHANGELOG.mdfile.The current development process can be tracked in thedevelop branch.InstallationThe module can be installed viapip.Runpip<version> install python-gedcomto install orpip<version> install python-gedcom --upgradeto upgrade to the newest version uploaded to thePyPI repository.If you want to use the latest pre-release of thepython-gedcompackage,
simply append the--preoption topip:pip<version> install python-gedcom --preExample usageFor more examples:Please have a look at the test files found in thetests/directory.When successfully installed you may import thegedcompackage and use it like so:fromgedcom.element.individualimportIndividualElementfromgedcom.parserimportParser# Path to your `.ged` filefile_path=''# Initialize the parsergedcom_parser=Parser()# Parse your filegedcom_parser.parse_file(file_path)root_child_elements=gedcom_parser.get_root_child_elements()# Iterate through all root child elementsforelementinroot_child_elements:# Is the `element` an actual `IndividualElement`? (Allows usage of extra functions such as `surname_match` and `get_name`.)ifisinstance(element,IndividualElement):# Get all individuals whose surname matches "Doe"ifelement.surname_match('Doe'):# Unpack the name tuple(first,last)=element.get_name()# Print the first and last name of the found individualprint(first+" "+last)Strict parsingLarge 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:fromgedcom.parserimportParserfile_path=''# Path to your `.ged` filegedcom_parser=Parser()gedcom_parser.parse_file(file_path,False)# Disable strict parsingDisabling strict parsing will allow the parser to gracefully handle the following quirks:Multi-line fields that don't useCONCorCONTHandle the last line not ending in a CRLF (\r\n)ReferenceNote: At a later state the documentation may be outsourced into individual, automatically generated wiki pages.
(Makes things a little bit easier.)ParserclassTheParserclass represents the actual parser. Use this class to parse a GEDCOM file.Note: May be imported viafrom gedcom.parser import Parser.MethodParametersReturnsDescriptioninvalidate_cacheEmpties the element list and dictionary to causeget_element_list()andget_element_dictionary()to return updated dataget_element_listlistofElementReturns a list containing all elements from within the GEDCOM fileget_element_dictionarydictofElementReturns a dictionary containing all elements, identified by a pointer, from within the GEDCOM fileget_root_elementRootElementReturns a virtual root element containing all logical records as childrenget_root_child_elementslistofElementReturns a list of logical records in the GEDCOM fileparse_filestrfile_path,boolstrictOpens and parses a file, from the given file path, as GEDCOM 5.5 formatted dataget_marriagesIndividualElementindividualtuple: (strdate,strplace)Returns a list of marriages of an individual formatted as a tuple (strdate,strplace)get_marriage_yearsIndividualElementindividuallistofintReturns a list of marriage years (as integers) for an individualmarriage_year_matchIndividualElementindividual,intyearboolChecks if one of the marriage years of an individual matches the supplied year. Year is an integer.marriage_range_matchIndividualElementindividual,intfrom_year,intto_yearboolCheck if one of the marriage years of an individual is in a given range. Years are integers.get_familiesIndividualElementindividual,strfamily_type =gedcom.tags.GEDCOM_TAG_FAMILY_SPOUSElistofFamilyElementReturn family elements listed for an individualget_ancestorsIndividualElementindividual,strancestor_type ="ALL"listofElementReturn elements corresponding to ancestors of an individualget_parentsIndividualElementindividual,strparent_type ="ALL"listofIndividualElementReturn elements corresponding to parents of an individualfind_path_to_ancestorIndividualElementdescendant,IndividualElementancestor,path=NoneobjectReturn path from descendant to ancestorget_family_membersFamilyElementfamily,strmembers_type =FAMILY_MEMBERS_TYPE_ALLlistofIndividualElementReturn array of family members: individual, spouse, and childrenprint_gedcomWrite GEDCOM data to stdoutsave_gedcomIOopen_fileSave GEDCOM data to a fileElementclassAn element represents a line from within the parsed GEDCOM file.May be imported viafrom gedcom.element.element import Element.MethodParametersReturnsDescriptionget_levelintReturns the level of this element from within the GEDCOM fileget_pointerstrReturns the pointer of this element from within the GEDCOM fileget_tagstrReturns the tag of this element from within the GEDCOM fileget_valuestrReturns the tag of this element from within the GEDCOM fileset_valuestrvaluestrSets the value of this elementget_multi_line_valuestrReturns the value of this element including concatenations or continuationsset_multi_line_valuestrvaluestrSets the value of this element, adding concatenation and continuation lines when necessaryget_child_elementslistofElementReturns the direct child elements of this elementnew_child_elementstrtag,strpointer ="",strvalue =""ElementCreates and returns a new child element of this elementadd_child_elementElementchildElementAdds a child element to this elementget_parent_elementElementReturns the parent element of this elementset_parent_elementElementparentAdds a parent element to this element. There's usually no need to call this method manually,add_child_element()calls it automatically.get_individualstrDEPRECATED: As of versionv1.0.0useto_gedcom_string()method instead.to_gedcom_stringboolrecursive =FalsestrFormats this element and optionally all of its sub-elements into a GEDCOM conform stringCasting anElementto a string will internally call theto_gedcom_string()method.FamilyElementclass (derived fromElement)May be imported viafrom gedcom.element.family import FamilyElement.MethodParametersReturnsDescriptionis_familyboolChecks if this element is an actual familyFileElementclass (derived fromElement)May be imported viafrom gedcom.element.file import FileElement.MethodParametersReturnsDescriptionis_fileboolChecks if this element is an actual fileIndividualElementclass (derived fromElement)Represents a person from within the parsed GEDCOM file.May be imported viafrom gedcom.element.individual import IndividualElement.MethodParametersReturnsDescriptionis_individualboolChecks if this element is an actual individualis_deceasedboolChecks if this individual is deceasedis_childboolChecks if this element is a child of a familyis_privateboolChecks if this individual is marked privateget_nametuple: (strgiven_name,strsurname)Returns an individual's names as a tuple: (strgiven_name,strsurname)surname_matchstrsurname_to_matchboolMatches a string with the surname of an individualgiven_name_matchstrgiven_name_to_matchboolMatches a string with the given names of an individualget_genderstrReturns the gender of a person in string formatget_birth_datatuple: (strdate,strplace,listsources)Returns the birth data of a person formatted as a tuple: (strdate,strplace,listsources)get_birth_yearintReturns the birth year of a person in integer formatget_death_datatuple: (strdate,strplace,listsources)Returns the death data of a person formatted as a tuple: (strdate,strplace,listsources)get_death_yearintReturns the death year of a person in integer formatget_burial_datatuple: (strdate,strplace,listsources)Returns the burial data of a person formatted as a tuple: (strdate,str´ place,list` sources)get_census_datalistoftuple: (strdate,strplace,listsources)Returns a list of censuses of an individual formatted as tuples: (strdate,str´ place,list` sources)get_last_change_datestrReturns the date of when the person data was last changed formatted as a stringget_occupationstrReturns the occupation of a personbirth_year_matchintyearboolReturnsTrueif the given year matches the birth year of this personbirth_range_matchintfrom_year,intto_yearboolChecks if the birth year of an individual lies within the given rangedeath_year_matchintyearboolReturnsTrueif the given year matches the death year of this persondeath_range_matchintfrom_year,intto_yearboolReturnsTrueif the given year matches the death year of this personcriteria_matchstrcriteriaboolChecks if this individual matches all of the given criteria. Full format forcriteria:surname=[name]:given_name=[given_name]:birth[year]:birth_range=[from_year-to_year]ObjectElementclass (derived fromElement)May be imported viafrom gedcom.element.object import ObjectElement.MethodParametersReturnsDescriptionis_objectboolChecks if this element is an actual objectRootElementclass (derived fromElement)Virtual GEDCOM root element containing all logical records as children.Local developmentI suggest usingpyenvfor local development.Running testsRunpip<version> install --no-cache-dir -r requirements.txtto install dependenciesRun tests withtox(toxin your console)For Python 2.7 runtox -e py27(you need to have Python 2.7 installed)For Python 3.4 runtox -e py34(you need to have Python 3.4 installed)For Python 3.5 runtox -e py35(you need to have Python 3.5 installed)For Python 3.6 runtox -e py36(you need to have Python 3.6 installed)Uploading a new package to PyPIRunpip<version> install --no-cache-dir -r requirements.txtto install dependenciesRunpython<version> setup.py sdist bdist_wheelto generate distribution archivesRuntwine upload --repository-url https://test.pypi.org/legacy/ dist/*to upload the archives to the Test Python Package Index repositoryWhen the package is ready to be published to the real Python Package Index
therepository-urlishttps://upload.pypi.org/legacy/.ChangelogPlease have a look at theCHANGELOG.mdfile.HistoryThis module was originally based on a GEDCOM parser written by
Daniel Zappala at Brigham Young University (Copyright (C) 2005) which
was licensed under the GPL v2 and then continued byMad Price Ballin 2012.The project was taken over byNicklas Reinckein 2018.
Together withDamon Brodiea lot of changes were made and the parser was optimized.LicenseLicensed under theGNU General Public License v2Python GEDCOM ParserCopyright (C) 2018 Damon Brodie (damon.brodie at gmail.com)Copyright (C) 2018-2019 Nicklas Reincke (contact at reynke.com)Copyright (C) 2016 Andreas OberritterCopyright (C) 2012 Madeleine Price BallCopyright (C) 2005 Daniel Zappala (zappala at cs.byu.edu)Copyright (C) 2005 Brigham Young UniversityThis 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.