fairgraph


Namefairgraph JSON
Version 0.11.1 PyPI version JSON
download
home_page
SummaryPython API for the EBRAINS Knowledge Graph
upload_time2023-09-11 12:47:58
maintainer
docs_urlNone
author
requires_python>=3.7
licenseApache Software License
keywords ebrains hbp metadata electrophysiology knowledge-graph
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # fairgraph: a Python API for the EBRAINS Knowledge Graph.

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

Copyright CNRS 2019-2023

**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.
The API is not stable, and is subject to change.

## 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 versions

This version of fairgraph supports version 3 of the EBRAINS Knowledge Graph (KG).

## 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 a Collaboratory Jupyter notebook, the client will find your token automatically.

If working outside the Collaboratory, we recommend you obtain a token from whichever authentication endpoint
is available to you, and save it as an environment variable so the client can find it, e.g. at a shell prompt:

```
export KG_AUTH_TOKEN=eyJhbGci...nPq
```

You can then create the client object:

```
>>> from fairgraph import KGClient

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

You can also pass the token explicitly to the client:

```
>>> client = KGClient(token)
```


## Retrieving metadata from the Knowledge Graph

The Knowledge Graph uses [openMINDS](https://github.com/HumanBrainProject/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.controlledterms import Technique
```

The following openMINDS modules are currently available: `core`, `controlledterms`, `sands`, `computation`, `ephys`, `publications`.
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', 'patch clamp technique', 'whole cell patch clamp']
>>> whole_cell_patch = patch_techniques[4]
```

```
>>> datasets = DatasetVersion.list(client, techniques=whole_cell_patch, scope="in progress")
```

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_name(client, scope="in progress"))
'Cholinergic interneurons in the striatum - Single cell patch clamp recordings'
```

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

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

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, scope="in progress")
>>> authors = [author.resolve(client, scope="in progress") for author in dataset.authors]
```

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

```
>>> print(dataset.version_innovation)
This is the first version of this research product.
```

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']
```

You can also access any associated data:

```
>>> dataset.download(client, local_directory=dataset.alias)
```


## 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 datetime
from fairgraph.openminds.core import Person, Organization, Affiliation

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

