Skip to content

Commit 2ffde53

Browse files
committed
add sample file to retrieve item api endpoints data
1 parent 53f0193 commit 2ffde53

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

example_item_gets.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# This software is licenced under the BSD 3-Clause licence
2+
# available at https://opensource.org/licenses/BSD-3-Clause
3+
# and described in the LICENCE file in the root of this project
4+
5+
"""
6+
Example Python 3 application using the dspace.py API client library to demonstrate
7+
various GET functionalities for items in a DSpace 7 repository.
8+
"""
9+
from pprint import pprint
10+
11+
import os
12+
import sys
13+
14+
from dspace_rest_client.client import DSpaceClient
15+
from dspace_rest_client.models import Item
16+
17+
DEFAULT_URL = "https://localhost:8080/server/api"
18+
DEFAULT_USERNAME = "username@test.system.edu"
19+
DEFAULT_PASSWORD = "password"
20+
21+
# UUID of the item to retrieve
22+
ITEM_UUID = "0128787c-6f79-4661-aea4-11635d6fb04f"
23+
24+
# Configuration from environment variables
25+
URL = os.environ.get("DSPACE_API_ENDPOINT", DEFAULT_URL)
26+
USERNAME = os.environ.get("DSPACE_API_USERNAME", DEFAULT_USERNAME)
27+
PASSWORD = os.environ.get("DSPACE_API_PASSWORD", DEFAULT_PASSWORD)
28+
29+
# Instantiate DSpace client
30+
d = DSpaceClient(
31+
api_endpoint=URL, username=USERNAME, password=PASSWORD, fake_user_agent=True
32+
)
33+
34+
# Authenticate against the DSpace client
35+
authenticated = d.authenticate()
36+
if not authenticated:
37+
print("Error logging in! Giving up.")
38+
sys.exit(1)
39+
40+
# Retrieve item by UUID
41+
item = d.get_item(uuid=ITEM_UUID)
42+
if not item:
43+
print(f"Item with UUID {ITEM_UUID} not found!")
44+
sys.exit(1)
45+
46+
print("Retrieved Item:")
47+
pprint(item.as_dict())
48+
49+
# Get item metrics
50+
metrics = d.get_item_metrics(item)
51+
print("\nItem Metrics:")
52+
pprint(metrics if metrics else "No metrics available.")
53+
54+
# Get item thumbnail
55+
thumbnail = d.get_item_thumbnail(item)
56+
print("\nItem Thumbnail:")
57+
pprint(thumbnail if thumbnail else "No thumbnail available.")
58+
59+
# Get item owning collection
60+
owning_collection = d.get_item_owning_collection(item)
61+
print("\nOwning Collection:")
62+
pprint(
63+
owning_collection.as_dict() if owning_collection else "No owning collection found."
64+
)
65+
66+
# Get item mapped collections
67+
mapped_collections = d.get_item_mapped_collections(item)
68+
print("\nMapped Collections:")
69+
pprint(mapped_collections if mapped_collections else "No mapped collections available.")
70+
71+
# Get item relationships
72+
relationships = d.get_item_relationships(item)
73+
print("\nItem Relationships:")
74+
pprint(relationships if relationships else "No relationships found.")
75+
76+
# Get item access status
77+
access_status = d.get_item_access_status(item)
78+
print("\nItem Access Status:")
79+
pprint(access_status if access_status else "No access status available.")

0 commit comments

Comments
 (0)