caltechdata-api 1.4.5__tar.gz → 1.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. caltechdata_api-1.6.0/PKG-INFO +100 -0
  2. caltechdata_api-1.6.0/README.md +78 -0
  3. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/caltechdata_edit.py +33 -10
  4. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/caltechdata_write.py +3 -9
  5. caltechdata_api-1.6.0/caltechdata_api/cli.py +608 -0
  6. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/customize_schema.py +28 -22
  7. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/get_metadata.py +7 -1
  8. caltechdata_api-1.6.0/caltechdata_api/md_to_json.py +139 -0
  9. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/utils.py +0 -1
  10. caltechdata_api-1.6.0/caltechdata_api.egg-info/PKG-INFO +100 -0
  11. caltechdata_api-1.6.0/caltechdata_api.egg-info/SOURCES.txt +19 -0
  12. caltechdata_api-1.6.0/caltechdata_api.egg-info/entry_points.txt +3 -0
  13. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api.egg-info/requires.txt +2 -0
  14. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/setup.py +14 -1
  15. caltechdata_api-1.4.5/PKG-INFO +0 -81
  16. caltechdata_api-1.4.5/README.md +0 -62
  17. caltechdata_api-1.4.5/caltechdata_api/vocabularies/date_types.yaml +0 -55
  18. caltechdata_api-1.4.5/caltechdata_api/vocabularies/description_types.yaml +0 -34
  19. caltechdata_api-1.4.5/caltechdata_api/vocabularies/identifier_types.yaml +0 -110
  20. caltechdata_api-1.4.5/caltechdata_api/vocabularies/licenses.csv +0 -419
  21. caltechdata_api-1.4.5/caltechdata_api/vocabularies/relation_types.yaml +0 -155
  22. caltechdata_api-1.4.5/caltechdata_api/vocabularies/resource_types.yaml +0 -675
  23. caltechdata_api-1.4.5/caltechdata_api/vocabularies/roles.yaml +0 -105
  24. caltechdata_api-1.4.5/caltechdata_api/vocabularies/title_types.yaml +0 -20
  25. caltechdata_api-1.4.5/caltechdata_api/vocabularies.yaml +0 -24
  26. caltechdata_api-1.4.5/caltechdata_api.egg-info/PKG-INFO +0 -81
  27. caltechdata_api-1.4.5/caltechdata_api.egg-info/SOURCES.txt +0 -28
  28. caltechdata_api-1.4.5/tests/test_conversion.py +0 -64
  29. caltechdata_api-1.4.5/tests/test_download.py +0 -27
  30. caltechdata_api-1.4.5/tests/test_rdm.py +0 -68
  31. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/LICENSE +0 -0
  32. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/__init__.py +0 -0
  33. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/download_file.py +0 -0
  34. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api/get_files.py +0 -0
  35. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api.egg-info/dependency_links.txt +0 -0
  36. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/caltechdata_api.egg-info/top_level.txt +0 -0
  37. {caltechdata_api-1.4.5 → caltechdata_api-1.6.0}/setup.cfg +0 -0
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.1
2
+ Name: caltechdata_api
3
+ Version: 1.6.0
4
+ Summary: Python wrapper for CaltechDATA API.
5
+ Home-page: https://github.com/caltechlibrary/caltechdata_api
6
+ Author: Thomas E Morrell
7
+ Author-email: tmorrell@caltech.edu
8
+ License: https://data.caltech.edu/license
9
+ Platform: UNKNOWN
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: Implementation :: CPython
15
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
16
+ Requires-Python: >=3.6.0
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+
20
+
21
+ # CaltechDATA API Python Library
22
+
23
+ The `caltechdata_api` Python library provides a convenient interface for interacting with the CaltechDATA API. It allows users to write files, create DataCite 4 standard JSON records, edit existing records, and retrieve metadata from the CaltechDATA repository.
24
+
25
+ ## Features
26
+
27
+ ### Writing and Editing Records
28
+ - `caltechdata_write`: Writes files and a DataCite 4 standard JSON record to the CaltechDATA repository.
29
+ - `caltechdata_edit`: Edits existing records in CaltechDATA.
30
+
31
+ ### Metadata Operations
32
+ - `get_metadata`: Retrieves metadata from CaltechDATA records.
33
+
34
+ ## Requirements
35
+
36
+ - Python 3 (Anaconda is recommended)
37
+ - `requests` library
38
+
39
+ ## Installation
40
+
41
+ Install the library via pip:
42
+
43
+ ```shell
44
+ pip install caltechdata_api
45
+ ```
46
+
47
+ ## Examples
48
+
49
+ There are some example python scripts in the GitHub repository.
50
+
51
+ ###Create a record:
52
+
53
+ ```shell
54
+ python write.py example.json -fnames logo.gif
55
+ # Output: pbkn6-m9y63 (unique identifier)
56
+ ```
57
+ > The response will be the unique identifier for the record. You can put this at
58
+ the end of a url to visit the record (e.g.
59
+ https://data.caltechlibrary.dev/records/pbkn6-m9y63)
60
+
61
+ ###Edit a record
62
+ Make changes to the example.json file to see a change)
63
+ ```
64
+ python edit.py example.json -id pbkn6-m9y63
65
+ 10.33569/pbkn6-m9y63
66
+ ```
67
+ > The response is the DOI for the record, which includes the unique identifier
68
+ for the record in the default configuration.
69
+
70
+ ## Using Custom DOIs
71
+ Some groups have worked with the library to create custom DOIs. These can be
72
+ passed in the metadata like:
73
+
74
+ ```shell
75
+ python write.py example_custom.json -fnames logo.gif
76
+ m6zxz-p4j22
77
+ ```
78
+
79
+ And then you can edit with
80
+ ```
81
+ python edit.py example_custom.json -id m6zxz-p4j22
82
+ 10.5281/inveniordm.1234
83
+ ```
84
+
85
+ This returns the custom DOI of the record if it is successful.
86
+
87
+
88
+ ## Setup and Authentication
89
+
90
+ 1. Acquire a personal access token from your CaltechDATA account (found under "Applications" at the top right of your screen).
91
+ 2. Copy the token to a file named token.bash.
92
+ 3. Load the token in the command line using source token.bash.
93
+
94
+ ## Note on Testing
95
+
96
+ Only test your application on the test repository (`data.caltechlibrary.dev`). Testing the API on the public
97
+ repository will generate junk records that are annoying to delete.
98
+
99
+
100
+
@@ -0,0 +1,78 @@
1
+ # CaltechDATA API Python Library
2
+
3
+ The `caltechdata_api` Python library provides a convenient interface for interacting with the CaltechDATA API. It allows users to write files, create DataCite 4 standard JSON records, edit existing records, and retrieve metadata from the CaltechDATA repository.
4
+
5
+ ## Features
6
+
7
+ ### Writing and Editing Records
8
+ - `caltechdata_write`: Writes files and a DataCite 4 standard JSON record to the CaltechDATA repository.
9
+ - `caltechdata_edit`: Edits existing records in CaltechDATA.
10
+
11
+ ### Metadata Operations
12
+ - `get_metadata`: Retrieves metadata from CaltechDATA records.
13
+
14
+ ## Requirements
15
+
16
+ - Python 3 (Anaconda is recommended)
17
+ - `requests` library
18
+
19
+ ## Installation
20
+
21
+ Install the library via pip:
22
+
23
+ ```shell
24
+ pip install caltechdata_api
25
+ ```
26
+
27
+ ## Examples
28
+
29
+ There are some example python scripts in the GitHub repository.
30
+
31
+ ###Create a record:
32
+
33
+ ```shell
34
+ python write.py example.json -fnames logo.gif
35
+ # Output: pbkn6-m9y63 (unique identifier)
36
+ ```
37
+ > The response will be the unique identifier for the record. You can put this at
38
+ the end of a url to visit the record (e.g.
39
+ https://data.caltechlibrary.dev/records/pbkn6-m9y63)
40
+
41
+ ###Edit a record
42
+ Make changes to the example.json file to see a change)
43
+ ```
44
+ python edit.py example.json -id pbkn6-m9y63
45
+ 10.33569/pbkn6-m9y63
46
+ ```
47
+ > The response is the DOI for the record, which includes the unique identifier
48
+ for the record in the default configuration.
49
+
50
+ ## Using Custom DOIs
51
+ Some groups have worked with the library to create custom DOIs. These can be
52
+ passed in the metadata like:
53
+
54
+ ```shell
55
+ python write.py example_custom.json -fnames logo.gif
56
+ m6zxz-p4j22
57
+ ```
58
+
59
+ And then you can edit with
60
+ ```
61
+ python edit.py example_custom.json -id m6zxz-p4j22
62
+ 10.5281/inveniordm.1234
63
+ ```
64
+
65
+ This returns the custom DOI of the record if it is successful.
66
+
67
+
68
+ ## Setup and Authentication
69
+
70
+ 1. Acquire a personal access token from your CaltechDATA account (found under "Applications" at the top right of your screen).
71
+ 2. Copy the token to a file named token.bash.
72
+ 3. Load the token in the command line using source token.bash.
73
+
74
+ ## Note on Testing
75
+
76
+ Only test your application on the test repository (`data.caltechlibrary.dev`). Testing the API on the public
77
+ repository will generate junk records that are annoying to delete.
78
+
@@ -33,7 +33,6 @@ def caltechdata_accept(ids, token=None, production=False):
33
33
  }
