aind-data-access-api 1.9.3__tar.gz → 1.10.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 (63) hide show
  1. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/PKG-INFO +1 -1
  2. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/ExamplesDocDBRestApi.rst +8 -1
  3. aind_data_access_api-1.10.0/src/aind_data_access_api/__init__.py +3 -0
  4. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/helpers/docdb.py +59 -1
  5. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api.egg-info/PKG-INFO +1 -1
  6. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/helpers/test_docdb.py +34 -2
  7. aind_data_access_api-1.9.3/src/aind_data_access_api/__init__.py +0 -3
  8. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.flake8 +0 -0
  9. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  10. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  11. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.github/ISSUE_TEMPLATE/user-story.md +0 -0
  12. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.github/workflows/add_issue_to_project_board.yml +0 -0
  13. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.github/workflows/publish_main.yml +0 -0
  14. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.github/workflows/run_dev_tests.yml +0 -0
  15. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.github/workflows/run_main_tests.yml +0 -0
  16. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.gitignore +0 -0
  17. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/.readthedocs.yaml +0 -0
  18. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/CODE_OF_CONDUCT.md +0 -0
  19. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/LICENSE +0 -0
  20. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/README.md +0 -0
  21. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/Makefile +0 -0
  22. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/make.bat +0 -0
  23. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/Contributing.rst +0 -0
  24. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/ExamplesDocDBDirectConnection.rst +0 -0
  25. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/Helpers.rst +0 -0
  26. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/UserGuide.rst +0 -0
  27. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/_static/dark-logo.svg +0 -0
  28. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/_static/favicon.ico +0 -0
  29. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/_static/light-logo.svg +0 -0
  30. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/aind_data_access_api.helpers.rst +0 -0
  31. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/aind_data_access_api.rst +0 -0
  32. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/conf.py +0 -0
  33. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/index.rst +0 -0
  34. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/docs/source/modules.rst +0 -0
  35. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/pyproject.toml +0 -0
  36. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/setup.cfg +0 -0
  37. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/setup.py +0 -0
  38. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/credentials.py +0 -0
  39. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/document_db.py +0 -0
  40. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/document_db_ssh.py +0 -0
  41. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/helpers/__init__.py +0 -0
  42. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/helpers/data_schema.py +0 -0
  43. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/rds_tables.py +0 -0
  44. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/secrets.py +0 -0
  45. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api/utils.py +0 -0
  46. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api.egg-info/SOURCES.txt +0 -0
  47. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api.egg-info/dependency_links.txt +0 -0
  48. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api.egg-info/requires.txt +0 -0
  49. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/src/aind_data_access_api.egg-info/top_level.txt +0 -0
  50. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/__init__.py +0 -0
  51. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/helpers/__init__.py +0 -0
  52. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/helpers/test_data_schema.py +0 -0
  53. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/resources/helpers/quality_control.json +0 -0
  54. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/resources/helpers/quality_control_invalid.json +0 -0
  55. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/resources/utils/example_metadata.nd.json +0 -0
  56. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/resources/utils/example_metadata1.nd.json +0 -0
  57. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/resources/utils/example_metadata2.nd.json +0 -0
  58. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/test_credentials.py +0 -0
  59. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/test_document_db.py +0 -0
  60. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/test_document_db_ssh.py +0 -0
  61. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/test_rds_tables.py +0 -0
  62. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/test_secrets_access.py +0 -0
  63. {aind_data_access_api-1.9.3 → aind_data_access_api-1.10.0}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aind-data-access-api
3
- Version: 1.9.3
3
+ Version: 1.10.0
4
4
  Summary: API to interact with a few AIND databases
5
5
  Author: Allen Institute for Neural Dynamics
6
6
  License: MIT
@@ -192,9 +192,16 @@ It's possible to attach a custom Session to retry certain requests errors:
192
192
 
193
193
  Updating Metadata
194
194
  ~~~~~~~~~~~~~~~~~~~~~~
195
+ .. note::
196
+
197
+ Manual updates to metadata in DocDB should be made through the
198
+ `aind-data-migration-scripts <https://github.com/AllenNeuralDynamics/aind-data-migration-scripts>`_
199
+ repository to track changes. Please see the README in that repository for instructions.
200
+
201
+ For special use cases, a minimal example of updating metadata directly using the API is provided below.
195
202
 
196
203
  1. **Permissions**: Request permissions for AWS Credentials to write to DocDB through the API Gateway.
197
- Note that the asset de/registration endpoints are intended for administrative use and require elevated AWS credentials/permissions.
204
+ Note that the asset de/registration endpoints are intended for administrative use and require elevated AWS credentials/permissions.
198
205
  2. **Query DocDB**: Filter for the records you want to update.
199
206
  3. **Update DocDB**: Use ``upsert_one_docdb_record`` or ``upsert_list_of_docdb_records`` to update the records.
200
207
 
