Skip to content

Commit f43deff

Browse files
committed
add _iter method example to example.py
1 parent bb21aac commit f43deff

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

example.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99

1010
from dspace_rest_client.client import DSpaceClient
1111
from dspace_rest_client.models import Community, Collection, Item, Bundle, Bitstream
12+
import os
1213

13-
# Example variables needed for authentication and basic API requests
14-
# SET THESE TO MATCH YOUR TEST SYSTEM BEFORE RUNNING THE EXAMPLE SCRIPT
15-
# You can also leave them out of the constructor and set environment variables instead:
16-
# DSPACE_API_ENDPOINT=
17-
# DSPACE_API_USERNAME=
18-
# DSPACE_API_PASSWORD=
19-
# USER_AGENT=
14+
# The DSpace client will look for the same environment variables but we can also look for them here explicitly
15+
# and as an example
2016
url = 'http://localhost:8080/server/api'
17+
if 'DSPACE_API_ENDPOINT' in os.environ:
18+
url = os.environ['DSPACE_API_ENDPOINT']
2119
username = '[email protected]'
20+
if 'DSPACE_API_USERNAME' in os.environ:
21+
username = os.environ['DSPACE_API_USERNAME']
2222
password = 'password'
23+
if 'DSPACE_API_PASSWORD' in os.environ:
24+
password = os.environ['DSPACE_API_PASSWORD']
2325

2426
# Instantiate DSpace client
2527
# Note the 'fake_user_agent' setting here -- this will set a string like the following, to get by Cloudfront:
@@ -221,3 +223,8 @@
221223
# print, or write to file, etc. You want to use the 'content' property of the response object
222224
#
223225
# print(r.content)
226+
227+
# Finally, let's show the new _iter methods which will transparently handle pagination and return iterators
228+
# which you can use as normal
229+
for i, search_result in enumerate(d.search_objects_iter('*:*')):
230+
print(f'Result #{i}: {search_result.name} ({search_result.uuid})')

0 commit comments

Comments
 (0)