gedcom.tags module

Module containing the actual gedcom.parser.Parser used to generate elements - out of each line - which can in return be manipulated.

exception gedcom.parser.GedcomFormatViolationError

Bases: Exception

class gedcom.parser.Parser

Bases: object

Parses and manipulates GEDCOM 5.5 format data For documentation of the GEDCOM 5.5 format, see: http://homepages.rootsweb.ancestry.com/~pmcbride/gedcom/55gctoc.htm This parser reads and parses a GEDCOM file. Elements may be accessed via:

  • a list through gedcom.parser.Parser.get_element_list()

  • a dict through gedcom.parser.Parser.get_element_dictionary()

find_all_paths_to_ancestor(descendant, ancestor, paths=None, parent_type='NAT')

Return list of list of all paths from descendant to ancestor. Each list contains the IndividualElements from the descendant to the ancestor.

Return type

object

find_path_to_ancestor(descendant, ancestor, path=None, parent_type='NAT')

Return path from descendant to ancestor. The search is biased towards male lines because males are listed first in family records. If there is more than one line, only one line is returned.

Return type

object

find_person(criteria)

Returns a person matching all of the criteria. criteria is a colon-separated list, where each item in the list has the form [name]=[value]. The following criteria are supported:

surname=[name] - Match a person with [name] in any part of the surname.

given_name=[given_name] - Match a person with [given_name] in any part of the given given_name.

birth=[year] - Match a person whose birth year is a four-digit [year].

birth_range=[from_year-to_year] - Match a person whose birth year is in the range of years from [from_year] to [to_year], including both [from_year] and [to_year].

death=[year] - Match a person whose death year is a four-digit [year].

death_range=[from_year-to_year] - Match a person whose death year is in the range of years from [from_year] to [to_year], including both [from_year] and [to_year].

Return type

IndividualElement

get_ancestors(individual, ancestor_type='ALL')

Return elements corresponding to ancestors of an individual Optional ancestor_type. Default “ALL” returns all ancestors, “NAT” can be used to specify only natural (genetic) ancestors.

Return type

list of Element

get_children(individual)

Return elements corresponding to children of an individual

Return type

list of IndividualElement

get_element_dictionary()

Returns a dictionary containing all elements, identified by a pointer, from within the GEDCOM file Only elements identified by a pointer are listed in the dictionary. The keys for the dictionary are the pointers.

This dictionary gets generated on-the-fly, but gets cached. If the database was modified, you should call invalidate_cache() once to let this method return updated data.

Return type

dict of Element

get_element_list()

Returns a list containing all elements from within the GEDCOM file By default elements are in the same order as they appeared in the file. This list gets generated on-the-fly, but gets cached. If the database was modified, you should call gedcom.parser.Parser.invalidate_cache() once to let this method return updated data.

Consider using gedcom.parser.Parser.get_root_element() or gedcom.parser.Parser.get_root_child_elements() to access the hierarchical GEDCOM tree, unless you rarely modify the database.

Return type

list of Element

get_families(individual, family_type='FAMS')

Return family elements listed for an individual family_type can be gedcom.tags.GEDCOM_TAG_FAMILY_SPOUSE (families where the individual is a spouse) or gedcom.tags.GEDCOM_TAG_FAMILY_CHILD (families where the individual is a child). If a value is not provided, gedcom.tags.GEDCOM_TAG_FAMILY_SPOUSE is default value.

Return type

list of FamilyElement

get_family(individual, members_type='CHIL')

Return elements corresponding to children or spouses of an individual

Return type

list of IndividualElement

get_family_members(family, members_type='ALL')

Return array of family members: individual, spouse, and children Optional argument members_type can be used to return specific subsets:

“FAMILY_MEMBERS_TYPE_ALL”: Default, return all members of the family

“FAMILY_MEMBERS_TYPE_PARENTS”: Return individuals with “HUSB” and “WIFE” tags (parents)

“FAMILY_MEMBERS_TYPE_HUSBAND”: Return individuals with “HUSB” tags (father)

“FAMILY_MEMBERS_TYPE_WIFE”: Return individuals with “WIFE” tags (mother)

“FAMILY_MEMBERS_TYPE_CHILDREN”: Return individuals with “CHIL” tags (children)

Return type

list of IndividualElement

get_marriage_years(individual)

Returns a list of marriage years (as integers) for an individual

Return type

list of int

get_marriages(individual)

Returns a list of marriages of an individual formatted as a tuple (str date, str place)

Return type

tuple

get_marriages_data(individual)

Returns a list of marriages of an individual formatted as a tuple (spouse str, str date, str place, list sources)

Return type

tuple

get_parents(individual, parent_type='ALL')

Return elements corresponding to parents of an individual Optional parent_type. Default “ALL” returns all parents. “NAT” can be used to specify only natural (genetic) parents.

Return type

list of IndividualElement

get_root_child_elements()

Returns a list of logical records in the GEDCOM file By default, elements are in the same order as they appeared in the file.

Return type

list of Element

get_root_element()

Returns a virtual root element containing all logical records as children When printed, this element converts to an empty string.

Return type

RootElement

get_spouses(individual)

Return elements corresponding to spouses of an individual

Return type

list of IndividualElement

invalidate_cache()

Empties the element list and dictionary to cause gedcom.parser.Parser.get_element_list() and gedcom.parser.Parser.get_element_dictionary() to return updated data. The update gets deferred until each of the methods actually gets called.

marriage_range_match(individual, from_year, to_year)

Check if one of the marriage years of an individual is in a given range. Years are integers.

Return type

bool

marriage_year_match(individual, year)

Checks if one of the marriage years of an individual matches the supplied year. Year is an integer.

Return type

bool

parse(gedcom_stream, strict=True, total_lines=0, callback=None)

Parses a stream, or an array of lines, as GEDCOM 5.5 formatted data. Callback function is used to communicate the progress. Parsing large files may take time.

parse_file(file_path, strict=True, callback=None)

Opens and parses a file, from the given file path, as GEDCOM 5.5 formatted data. Callback function is used to communicate the progress. Parsing large files may take time.

print_gedcom()

Write GEDCOM data to stdout

save_gedcom(open_file)

Save GEDCOM data to a file