Skip to content

Commit 2bfc84d

Browse files
committed
Update README
1 parent 711999e commit 2bfc84d

File tree

1 file changed

+58
-36
lines changed

1 file changed

+58
-36
lines changed

README.md

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
Copyright CNRS 2019-2024
5+
Copyright CNRS 2019-2025
66

77
**fairgraph** is a Python library for working with metadata
88
in the EBRAINS Knowledge Graph, with a particular focus on data reuse,
@@ -24,40 +24,34 @@ git clone https://github.com/HumanBrainProject/fairgraph.git
2424
pip install -U ./fairgraph
2525
```
2626

27-
## Knowledge Graph versions
27+
## Knowledge Graph and openMINDS versions
2828

29-
This version of fairgraph supports version 3 of the EBRAINS Knowledge Graph (KG).
29+
This version of fairgraph supports version 3 of the EBRAINS Knowledge Graph (KG),
30+
and version 4 of the openMINDS metadata schemas.
3031

3132
## Basic setup
3233

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

37-
If you are working in a Collaboratory Jupyter notebook, the client will find your token automatically.
38+
If you are working in an EBRAINS Lab Jupyter notebook, the client will find your token automatically.
3839

39-
If working outside the Collaboratory, we recommend you obtain a token from whichever authentication endpoint
40-
is available to you, and save it as an environment variable so the client can find it, e.g. at a shell prompt:
40+
If working outside EBRAINS Lab, we recommend you use the `allow_interactive` option:
4141

4242
```
43-
export KG_AUTH_TOKEN=eyJhbGci...nPq
43+
>>> client = KGClient(host="core.kg.ebrains.eu", allow_interactive=True)
4444
```
4545

46-
You can then create the client object:
46+
This prints the URL of a log-in page, which you should open in a web-browser.
47+
Once you have logged in, close the tab and return to your Python prompt.
4748

48-
```
49-
>>> from fairgraph import KGClient
50-
51-
>>> client = KGClient(host="core.kg.ebrains.eu")
52-
```
53-
54-
You can also pass the token explicitly to the client:
49+
You can also obtains a token elsewhere and pass it to the client:
5550

5651
```
57-
>>> client = KGClient(token)
52+
>>> client = KGClient(host="core.kg.ebrains.eu", token)
5853
```
5954

60-
6155
## Retrieving metadata from the Knowledge Graph
6256

6357
The Knowledge Graph uses [openMINDS](https://github.com/HumanBrainProject/openMINDS) schemas.
@@ -75,42 +69,77 @@ Using these classes, it is possible to list all metadata matching a particular c
7569
```
7670
>>> patch_techniques = Technique.list(client, name="patch clamp")
7771
>>> print([technique.name for technique in patch_techniques])
78-
['cell attached patch clamp', 'multiple whole cell patch clamp', 'patch clamp', 'patch clamp technique', 'whole cell patch clamp']
79-
>>> whole_cell_patch = patch_techniques[4]
72+
['cell attached patch clamp', 'multiple whole cell patch clamp', 'patch clamp', 'whole cell patch clamp']
73+
>>> whole_cell_patch = patch_techniques[3]
74+
```
75+
76+
```
77+
>>> datasets = DatasetVersion.list(client, techniques=whole_cell_patch)
78+
```
79+
80+
The associated metadata are accessible as attributes of the Python objects, e.g.:
81+
82+
```
83+
>>> print(datasets[0].version_innovation)
84+
'This is the only version of this dataset.'
8085
```
8186

87+
You can also access any associated data:
88+
8289
```
83-
>>> datasets = DatasetVersion.list(client, techniques=whole_cell_patch, release_status="in progress")
90+
>>> datasets[0].download(client, local_directory="downloads")
8491
```
8592

86-
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:
93+
### Inherited attributes
94+
95+
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).
96+
In this case, we have a convenience method to retrieve the parent's name:
8797

8898
```
89-
>>> print(datasets[0].get_name(client, release_status="in progress"))
90-
'Cholinergic interneurons in the striatum - Single cell patch clamp recordings'
99+
>>> print(datasets[0].get_full_name(client))
100+
'Recordings of excitatory postsynaptic currents from cerebellar neurons'
91101
```
92102

103+
### Unique identifiers
104+
93105
If you know the unique identifier of an object, you can retrieve it directly:
94106

95107
```
96-
>>> dataset = DatasetVersion.from_id("17196b79-04db-4ea4-bb69-d20aab6f1d62", client, release_status="in progress")
108+
>>> dataset = DatasetVersion.from_id("17196b79-04db-4ea4-bb69-d20aab6f1d62", client)
97109
```
98110

111+
### Following links in the knowledge graph
112+
99113
Links between metadata in the Knowledge Graph are not followed automatically,
100114
to avoid unnecessary network traffic, but can be followed with the `resolve()` method:
101115

102116
```
103-
>>> license = dataset.license.resolve(client, release_status="in progress")
104-
>>> authors = [author.resolve(client, release_status="in progress") for author in dataset.authors]
117+
>>> license = dataset.license.resolve(client)
118+
>>> authors = [author.resolve(client) for author in dataset.get_authors(client)]
105119
```
106120

107-
The associated metadata is accessible as attributes of the Python objects, e.g.:
121+
If you know in advance which links you wish to follow, you can use the `follow_links` option:
108122

109123
```
110-
>>> print(dataset.version_innovation)
111-
This is the first version of this research product.
124+
>>> dataset = DatasetVersion.from_id(
125+
... "17196b79-04db-4ea4-bb69-d20aab6f1d62",
126+
... client,
127+
... follow_links={
128+
... "license": {},
129+
... "is_version_of": {
130+
... "authors": {}
131+
... }
132+
... }
133+
... )
134+
>>> dataset.is_version_of[0].authors[0].given_name
135+
'Francesca'
136+
>>> dataset.license.short_name
137+
'CC-BY-NC-SA-4.0'
112138
```
113139

140+
Note that this can also be used to follow multiple links in the graph;
141+
in the example above we asked for the authors of the parent `Dataset`.
142+
114143
To print out all the metadata for a given object, use the `show()` method:
115144

116145
```
@@ -122,13 +151,6 @@ alias CC BY-NC-SA 4.0
122151
webpages ['https://creativecommons.org/licenses/by-nc-sa/4.0', 'https://spdx.org/licenses/CC-BY-NC-SA-4.0.html']
123152
```
124153

125-
You can also access any associated data:
126-
127-
```
128-
>>> dataset.download(client, local_directory=dataset.alias)
129-
```
130-
131-
132154
## Storing and editing metadata
133155

134156
For those users who have the necessary permissions to store and edit metadata in the Knowledge Graph,

0 commit comments

Comments
 (0)