Tools to implement data APIs

Support for accessing data in a repository with some “known locations” via an API object.

class clldutils.apilib.API(repos=None)[source]

An API base class to provide programmatic access to data in a git repository.

Variables:

repos (pathlib.Path) – Path of the (data) repository.

Some repositories provide functionality to explore their data, implemented as Javascript app that can be browsed locally, from the filesystem. This scenario is supported as follows:

  • the app is assumed to “live” in the API.appdir() sub-directory,

  • browsable at <API.appdir>/index.html,

  • with app data at API.appdatadir().

Then, a function which recreates the app data can be decorated with API.app_wrapper() to initialise the app data directory and open the app in a browser after the method has finished.

@API.app_wrapper
def f(args):
    import shutil
    shutil.copy(args.api.path('stuff'), args.api.appdatadir)
path(*comps)[source]

A path within the repository.

Parameters:

comps (str) – path components relative to self.repos.

Return type:

pathlib.Path

dataset_metadata[source]

If a repository provides metadata about the dataset curated there as JSON-LD file called metadata.json, this property returns a clldutils.metadata.Metadata object, loaded from this metadata.