Skip to main content

A simple Python client to interact with Gramps Web API

Project description

Gramps Web API Client

A simple Python client based on requests for interacting with a Gramps Web API server.

Warning

This is an experimental project for advanced users. The goal is to allow powerful batch operations on Gramps objects via the API. But only use it if you know what you are doing – you can easily break your Gramps database with this tool!

Quick start

First, instantiate the API instance:

from gramps_web_api_client import API

api = API(
    host="https://my-gramps-web-instance.com",
    basic_auth("my_user", "my_password")
)

Methods currently implemented:

Method description
api.iter_people() Generator iterating over people
api.iter_events() Generator iterating over events
api.iter_places() Generator iterating over places
api.get_person(handle) Get a single person by handle
api.get_event(handle) Get a single event by handle
api.get_place(handle) Get a single place by handle
api.update_person(handle, data) Update a single person
api.update_event(handle, data) Update a single event
api.update_place(handle, data) Update a single place
api.create_person(data) Create a new person
api.create_event(data) Create a new evebt
api.create_place(data) GCreateet a new place

In all cases, data are dictionaries for JSON objects following the Gramps Web API conventions.

Examples

Removing all citations from an existing person:

api.update_person("somehandle", {"citation_list": []})

In this example, all other properties of the person (except citations) will remain the same.

Creating a new place:

api.create_place({
    "name": {
        "_class": "PlaceName",
        "value": "Gotham City"
    }
})

Iterating over people and adding a citation if a condition is satisfied:

for person in api.iter_people():
    try:
        surname = person["primary_name"]["surname_list"][0]["surname"]
    except (KeyError, IndexError):
        continue
    if surname == "Garner":
        api.update_person(
            person["handle"],
            {"citation_list": person["citation_list"] + ["some_citation_handle"]}
        )    

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

gramps-web-api-client-0.1.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

gramps_web_api_client-0.1-py3-none-any.whl (4.7 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