Get UUID#
The api.get_uuid
api endpoint is a utility function for finding database entities across database models.
Example#
We can easily find a specific record by UUID. If you populated the default Keyword
, you will find a record of UUID 885735f3-121e-4ca0-ac8b-f37dbc972f03
. The get_uuid
will figure out, what kind of database model has to be loaded.
[1]:
from metacatalog import api
session = api.connect_database()
keyword = api.get_uuid(session, uuid='885735f3-121e-4ca0-ac8b-f37dbc972f03')
print(keyword)
EARTH SCIENCE > TERRESTRIAL HYDROSPHERE <ID=25>
While Keyword
is already capable of loading all child keywords recursively, we can easily rebuild this function using the get_uuid
function. This can be very helpful, when a list of objects needs to be loaded from metacatalog
.
[2]:
import json
kw_dict = keyword.to_dict(deep=False)
print('Parent object\n' + '#' * 40)
print(json.dumps(kw_dict, indent=4))
# load the children
print('\nChildren:\n' + '#' * 40)
for uuid in kw_dict.get('children', []):
print(api.get_uuid(session, uuid=uuid).full_path)
Parent object
########################################
{
"id": 25,
"uuid": "885735f3-121e-4ca0-ac8b-f37dbc972f03",
"value": "TERRESTRIAL HYDROSPHERE",
"path": "EARTH SCIENCE > TERRESTRIAL HYDROSPHERE",
"children": [
"099ab1ae-f4d2-48cc-be2f-86bd58ffc4ca",
"734f8f27-6976-4b67-8794-c7fc79d6161e",
"50b8fe04-9149-4b7f-a8b2-b33b1e3aa192",
"5debb283-51e4-435e-b2a2-e8e2a977220d",
"8c02f5d1-ce86-4bf5-84d5-b3496cdba6ad"
],
"thesaurus_id": 1
}
Children:
########################################
EARTH SCIENCE > TERRESTRIAL HYDROSPHERE > GLACIERS/ICE SHEETS
EARTH SCIENCE > TERRESTRIAL HYDROSPHERE > GROUND WATER
EARTH SCIENCE > TERRESTRIAL HYDROSPHERE > SNOW/ICE
EARTH SCIENCE > TERRESTRIAL HYDROSPHERE > SURFACE WATER
EARTH SCIENCE > TERRESTRIAL HYDROSPHERE > WATER QUALITY/WATER CHEMISTRY
Funtion#
- metacatalog.api.get_uuid(as_result: typing_extensions.Literal[False] = False) 'Entry' | 'EntryGroup' | 'Person' | 'Keyword' | None #
- metacatalog.api.get_uuid(as_result: typing_extensions.Literal[True] = False) ImmutableResultSet
Return the Metacatalog object of given version 4 UUID. The supported objects are:
Entry
EntryGroup
Keyword
Person
New in version 0.1.13.
Changed in version 0.2.7: Now, also
Persons
can be found by UUIDChanged in version 0.7.5: Found Entry and EntryGroup can be returned as ImmutableResultSet now.
- Parameters:
session (sqlalchemy.Session) – SQLAlchemy session connected to the database.
uuid (str) – Find by version 4 UUID.
as_result (bool) –
New in version 0.7.5.
If True, the found Entry or Entrygroup will be merged into a
ImmutableResultSet
. Ignored for matched Keyword and Person. Defaults to False.
- Returns:
record – Matched Entry, EntryGroup, Keyword, Person or ImmutableResultSet. If no match was found, None is returned.
- Return type:
Entry, EntryGroup, Keyword, Person, ImmutableResultSet, None