@@ -0,0 +1,3 @@
1
+ """Init package"""
2
+
3
+ __version__ = "1.10.0"
@@ -37,7 +37,7 @@ def get_projection_by_id(
37
37
  """
38
38
  Download a record from docdb using the record _id and a projection.
39
39
 
40
- Projections return fields set to 1 {"field": 1}
40
+ Projections return fields set to 1, e.g. {"field": 1}
41
41
 
42
42
  Parameters
43
43
  ----------
@@ -137,3 +137,61 @@ def get_name_from_id(
137
137
  if len(records) == 0:
138
138
  raise ValueError(f"No record found with _id {_id}")
139
139
  return records[0]["name"]
140
+
141
+
142
+ def get_record_by_name(
143
+ client: MetadataDbClient,
144
+ name: str,
145
+ ) -> Optional[dict]:
146
+ """
147
+ Download a record from docdb using the record name.
148
+
149
+ Parameters
150
+ ----------
151
+ client : MetadataDbClient
152
+ name : str
153
+
154
+ Returns
155
+ -------
156
+ Optional[dict]
157
+ None if record does not exist. Otherwise, it will return the record as
158
+ a dict.
159
+ """
160
+ records = client.retrieve_docdb_records(
161
+ filter_query={"name": name}, limit=1
162
+ )
163
+ if len(records) > 0:
164
+ return records[0]
165
+ else:
166
+ return None
167
+
168
+
169
+ def get_projection_by_name(
170
+ client: MetadataDbClient,
171
+ name: str,
172
+ projection: dict,
173
+ ) -> Optional[dict]:
174
+ """
175
+ Download a record from docdb using the record name and a projection.
176
+
177
+ Projections return fields set to 1, e.g. {"field": 1}
178
+
179
+ Parameters
180
+ ----------
181
+ client : MetadataDbClient
182
+ name : str
183
+ projection : dict
184
+
185
+ Returns
186
+ -------
187
+ Optional[dict]
188
+ None if record does not exist. Otherwise, it will return the projected
189
+ record as a dict.
190
+ """
191
+ records = client.retrieve_docdb_records(
192
+ filter_query={"name": name}, projection=projection, limit=1
193
+ )
194
+ if len(records) > 0:
195
+ return records[0]
196
+ else:
197
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aind-data-access-api
3
- Version: 1.9.3
3
+ Version: 1.10.0
4
4
  Summary: API to interact with a few AIND databases
5
5
  Author: Allen Institute for Neural Dynamics
6
6
  License: MIT
@@ -8,7 +8,9 @@ from aind_data_access_api.helpers.docdb import (
8
8
  get_id_from_name,
9
9
  get_name_from_id,
10
10
  get_projection_by_id,
11
+ get_projection_by_name,
11
12
  get_record_by_id,
13
+ get_record_by_name,
12
14
  )
13
15
 
14
16
 
@@ -75,8 +77,8 @@ class TestHelpersDocDB(unittest.TestCase):
75
77
  record = get_record_by_id(client, _id="abcd")
76
78
  self.assertIsNone(record)
77
79
 
78
- def test_get_projected_record_from_docdb(self):
79
- """Tests get_projected_record_from_docdb"""
80
+ def test_get_projection_by_id(self):
81
+ """Tests get_projection_by_id"""
80
82
  client = MagicMock()
81
83
  client.retrieve_docdb_records.return_value = [
82
84
  {"quality_control": {"a": 1}}
@@ -95,6 +97,36 @@ class TestHelpersDocDB(unittest.TestCase):
95
97
  field = get_field_by_id(client, _id="abcd", field="quality_control")
96
98
  self.assertEqual({"quality_control": {"a": 1}}, field)
97
99
 
100
+ def test_get_record_by_name(self):
101
+ """Tests get_record_by_name"""
102
+ client = MagicMock()
103
+ client.retrieve_docdb_records.return_value = [{"name": "abcd"}]
104
+ record = get_record_by_name(client=client, name="abcd")
105
+ self.assertEqual({"name": "abcd"}, record)
106
+
107
+ # test the empty case
108
+ client.retrieve_docdb_records.return_value = []
109
+ record = get_record_by_name(client=client, name="abcd")
110
+ self.assertIsNone(record)
111
+
112
+ def test_get_projection_by_name(self):
113
+ """Tests get_projection_by_name"""
114
+ client = MagicMock()
115
+ client.retrieve_docdb_records.return_value = [
116
+ {"quality_control": {"a": 1}}
117
+ ]
118
+ record = get_projection_by_name(
119
+ client=client, name="abcd", projection={"quality_control": 1}
120
+ )
121
+ self.assertEqual({"quality_control": {"a": 1}}, record)
122
+
123
+ # test the empty case
124
+ client.retrieve_docdb_records.return_value = []
125
+ record = get_projection_by_name(
126
+ client=client, name="abcd", projection={"quality_control": 1}
127
+ )
128
+ self.assertIsNone(record)
129
+
98
130
 
99
131
  if __name__ == "__main__":
100
132
  unittest.main()
@@ -1,3 +0,0 @@
1
- """Init package"""
2
-
3
- __version__ = "1.9.3"