Skip to main content

fairgraph: a Python API for the EBRAINS Knowledge Graph.

tests Documentation PyPI - Version

Authors: Andrew P. Davison, Onur Ates, Nico Feld, Yann Zerlaut, Glynis Mattheisen, Peyman Najafi

Copyright 2018-2026 CNRS and fairgraph authors and/or their employers

fairgraph is a Python library for working with metadata in the EBRAINS Knowledge Graph, with a particular focus on data reuse, although it is also useful in metadata registration/curation.

Installation

To get the latest release:

pip install fairgraph

To get the development version:

git clone https://github.com/HumanBrainProject/fairgraph.git
pip install -U ./fairgraph

Knowledge Graph and openMINDS versions

This version of fairgraph supports version 3 of the EBRAINS Knowledge Graph (KG), and both version 4 and version 5 of the openMINDS metadata schemas.

openMINDS v4 is the default: fairgraph.openminds.core and the other domain modules contain the v4 classes, as before. The v5 classes live alongside them, and each version can also be imported explicitly:

import fairgraph.openminds.core as omcore          # v4 (default)
import fairgraph.openminds.v4.core as omcore4      # explicit v4
import fairgraph.openminds.v5.core as omcore5      # explicit v5

Since the two versions share the same node type URIs in the KG, the client needs to be told which of them to deserialize responses into:

client = KGClient(host=host_serving_v5_metadata, openminds_version="v5")

Omitting openminds_version keeps the v4 behaviour.

Basic setup

The basic idea of the library is to represent metadata nodes from the Knowledge Graph as Python objects. Communication with the Knowledge Graph service is through a client object, for which an access token associated with an EBRAINS account is needed.

If you are working in an EBRAINS Lab Jupyter notebook, the client will find your token automatically.

If working outside EBRAINS Lab, we recommend you use the allow_interactive option:

>>> client = KGClient(host="core.kg.ebrains.eu", allow_interactive=True)

This prints the URL of a log-in page, which you should open in a web-browser. Once you have logged in, close the tab and return to your Python prompt.

You can also obtains a token elsewhere and pass it to the client:

>>> client = KGClient(host="core.kg.ebrains.eu", token)

Retrieving metadata from the Knowledge Graph

The Knowledge Graph uses openMINDS schemas. Each openMINDS schema corresponds to a Python class, which are grouped into modules following the openMINDS structure. For example:

>>> from fairgraph.openminds.core import DatasetVersion
>>> from fairgraph.openminds.controlled_terms import Technique

The following openMINDS modules are currently available: core, controlled_terms, sands, computation, chemicals, specimen_prep, ephys, publications, stimulation. Using these classes, it is possible to list all metadata matching a particular criterion, e.g.

>>> patch_techniques = Technique.list(client, name="patch clamp")
>>> print([technique.name for technique in patch_techniques])
['cell attached patch clamp', 'multiple whole cell patch clamp', 'patch clamp', 'whole cell patch clamp']
>>> whole_cell_patch = patch_techniques[3]
>>> datasets = DatasetVersion.list(client, techniques=whole_cell_patch)

The associated metadata are accessible as attributes of the Python objects, e.g.:

>>> print(datasets[0].version_innovation)
'This is the only version of this dataset.'

You can also access any associated data:

>>> datasets[0].download(client, local_directory="downloads")

Inherited attributes

For research products that are versioned, such as datasets, models, and software, certain attributes may be inherited from the parent (e.g., a DatasetVersion generally inherits its name from a Dataset). In this case, we have a convenience method to retrieve the parent's name:

>>> print(datasets[0].get_full_name(client))
'Recordings of excitatory postsynaptic currents from cerebellar neurons'

Unique identifiers

If you know the unique identifier of an object, you can retrieve it directly:

>>> dataset = DatasetVersion.from_id("17196b79-04db-4ea4-bb69-d20aab6f1d62", client)

Links between metadata in the Knowledge Graph are not followed automatically, to avoid unnecessary network traffic, but can be followed with the resolve() method:

>>> license = dataset.license.resolve(client)
>>> authors = [author.resolve(client) for author in dataset.get_authors(client)]

If you know in advance which links you wish to follow, you can use the follow_links option:

>>> dataset = DatasetVersion.from_id(
...     "17196b79-04db-4ea4-bb69-d20aab6f1d62",
...     client,
...     follow_links={
...         "license": {},
...         "is_version_of": {
...             "authors": {}
...         }
...     }
... )
>>> dataset.is_version_of[0].authors[0].given_name
'Francesca'
>>> dataset.license.short_name
'CC-BY-NC-SA-4.0'

Note that this can also be used to follow multiple links in the graph; in the example above we asked for the authors of the parent Dataset.

To print out all the metadata for a given object, use the show() method:

>>> print(license.show())
id          https://kg.ebrains.eu/api/instances/6ebce971-7f99-4fbc-9621-eeae47a70d85
name        Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
legal_code  https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
alias       CC BY-NC-SA 4.0
webpages    ['https://creativecommons.org/licenses/by-nc-sa/4.0', 'https://spdx.org/licenses/CC-BY-NC-SA-4.0.html']

Storing and editing metadata

For those users who have the necessary permissions to store and edit metadata in the Knowledge Graph, fairgraph objects can be created or edited in Python, and then saved back to the Knowledge Graph, e.g.:

from datetime import date
from fairgraph.openminds.core import Person, Organization, Affiliation

mgm = Organization(full_name="Metro-Goldwyn-Mayer", short_name="MGM")
mgm.save(client, space="myspace")

affiliation = Affiliation(member_of=mgm, start_date=date(1941, 2, 23))
author = Person(family_name="Laurel", given_name="Stan", affiliations=[affiliation])
author.save(client, space="myspace")

Roadmap

Planned work is tracked with milestones on the issue tracker: each milestone collects the issues intended for a given release.

Getting help

In case of questions about fairgraph, please contact us via https://ebrains.eu/support/. If you find a bug or would like to suggest an enhancement or new feature, please open a ticket in the issue tracker.

Acknowledgements

EU Logo

This open source software code was developed in part or in whole in the Human Brain Project, funded from the European Union's Horizon 2020 Framework Programme for Research and Innovation under Specific Grant Agreements No. 720270, No. 785907 and No. 945539 (Human Brain Project SGA1, SGA2 and SGA3) and in the EBRAINS research infrastructure, funded from the European Union's Horizon Europe funding programme under grant agreement No. 101147319 (EBRAINS-2.0).

Metadata

Release files for fairgraph 0.16.0

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

Source distribution (sdist)

Source distribution for fairgraph 0.16.0
File Size Uploaded Provenance Actions
fairgraph-0.16.0.tar.gz 260.5 kB Without provenance Details for fairgraph-0.16.0.tar.gz

Built distribution (wheel)

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

Total release size: 916.4 kB

Release files / fairgraph-0.16.0.tar.gz

Download URL fairgraph-0.16.0.tar.gz
Size 260.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6a07219f435eb5b74147a37b8b763b982138fb6ec8d780826ecc5e0f98d66427
BLAKE2b-256 checksum
How to use checksums
2f1e3fc197b19813d8526d26edf108ff472eee151d038c3da25e27243f923da7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / fairgraph-0.16.0-py3-none-any.whl

Download URL fairgraph-0.16.0-py3-none-any.whl
Size 655.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4cbc5d20fedb2ed14ffcccc1a1f443513e51cad9c5d0d3270b71aaa79c05f1aa
BLAKE2b-256 checksum
How to use checksums
b0623c532ed9f4d27a94d845414f0b3f98f53779b8b5a4a0003999404ca97819
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Security for fairgraph 0.16.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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