Skip to main content

pygedcom

Python module to parse GEDCOM 5.5.1 files and generate output files in a more human readable format.

Full documentation is available at https://topetit.github.io/pygedcom/docs/.

Installation

You can install the module with pip:

pip install pygedcom

Getting started

First, you need to import the pygedcom module.

import pygedcom

To get started with the parser module, you'll need to initialize a GedcomParser object:

parser = pygedcom.GedcomParser(path="path/to/your/gedcom_file.ged")

You can check the parsing statistics to ensure that you've parsed the file correctly:

print(parser.get_stats())

It's good practice to verify your GEDCOM file before parsing it. You can do this with the following command:

check = parser.verify()
if check.status == 'ok':
    print("Your GEDCOM file is valid")
else:
    print("Your GEDCOM file is not valid")
    print(check.errors)

Here is the full setup block:

import pygedcom

parser = pygedcom.GedcomParser(path="path/to/your/gedcom_file.ged")
check = parser.verify()

if check.status == 'ok':
    print("Your GEDCOM file is valid")
else:
    print("Your GEDCOM file is not valid")
    print(check.errors)

print(parser.get_stats())

Parsing

The parser is a simple recursive parser. It creates a series of GedcomElement objects.

    # Initialize the parser
    data = parser.parse()

Now the data object contains the parsed data. This is a dictionary with the following fields:

  • head: the GedcomHead object.
  • submitters: a list of GedcomSubmitter objects.
  • individuals: a list of GedcomIndividual objects.
  • families: a list of GedcomFamily objects.
  • objects: a list of GedcomObject objects.
  • notes: a list of GedcomNote objects.
  • repository: a list of GedcomRepository objects.
  • source: a list of GedcomSource objects.

Export

The export function is used to export the GedcomParser object to a file. The export function takes two arguments:

  • format (str): The format to export to. Currently only "json" is supported.
  • empty_fields (bool): Whether to include empty fields in the export. Defaults to True.

This is a recursive export process. The method GedcomParser.export() calls the GedcomElement.export() method for each element in the GedcomParser object. All attributes starting with __export_ are exported. This is implemented as such to centralise the export process and to make it easy to add new export formats. Only one declaration is needed in the GedcomElement. If you want an attribute to be exported, you need it to start with __export_.

# Make sure you initialized the parser first
parser = GedcomParser("path/to/file.ged")
parser.parse()
export = parser.export("json", empty_fields=False)

# Write the export to a file
with open("path/to/export.json", "w") as f:
    f.write(export)

The export variable in this example contains the exported GedcomParser object as a string. You can write this string to a file or do whatever you want with it.

Metadata

Release files for pygedcom 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygedcom 0.2.3
File Size Uploaded
pygedcom-0.2.3.tar.gz 26.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygedcom 0.2.3
File Interpreter ABI Platform
pygedcom-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 52.8 kB

Release files / pygedcom-0.2.3.tar.gz

Download URL pygedcom-0.2.3.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
50c43fa18c88d304ee76ec31f07e99239742f32347269d99927776d71a34ebb3
BLAKE2b-256 checksum
How to use checksums
6fc8d5f7021f951a5d04e9b20a4be3c9146e3758d572b67c20fa9a8f034d3c40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.19

Release files / pygedcom-0.2.3-py3-none-any.whl

Download URL pygedcom-0.2.3-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c796dcc54f9a1118b6f98747bffb8bebff965dc75fa39e93d2a1584b5f40895a
BLAKE2b-256 checksum
How to use checksums
4dff7dedb857755edb9be3482c1d49daa44dd058d03384ef4a1be6107411a9ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page