Skip to main content

A gedcom tool to parse, browse and modify gedcom files

Project description

FastGedcom

A gedcom tool to parse, browse and modify gedcom files

Installation

You can install FastGedcom using pip:

pip install fastgedcom

The ansel library is a dependancy of FastGedcom. It is automatically installed by pip. This library allows to decode files encoded in ansel or gedcom.

Features

  • Supports the read of gedcom files encoded in UTF-8 with and without BOM, UTF-16 (also named UNICODE), ANSI, and ANSEL.

  • Supports the export to gedcom files encoded in UTF-8, UTF-16, and ANSI.

  • The gedcom representation (the data structure) is very lite (2 classes overall).

  • No data parsing is done (due to the wide diversity), but helper methods are provided.

Motivations

The FastGedcom library is intented to be read, understood, and used quickly, so you focus on what really matters. The code has type hints to help with development. Functions are based directly on gedcom pointers for ease of use. Due to the wide variety of gedcom software, no data parsing is done, but some standalone functions are provided (see the gedcom_helper module).

Usage examples

In the following example, we print the name of the person under the reference @I1@.

from fastgedcom.gedcom_parser import guess_encoding, parse

gedcom_file = "your_gedcom_file"
with open(gedcom_file, "r", encoding=guess_encoding(gedcom_file)) as f:
	gedcom, warnings = parse(f)
print("Warnings:", *warnings, sep="\n", end="---\n")

indi = gedcom.get_record("@I1@")
assert(indi)
name = indi.get_sub_record_payload("NAME")
print(name)

In the following example, we count the number of ancestral generations of the person whose reference is @I1@.

from fastgedcom.gedcom_parser import guess_encoding, parse
from fastgedcom.gedcom_structure import IndiRef

gedcom_file = "fastgedcom/test/test_data/bouyer-perret 20220809.ged"
with open(gedcom_file, "r", encoding=guess_encoding(gedcom_file)) as f:
	gedcom, _ = parse(f)

def nb_ancestral_gen(indi: IndiRef) -> int:
	father, mother = gedcom.get_parents(indi)
	father_gens = 0 if father is None else 1+nb_ancestral_gen(father)
	mother_gens = 0 if mother is None else 1+nb_ancestral_gen(mother)
	return max(1, father_gens, mother_gens)

number_generations_above_root = nb_ancestral_gen("@I1@")

print(f"Number of generations above root: {number_generations_above_root}")

In the following example, we find the oldest deceased person. Then, we print his name and all his gedcom information using the gedcom_helper module

from fastgedcom.gedcom_helper import (extract_int_year, extract_year,
                                      get_birth_date, get_death_date,
                                      get_gedcom_data, get_name)
from fastgedcom.gedcom_parser import guess_encoding, parse

gedcom_file = "your_gedcom_file"
with open(gedcom_file, "r", encoding=guess_encoding(gedcom_file)) as f:
	gedcom, _ = parse(f)

oldest = next(gedcom.get_records("INDI")).tag
age_oldest = 0.0 # the age is a float to handle all type of date
# A date such as between 2001 and 2002 returns 2001.5
for individual in gedcom.get_records("INDI"):
	birth_date = get_birth_date(gedcom, individual.tag)
	death_date = get_death_date(gedcom, individual.tag)
	birth_year = extract_int_year(birth_date)
	death_year = extract_int_year(death_date)
	if birth_year is None or death_year is None: continue
	age = death_year - birth_year
	if age > age_oldest:
		oldest = individual.tag
		age_oldest = age

print("Oldest person:", get_name(gedcom, oldest))
print("Year of birth:", extract_year(get_birth_date(gedcom, oldest)))
print("Year of death:", extract_year(get_death_date(gedcom, oldest)))
print("Age:", age_oldest)
print("All the information:", get_gedcom_data(gedcom, oldest))

Contributing

Contributions are welcome, and they will be greatly appreciated!

If you like this project, consider putting a star on Github, thank you!

For any feedback or question, please feel free to contact me by email at gatien.bouyer.dev@gmail.com or via Github issues.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastgedcom-0.0.1.tar.gz (12.6 kB view hashes)

Uploaded Source

Built Distribution

fastgedcom-0.0.1-py3-none-any.whl (12.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page