GedcomParser

class src.pygedcom.gedcom_parser.GedcomParser(path: str)

The GEDCOM parser main class.

Use this class to initialize the parsing of a GEDCOM file. You can then verify, parse, access the elements and export the data.

Parameters:

path (str) – The path to the GEDCOM file.

Returns:

The GEDCOM parser.

Return type:

GedcomParser

add_family(family: GedcomFamily)

Add a family to the collection.

This checks :
  • if the family passed is of type GedcomFamily.

  • if the family passed does not already exist (by xref).

  • if every parent and child exists (their xref are in the individual collection).

Parameters:

family (GedcomFamily) – The family to add.

Raises:
  • KeyError – If the family already exists.

  • TypeError – If the family is not of type GedcomFamily.

add_individual(individual: GedcomIndividual)

Add an individual to the collection.

Parameters:

individual (GedcomIndividual) – The individual to add.

Raises:
  • KeyError – If the individual already exists.

  • TypeError – If the individual is not of type GedcomIndividual.

add_object(object: GedcomObject)

Add an object to the collection.

Parameters:

object (GedcomObject) – The object to add.

Raises:
  • KeyError – If the object already exists.

  • TypeError – If the object is not of type GedcomObject.

add_repository(repository: GedcomRepository)

Add a repository to the collection.

Parameters:

repository (GedcomRepository) – The repository to add.

Raises:
  • KeyError – If the repository already exists.

  • TypeError – If the repository is not of type GedcomRepository.

add_source(source: GedcomSource)

Add a source to the collection.

Parameters:

source (GedcomSource) – The source to add.

Raises:
  • KeyError – If the source already exists.

  • TypeError – If the source is not of type GedcomSource.

export(format: str = 'json', empty_fields=True) str

Export the GEDCOM file to another format.

Parameters:
  • format (str) – The format to export to. Default is “json”.

  • empty_fields (bool) – If True, empty fields will be exported. Default is True.

Returns:

The exported file’s content.

Return type:

str

Raises:

ValueError – If the format is not supported.

find_family(xref: str) GedcomFamily

Find a family by its xref.

Parameters:

xref (str) – The xref to search for.

Returns:

The family if found, None otherwise.

Return type:

GedcomFamily

find_individual(xref: str) GedcomIndividual

Find an individual by its xref.

Parameters:

xref (str) – The xref to search for.

Returns:

The individual if found, None otherwise.

Return type:

GedcomIndividual

find_object(xref: str) GedcomObject

Find an object by its xref.

Parameters:

xref (str) – The xref to search for.

Returns:

The object if found, None otherwise.

Return type:

GedcomObject

find_repository(xref: str) GedcomRepository

Find a repository by its xref.

Parameters:

xref (str) – The xref to search for.

Returns:

The repository if found, None otherwise.

Return type:

GedcomRepository

find_source(xref: str) GedcomSource

Find a source by its xref.

Parameters:

xref (str) – The xref to search for.

Returns:

The source if found, None otherwise.

Return type:

GedcomSource

get_children(individual: GedcomIndividual) list

Get the children of an individual.

Parameters:

individual (GedcomIndividual) – The individual to get the children of.

Returns:

A list of GedcomIndividual objects.

Return type:

list

get_parents(individual: GedcomIndividual) list

Get the parents of an individual.

Parameters:

individual (GedcomIndividual) – The individual to get the parents of.

Returns:

A list of GedcomIndividual objects.

Return type:

list

get_stats() dict

Get statistics about the GEDCOM file.

Returns:

A dictionary with the statistics.

Return type:

dict

parse() dict

Parse the GEDCOM file and return a dictionary with the parsed elements

Returns:

A dictionary with the parsed elements.

Return type:

dict

remove_family(xref: str)

Remove a family from the collection.

Parameters:

xref (str) – The xref of the family to remove.

Raises:

KeyError – If the family does not exist.

remove_individual(xref: str)

Remove an individual from the collection and all mentions of it in families.

Parameters:

xref (str) – The xref of the individual to remove.

Raises:

KeyError – If the individual does not exist.

verify() dict

Verify the file is a valid GEDCOM file. This only checks the level of each line, not the content.

Returns:

A dictionary with the status and the message.

Return type:

dict