Ontology Operations
Find Ontologies
The find_ontologies function allows you to retrieve a list of ontologies from the Perseus server based on specified criteria.
Synchronous
find_ontologies
def find_ontologies(
ids: Optional[list[str]] = None,
source_hashes: Optional[list[str]] = None,
) -> list[Ontology]:Finds ontologies matching the provided IDs or source hashes.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
ids | Optional[List[str]] | A list of ontology IDs to retrieve. | None |
source_hashes | Optional[List[str]] | A list of source hashes to retrieve ontologies by. | None |
Returns
| Type | Description |
|---|---|
List[Ontology] | A list of Ontology objects that match the query. |
Example
import perseus_client
try:
# Find by IDs
ontologies_by_id = perseus_client.find_ontologies(ids=["ont_id_1", "ont_id_2"])
print(f"Found {len(ontologies_by_id)} ontologies by ID.")
# Find by source hashes
ontologies_by_hash = perseus_client.find_ontologies(source_hashes=["hash1", "hash2"])
print(f"Found {len(ontologies_by_hash)} ontologies by source hash.")
except Exception as e:
print(f"An error occurred: {e}")Asynchronous
find_ontologies_async
async def find_ontologies_async(
ids: Optional[list[str]] = None,
source_hashes: Optional[list[str]] = None,
) -> list[Ontology]:Asynchronously finds ontologies matching the provided IDs or source hashes.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
ids | Optional[List[str]] | A list of ontology IDs to retrieve. | None |
source_hashes | Optional[List[str]] | A list of source hashes to retrieve ontologies by. | None |
Returns
| Type | Description |
|---|---|
List[Ontology] | A list of Ontology objects that match the query. |
Example
import asyncio
import perseus_client
async def main():
try:
# Find by IDs
ontologies_by_id = await perseus_client.find_ontologies_async(ids=["ont_id_1", "ont_id_2"])
print(f"Found {len(ontologies_by_id)} ontologies by ID.")
# Find by source hashes
ontologies_by_hash = await perseus_client.find_ontologies_async(source_hashes=["hash1", "hash2"])
print(f"Found {len(ontologies_by_hash)} ontologies by source hash.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
await perseus_client.close_async()
if __name__ == "__main__":
asyncio.run(main())