34
34
 
35
35
  for idv in ids:
36
-
37
36
  result = requests.get(
38
37
  url + "/api/records/" + idv + "/draft/review", headers=headers
39
38
  )
@@ -65,6 +64,7 @@ def caltechdata_edit(
65
64
  file_descriptions=[],
66
65
  s3_link=None,
67
66
  default_preview=None,
67
+ authors=False,
68
68
  ):
69
69
  # Make a copy of the metadata to make sure our local changes don't leak
70
70
  metadata = copy.deepcopy(metadata)
@@ -104,10 +104,16 @@ def caltechdata_edit(
104
104
  metadata, ex_file_links, file_descriptions, s3_link=s3_link
105
105
  )
106
106
 
107
- if production == True:
108
- url = "https://data.caltech.edu"
107
+ if authors == False:
108
+ if production == True:
109
+ url = "https://data.caltech.edu/"
110
+ else:
111
+ url = "https://data.caltechlibrary.dev/"
109
112
  else:
110
- url = "https://data.caltechlibrary.dev"
113
+ if production == True:
114
+ url = "https://authors.library.caltech.edu/"
115
+ else:
116
+ url = "https://authors.caltechlibrary.dev/"
111
117
 
112
118
  headers = {
113
119
  "Authorization": "Bearer %s" % token,
@@ -156,8 +162,12 @@ def caltechdata_edit(
156
162
 
157
163
  print(idv)
158
164
  # Pull out pid information
165
+ # Not currently used for authors
159
166
  if production == True:
160
- repo_prefix = "10.22002"
167
+ if authors == True:
168
+ repo_prefix = "10.7907"
169
+ else:
170
+ repo_prefix = "10.22002"
161
171
  else:
162
172
  repo_prefix = "10.33569"
163
173
  pids = {}
@@ -209,8 +219,18 @@ def caltechdata_edit(
209
219
  # We want to have the system set new DOIs
210
220
  data["pids"] = {}
211
221
  else:
212
- metadata["pids"] = pids
213
- data = customize_schema.customize_schema(metadata, schema=schema)
222
+ if authors == False:
223
+ metadata["pids"] = pids
224
+ data = customize_schema.customize_schema(metadata, schema=schema)
225
+ else:
226
+ # Authors, force oai PID
227
+ if "pids" not in metadata:
228
+ metadata["pids"] = {}
229
+ metadata["pids"]["oai"] = {
230
+ "identifier": f"oai:authors.library.caltech.edu:{idv}",
231
+ "provider": "oai",
232
+ }
233
+ data = metadata
214
234
 
215
235
  if files:
216
236
  if default_preview:
@@ -250,7 +270,7 @@ def caltechdata_edit(
250
270
  if result.status_code != 200:
251
271
  raise Exception(result.text)
252
272
  # We want files to stay the same as the existing record
253
- data["files"] = existing.json()["files"]
273
+ data["files"] = existing["files"]
254
274
  if default_preview:
255
275
  data["files"]["default_preview"] = default_preview
256
276
  # Update metadata
@@ -267,7 +287,10 @@ def caltechdata_edit(
267
287
  result = requests.post(publish_link, headers=headers)
268
288
  if result.status_code != 202:
269
289
  raise Exception(result.text)
270
- doi = result.json()["pids"]["doi"]["identifier"]
271
- return doi
290
+ pids = result.json()["pids"]
291
+ if "doi" in pids:
292
+ return pids["doi"]["identifier"]
293
+ else:
294
+ return pids["oai"]["identifier"]
272
295
  else:
273
296
  return idv
@@ -67,9 +67,9 @@ def write_files_rdm(files, file_link, headers, f_headers, s3=None):
67
67
  def add_file_links(
68
68
  metadata, file_links, file_descriptions=[], additional_descriptions="", s3_link=None
69
69
  ):
70
- # Currently configured for OSN S3 links
70
+ # Currently configured for S3 links, assuming all are at same endpoint
71
71
  link_string = ""
72
- endpoint = "https://renc.osn.xsede.org/"
72
+ endpoint = "https://" + file_links[0].split("/")[2]
73
73
  s3 = s3fs.S3FileSystem(anon=True, client_kwargs={"endpoint_url": endpoint})
74
74
  index = 0
75
75
  for link in file_links:
@@ -102,7 +102,6 @@ def add_file_links(
102
102
 
103
103
 
104
104
  def send_to_community(review_link, data, headers, publish, community, message=None):
105
-
106
105
  if not message:
107
106
  message = "This record is submitted automatically with the CaltechDATA API"
108
107
 
@@ -189,6 +188,7 @@ def caltechdata_write(
189
188
  elif "identifiers" in metadata:
190
189
  identifiers = metadata["identifiers"]
191
190
  for identifier in identifiers:
191
+ doi = False
192
192
  if "identifierType" in identifier:
193
193
  if identifier["identifierType"] == "DOI":
194
194
  doi = identifier["identifier"]
@@ -198,17 +198,11 @@ def caltechdata_write(
198
198
  "identifier": identifier["identifier"],
199
199
  "provider": "oai",
200
200
  }
201
- else:
202
- doi = False
203
201
  elif "scheme" in identifier:
204
202
  # We have RDM internal metadata
205
203
  if identifier["scheme"] == "doi":
206
204
  doi = identifier["identifier"]
207
205
  prefix = doi.split("/")[0]
208
- else:
209
- doi = False
210
- else:
211
- doi = False
212
206
  if doi != False:
213
207
  if prefix == repo_prefix:
214
208
  pids["doi"] = {