affiliation = Affiliation(organization=mgm, start_date=datetime(1942, 1, 1))
author = Person(family_name="Laurel", given_name="Stan", affiliations=affiliation)
author.save(client, space="myspace")
```

## 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](https://github.com/HumanBrainProject/fairgraph/issues).

## Acknowledgements

<div><img src="https://www.braincouncil.eu/wp-content/uploads/2018/11/wsi-imageoptim-EU-Logo.jpg" alt="EU Logo" height="23%" width="15%" align="right" style="margin-left: 10px"></div>

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).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fairgraph",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "ebrains,hbp,metadata,electrophysiology,knowledge-graph",
    "author": "",
    "author_email": "\"Andrew P. Davison\" <andrew.davison@cnrs.fr>",
    "download_url": "https://files.pythonhosted.org/packages/e9/28/ce57531a6732f1d84637347fe69bb8492d51c85bffe1913ff3c037c98bfa/fairgraph-0.11.1.tar.gz",
    "platform": null,
    "description": "# fairgraph: a Python API for the EBRAINS Knowledge Graph.\n\nAuthors: Andrew P. Davison, Onur Ates, Nico Feld, Yann Zerlaut, Glynis Mattheisen, Peyman Najafi\n\nCopyright CNRS 2019-2023\n\n**fairgraph** is a Python library for working with metadata\nin the EBRAINS Knowledge Graph, with a particular focus on data reuse,\nalthough it is also useful in metadata registration/curation.\nThe API is not stable, and is subject to change.\n\n## Installation\n\nTo get the latest release:\n\n```\npip install fairgraph\n```\n\nTo get the development version:\n\n```\ngit clone https://github.com/HumanBrainProject/fairgraph.git\npip install -U ./fairgraph\n```\n\n## Knowledge Graph versions\n\nThis version of fairgraph supports version 3 of the EBRAINS Knowledge Graph (KG).\n\n## Basic setup\n\nThe basic idea of the library is to represent metadata nodes from the Knowledge Graph as Python objects.\nCommunication with the Knowledge Graph service is through a client object,\nfor which an access token associated with an EBRAINS account is needed.\n\nIf you are working in a Collaboratory Jupyter notebook, the client will find your token automatically.\n\nIf working outside the Collaboratory, we recommend you obtain a token from whichever authentication endpoint\nis available to you, and save it as an environment variable so the client can find it, e.g. at a shell prompt:\n\n```\nexport KG_AUTH_TOKEN=eyJhbGci...nPq\n```\n\nYou can then create the client object:\n\n```\n>>> from fairgraph import KGClient\n\n>>> client = KGClient(host=\"core.kg.ebrains.eu\")\n```\n\nYou can also pass the token explicitly to the client:\n\n```\n>>> client = KGClient(token)\n```\n\n\n## Retrieving metadata from the Knowledge Graph\n\nThe Knowledge Graph uses [openMINDS](https://github.com/HumanBrainProject/openMINDS) schemas.\nEach openMINDS schema corresponds to a Python class, which are grouped into modules\nfollowing the openMINDS structure. For example:\n\n```\n>>> from fairgraph.openminds.core import DatasetVersion\n>>> from fairgraph.openminds.controlledterms import Technique\n```\n\nThe following openMINDS modules are currently available: `core`, `controlledterms`, `sands`, `computation`, `ephys`, `publications`.\nUsing these classes, it is possible to list all metadata matching a particular criterion, e.g.\n\n```\n>>> patch_techniques = Technique.list(client, name=\"patch clamp\")\n>>> print([technique.name for technique in patch_techniques])\n['cell attached patch clamp', 'multiple whole cell patch clamp', 'patch clamp', 'patch clamp technique', 'whole cell patch clamp']\n>>> whole_cell_patch = patch_techniques[4]\n```\n\n```\n>>> datasets = DatasetVersion.list(client, techniques=whole_cell_patch, scope=\"in progress\")\n```\n\nFor 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:\n\n```\n>>> print(datasets[0].get_name(client, scope=\"in progress\"))\n'Cholinergic interneurons in the striatum - Single cell patch clamp recordings'\n```\n\nIf you know the unique identifier of an object, you can retrieve it directly:\n\n```\n>>> dataset = DatasetVersion.from_id(\"17196b79-04db-4ea4-bb69-d20aab6f1d62\", client, scope=\"in progress\")\n```\n\nLinks between metadata in the Knowledge Graph are not followed automatically,\nto avoid unnecessary network traffic, but can be followed with the `resolve()` method:\n\n```\n>>> license = dataset.license.resolve(client, scope=\"in progress\")\n>>> authors = [author.resolve(client, scope=\"in progress\") for author in dataset.authors]\n```\n\nThe associated metadata is accessible as attributes of the Python objects, e.g.:\n\n```\n>>> print(dataset.version_innovation)\nThis is the first version of this research product.\n```\n\nTo print out all the metadata for a given object, use the `show()` method:\n\n```\n>>> print(license.show())\nid          https://kg.ebrains.eu/api/instances/6ebce971-7f99-4fbc-9621-eeae47a70d85\nname        Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International\nlegal_code  https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode\nalias       CC BY-NC-SA 4.0\nwebpages    ['https://creativecommons.org/licenses/by-nc-sa/4.0', 'https://spdx.org/licenses/CC-BY-NC-SA-4.0.html']\n```\n\nYou can also access any associated data:\n\n```\n>>> dataset.download(client, local_directory=dataset.alias)\n```\n\n\n## Storing and editing metadata\n\nFor those users who have the necessary permissions to store and edit metadata in the Knowledge Graph,\n**fairgraph** objects can be created or edited in Python, and then saved back to the Knowledge Graph, e.g.:\n\n```\nfrom datetime import datetime\nfrom fairgraph.openminds.core import Person, Organization, Affiliation\n\nmgm = Organization(name=\"Metro-Goldwyn-Mayer\", alias=\"MGM\")\nmgm.save(client, space=\"myspace\")\n\naffiliation = Affiliation(organization=mgm, start_date=datetime(1942, 1, 1))\nauthor = Person(family_name=\"Laurel\", given_name=\"Stan\", affiliations=affiliation)\nauthor.save(client, space=\"myspace\")\n```\n\n## Getting help\n\nIn case of questions about **fairgraph**, please contact us via https://ebrains.eu/support/.\nIf you find a bug or would like to suggest an enhancement or new feature,\nplease open a ticket in the [issue tracker](https://github.com/HumanBrainProject/fairgraph/issues).\n\n## Acknowledgements\n\n<div><img src=\"https://www.braincouncil.eu/wp-content/uploads/2018/11/wsi-imageoptim-EU-Logo.jpg\" alt=\"EU Logo\" height=\"23%\" width=\"15%\" align=\"right\" style=\"margin-left: 10px\"></div>\n\nThis 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).\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "Python API for the EBRAINS Knowledge Graph",
    "version": "0.11.1",
    "project_urls": {
        "Homepage": "https://github.com/HumanBrainProject/fairgraph"
    },
    "split_keywords": [
        "ebrains",
        "hbp",
        "metadata",
        "electrophysiology",
        "knowledge-graph"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "258ceec262f480a46d99c69e17d6f09dd53b7dcde1d92ba9509e81e861cadeda",
                "md5": "8543192c2608a368c959cc42020c9d71",
                "sha256": "4ba702e59ca436dfe80c093db196657442347667575027689136bfe362b09655"
            },
            "downloads": -1,
            "filename": "fairgraph-0.11.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8543192c2608a368c959cc42020c9d71",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 416628,
            "upload_time": "2023-09-11T12:47:56",
            "upload_time_iso_8601": "2023-09-11T12:47:56.378750Z",
            "url": "https://files.pythonhosted.org/packages/25/8c/eec262f480a46d99c69e17d6f09dd53b7dcde1d92ba9509e81e861cadeda/fairgraph-0.11.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e928ce57531a6732f1d84637347fe69bb8492d51c85bffe1913ff3c037c98bfa",
                "md5": "5e82b575ce14db5a1522e617f93a99c4",
                "sha256": "e4bc1737af032e7a9f693c8f12112e100762dd9597022aed012ae05d8196ebeb"
            },
            "downloads": -1,
            "filename": "fairgraph-0.11.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5e82b575ce14db5a1522e617f93a99c4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 175335,
            "upload_time": "2023-09-11T12:47:58",
            "upload_time_iso_8601": "2023-09-11T12:47:58.673209Z",
            "url": "https://files.pythonhosted.org/packages/e9/28/ce57531a6732f1d84637347fe69bb8492d51c85bffe1913ff3c037c98bfa/fairgraph-0.11.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-11 12:47:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HumanBrainProject",
    "github_project": "fairgraph",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "fairgraph"
}
        
Elapsed time: 0.11265s