A gedcom utility library
Project description
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
GedcomHeadobject. - submitters: a list of
GedcomSubmitterobjects. - individuals: a list of
GedcomIndividualobjects. - families: a list of
GedcomFamilyobjects. - objects: a list of
GedcomObjectobjects. - notes: a list of
GedcomNoteobjects. - repository: a list of
GedcomRepositoryobjects. - source: a list of
GedcomSourceobjects.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygedcom-0.2.3.tar.gz.
File metadata
- Download URL: pygedcom-0.2.3.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50c43fa18c88d304ee76ec31f07e99239742f32347269d99927776d71a34ebb3
|
|
| MD5 |
07c35fc9a87931b38933bc735c0cf871
|
|
| BLAKE2b-256 |
6fc8d5f7021f951a5d04e9b20a4be3c9146e3758d572b67c20fa9a8f034d3c40
|
File details
Details for the file pygedcom-0.2.3-py3-none-any.whl.
File metadata
- Download URL: pygedcom-0.2.3-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c796dcc54f9a1118b6f98747bffb8bebff965dc75fa39e93d2a1584b5f40895a
|
|
| MD5 |
013652d684ccdff318e6d740d39719a1
|
|
| BLAKE2b-256 |
4dff7dedb857755edb9be3482c1d49daa44dd058d03384ef4a1be6107411a9ad
|