entitysdk 0.5.0__tar.gz → 0.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 (126) hide show
  1. {entitysdk-0.5.0/src/entitysdk.egg-info → entitysdk-0.6.0}/PKG-INFO +1 -1
  2. {entitysdk-0.5.0 → entitysdk-0.6.0}/examples/01_searching.ipynb +1 -15
  3. entitysdk-0.6.0/examples/02_morphology.ipynb +417 -0
  4. entitysdk-0.5.0/examples/04_circuit.ipynb → entitysdk-0.6.0/examples/03_circuit.ipynb +1 -15
  5. entitysdk-0.6.0/examples/04_simulation_campaign.ipynb +389 -0
  6. {entitysdk-0.5.0 → entitysdk-0.6.0}/pyproject.toml +1 -0
  7. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/client.py +152 -16
  8. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/core.py +90 -9
  9. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/__init__.py +15 -0
  10. entitysdk-0.6.0/src/entitysdk/models/activity.py +16 -0
  11. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/asset.py +41 -1
  12. entitysdk-0.6.0/src/entitysdk/models/classification.py +38 -0
  13. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/core.py +0 -4
  14. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/memodel.py +45 -7
  15. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/simulation_campaign.py +2 -0
  16. entitysdk-0.6.0/src/entitysdk/models/simulation_execution.py +10 -0
  17. entitysdk-0.6.0/src/entitysdk/models/simulation_generation.py +9 -0
  18. entitysdk-0.6.0/src/entitysdk/models/simulation_result.py +10 -0
  19. entitysdk-0.6.0/src/entitysdk/models/single_neuron_simulation.py +50 -0
  20. entitysdk-0.6.0/src/entitysdk/models/single_neuron_synaptome_simulation.py +51 -0
  21. entitysdk-0.6.0/src/entitysdk/models/synaptome.py +63 -0
  22. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/route.py +8 -0
  23. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/serdes.py +24 -3
  24. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/types.py +18 -0
  25. {entitysdk-0.5.0 → entitysdk-0.6.0/src/entitysdk.egg-info}/PKG-INFO +1 -1
  26. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk.egg-info/SOURCES.txt +10 -3
  27. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/integration/test_searching.py +6 -0
  28. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/ion_channel_model.json +1 -0
  29. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/reconstruction_morphology.json +2 -0
  30. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/simulation_campaign.json +1 -0
  31. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_asset.py +1 -0
  32. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_client.py +296 -31
  33. entitysdk-0.6.0/tests/unit/test_serdes.py +95 -0
  34. {entitysdk-0.5.0 → entitysdk-0.6.0}/tox.ini +1 -0
  35. entitysdk-0.5.0/examples/02_morphology.ipynb +0 -640
  36. entitysdk-0.5.0/examples/03_contribution.ipynb +0 -209
  37. entitysdk-0.5.0/examples/05_simulation_campaign.ipynb +0 -164
  38. entitysdk-0.5.0/tests/unit/test_serdes.py +0 -54
  39. {entitysdk-0.5.0 → entitysdk-0.6.0}/.github/workflows/sdist.yml +0 -0
  40. {entitysdk-0.5.0 → entitysdk-0.6.0}/.github/workflows/tox.yml +0 -0
  41. {entitysdk-0.5.0 → entitysdk-0.6.0}/.gitignore +0 -0
  42. {entitysdk-0.5.0 → entitysdk-0.6.0}/CHANGELOG.rst +0 -0
  43. {entitysdk-0.5.0 → entitysdk-0.6.0}/CONTRIBUTING.md +0 -0
  44. {entitysdk-0.5.0 → entitysdk-0.6.0}/LICENSE.txt +0 -0
  45. {entitysdk-0.5.0 → entitysdk-0.6.0}/README.md +0 -0
  46. {entitysdk-0.5.0 → entitysdk-0.6.0}/setup.cfg +0 -0
  47. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/__init__.py +0 -0
  48. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/common.py +0 -0
  49. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/config.py +0 -0
  50. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/downloaders/__init__.py +0 -0
  51. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/downloaders/emodel.py +0 -0
  52. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/downloaders/ion_channel_model.py +0 -0
  53. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/downloaders/memodel.py +0 -0
  54. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/downloaders/morphology.py +0 -0
  55. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/exception.py +0 -0
  56. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/mixin.py +0 -0
  57. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/agent.py +0 -0
  58. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/base.py +0 -0
  59. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/brain_location.py +0 -0
  60. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/brain_region.py +0 -0
  61. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/circuit.py +0 -0
  62. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/contribution.py +0 -0
  63. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/electrical_cell_recording.py +0 -0
  64. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/emodel.py +0 -0
  65. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/entity.py +0 -0
  66. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/etype.py +0 -0
  67. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/ion_channel_model.py +0 -0
  68. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/license.py +0 -0
  69. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/memodelcalibrationresult.py +0 -0
  70. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/morphology.py +0 -0
  71. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/mtype.py +0 -0
  72. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/response.py +0 -0
  73. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/scientific_artifact.py +0 -0
  74. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/simulation.py +0 -0
  75. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/subject.py +0 -0
  76. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/taxonomy.py +0 -0
  77. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/models/validation_result.py +0 -0
  78. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/result.py +0 -0
  79. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/schemas/__init__.py +0 -0
  80. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/schemas/asset.py +0 -0
  81. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/schemas/base.py +0 -0
  82. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/schemas/memodel.py +0 -0
  83. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/token_manager.py +0 -0
  84. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/util.py +0 -0
  85. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/utils/__init__.py +0 -0
  86. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/utils/asset.py +0 -0
  87. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk/utils/filesystem.py +0 -0
  88. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk.egg-info/dependency_links.txt +0 -0
  89. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk.egg-info/requires.txt +0 -0
  90. {entitysdk-0.5.0 → entitysdk-0.6.0}/src/entitysdk.egg-info/top_level.txt +0 -0
  91. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/__init__.py +0 -0
  92. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/integration/__init__.py +0 -0
  93. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/integration/conftest.py +0 -0
  94. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/__init__.py +0 -0
  95. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/conftest.py +0 -0
  96. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/downloaders/test_emodel.py +0 -0
  97. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/downloaders/test_ion_channel_model.py +0 -0
  98. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/downloaders/test_memodel.py +0 -0
  99. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/downloaders/test_morphology.py +0 -0
  100. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/__init__.py +0 -0
  101. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/.gitignore +0 -0
  102. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/circuit.json +0 -0
  103. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/electrical_cell_recording.json +0 -0
  104. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/memodel_calibration_result.json +0 -0
  105. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/data/validation_result.json +0 -0
  106. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_agent.py +0 -0
  107. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_brain_region.py +0 -0
  108. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_circuit.py +0 -0
  109. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_contribution.py +0 -0
  110. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_electrical_cell_recording.py +0 -0
  111. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_init.py +0 -0
  112. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_ion_channel_model.py +0 -0
  113. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_memodel_calibration_result.py +0 -0
  114. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_morphology.py +0 -0
  115. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_simulation_campaign.py +0 -0
  116. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/models/test_validation_result.py +0 -0
  117. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_base.py +0 -0
  118. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_common.py +0 -0
  119. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_config.py +0 -0
  120. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_result.py +0 -0
  121. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_route.py +0 -0
  122. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_token_manager.py +0 -0
  123. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/test_util.py +0 -0
  124. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/util.py +0 -0
  125. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/utils/test_asset.py +0 -0
  126. {entitysdk-0.5.0 → entitysdk-0.6.0}/tests/unit/utils/test_filesystem.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: entitysdk
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Python library for interacting with the entitycore service
5
5
  Author-email: Open Brain Institute <info@openbraininstitute.org>
6
6
  Maintainer-email: Open Brain Institute <info@openbraininstitute.org>
@@ -283,22 +283,8 @@
283
283
  }
284
284
  ],
285
285
  "metadata": {
286
- "kernelspec": {
287
- "display_name": "Python 3 (ipykernel)",
288
- "language": "python",
289
- "name": "python3"
290
- },
291
286
  "language_info": {
292
- "codemirror_mode": {
293
- "name": "ipython",
294
- "version": 3
295
- },
296
- "file_extension": ".py",
297
- "mimetype": "text/x-python",
298
- "name": "python",
299
- "nbconvert_exporter": "python",
300
- "pygments_lexer": "ipython3",
301
- "version": "3.12.10"
287
+ "name": "python"
302
288
  }
303
289
  },
304
290
  "nbformat": 4,
@@ -0,0 +1,417 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "47471adc-9c79-4262-9fc4-66f5579f14a8",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import io\n",
11
+ "import os\n",
12
+ "import tempfile\n",
13
+ "from pathlib import Path\n",
14
+ "\n",
15
+ "from rich import print as rprint\n",
16
+ "\n",
17
+ "from entitysdk.client import Client\n",
18
+ "from entitysdk.common import ProjectContext\n",
19
+ "from entitysdk.models import (\n",
20
+ " BrainLocation,\n",
21
+ " BrainRegion,\n",
22
+ " Contribution,\n",
23
+ " MTypeClass,\n",
24
+ " MTypeClassification,\n",
25
+ " Organization,\n",
26
+ " ReconstructionMorphology,\n",
27
+ " Role,\n",
28
+ " Species,\n",
29
+ " Strain,\n",
30
+ ")"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "markdown",
35
+ "id": "cacdf95f-d545-417b-b1bd-c8a5181c162f",
36
+ "metadata": {},
37
+ "source": [
38
+ "### Initialize the entitycore client"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": null,
44
+ "id": "5e4f4ff2-3d5b-4f3a-90a9-ea43d587ebce",
45
+ "metadata": {},
46
+ "outputs": [],
47
+ "source": [
48
+ "entitycore_api_url = \"http://127.0.0.1:8000\"\n",
49
+ "project_context = ProjectContext(\n",
50
+ " virtual_lab_id=\"a98b7abc-fc46-4700-9e3d-37137812c730\",\n",
51
+ " project_id=\"0dbced5f-cc3d-488a-8c7f-cfb8ea039dc6\",\n",
52
+ ")\n",
53
+ "token = os.getenv(\"ACCESS_TOKEN\", \"XXX\")\n",
54
+ "client = Client(api_url=entitycore_api_url, project_context=project_context, token_manager=token)\n",
55
+ "\n",
56
+ "\n",
57
+ "# uncomment for staging\n",
58
+ "# from obi_auth import get_token\n",
59
+ "# token = get_token(environment=\"staging\")\n",
60
+ "# Replace this with your vlab project url in staging\n",
61
+ "# project_context = ProjectContext.from_vlab_url(\"https://staging.openbraininstitute.org/app/virtual-lab/lab/594fd60d-7a38-436f-939d-500feaa13bba/project/ff89ca07-6613-4922-9ab0-2637221db8b5/home\")\n",
62
+ "# client = Client(environment=\"staging\", project_context=project_context)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "markdown",
67
+ "id": "15b1762d-11df-42be-bcff-5f42b03ab2cd",
68
+ "metadata": {},
69
+ "source": [
70
+ "## Search for entities"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": null,
76
+ "id": "93d30bc5-c40c-4a5d-ad9e-9b0c4abc3ef4",
77
+ "metadata": {},
78
+ "outputs": [],
79
+ "source": [
80
+ "species = client.search_entity(entity_type=Species, query={\"name\": \"Mus musculus\"}, limit=10).one()"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": null,
86
+ "id": "2a697b1d-2bdc-488d-8ce6-5f7547af87fe",
87
+ "metadata": {},
88
+ "outputs": [],
89
+ "source": [
90
+ "rprint(species)"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": null,
96
+ "id": "0ea7fd15-bf51-4039-a1fd-c580ce813ff3",
97
+ "metadata": {},
98
+ "outputs": [],
99
+ "source": [
100
+ "strain = client.search_entity(entity_type=Strain, query={\"name\": \"Cux2-CreERT2\"}).one()"
101
+ ]
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "execution_count": null,
106
+ "id": "e5dde536-0c58-4d42-a834-1b1a0ec17e9d",
107
+ "metadata": {},
108
+ "outputs": [],
109
+ "source": [
110
+ "rprint(strain)"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": null,
116
+ "id": "5d42a174-9737-4477-830a-3dc908dea925",
117
+ "metadata": {},
118
+ "outputs": [],
119
+ "source": [
120
+ "brain_region = client.search_entity(entity_type=BrainRegion, query={\"annotation_value\": 68}).one()"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": null,
126
+ "id": "282200cd-ad0c-4bb3-bc21-88de85289179",
127
+ "metadata": {},
128
+ "outputs": [],
129
+ "source": [
130
+ "rprint(brain_region)"
131
+ ]
132
+ },
133
+ {
134
+ "cell_type": "markdown",
135
+ "id": "a0193055-3448-4d1c-99cc-4d953727ef4e",
136
+ "metadata": {},
137
+ "source": [
138
+ "### Create a morphology object"
139
+ ]
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": null,
144
+ "id": "fdc328df-2cef-4e23-b240-2de061f0e640",
145
+ "metadata": {},
146
+ "outputs": [],
147
+ "source": [
148
+ "brain_location = BrainLocation(\n",
149
+ " x=4101.52490234375,\n",
150
+ " y=1173.8499755859375,\n",
151
+ " z=4744.60009765625,\n",
152
+ ")\n",
153
+ "morphology = ReconstructionMorphology(\n",
154
+ " name=\"my-morph\",\n",
155
+ " description=\"A morphology\",\n",
156
+ " species=species,\n",
157
+ " strain=strain,\n",
158
+ " brain_region=brain_region,\n",
159
+ " location=brain_location,\n",
160
+ " legacy_id=None,\n",
161
+ " authorized_public=True,\n",
162
+ ")"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": null,
168
+ "id": "2568abc1-8b72-4f35-85d3-19f6935ea232",
169
+ "metadata": {},
170
+ "outputs": [],
171
+ "source": [
172
+ "rprint(morphology)"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "markdown",
177
+ "id": "83fb7e5e-73b5-4227-aa22-90bb789b0907",
178
+ "metadata": {},
179
+ "source": [
180
+ "## Register morphology"
181
+ ]
182
+ },
183
+ {
184
+ "cell_type": "code",
185
+ "execution_count": null,
186
+ "id": "2e32a168",
187
+ "metadata": {},
188
+ "outputs": [],
189
+ "source": [
190
+ "registered = client.register_entity(entity=morphology)"
191
+ ]
192
+ },
193
+ {
194
+ "cell_type": "markdown",
195
+ "id": "5a4482d8-d5d4-45b9-80cb-264c1a531216",
196
+ "metadata": {},
197
+ "source": [
198
+ "## Add mtype to morphology"
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "code",
203
+ "execution_count": null,
204
+ "id": "540aec85-ed13-4224-99ce-a0628f3fa745",
205
+ "metadata": {},
206
+ "outputs": [],
207
+ "source": [
208
+ "mtype = client.search_entity(entity_type=MTypeClass, query={\"pref_label\": \"L5_PC\"}).one()\n",
209
+ "\n",
210
+ "mtype_classification = MTypeClassification(\n",
211
+ " mtype_class_id=mtype.id, entity_id=registered.id, authorized_public=True\n",
212
+ ")\n",
213
+ "\n",
214
+ "mtype_classification = client.register_entity(mtype_classification)"
215
+ ]
216
+ },
217
+ {
218
+ "cell_type": "markdown",
219
+ "id": "9cd036c4-e722-42a9-bed9-b6985a663400",
220
+ "metadata": {},
221
+ "source": [
222
+ "## Add contribution to morphology"
223
+ ]
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "execution_count": null,
228
+ "id": "c74eedae-6674-4695-b20b-177c25c8a59c",
229
+ "metadata": {},
230
+ "outputs": [],
231
+ "source": [
232
+ "agent = client.search_entity(entity_type=Organization, limit=1).one()\n",
233
+ "role = client.search_entity(entity_type=Role, limit=1).one()\n",
234
+ "contribution = Contribution(\n",
235
+ " agent=agent,\n",
236
+ " role=role,\n",
237
+ " entity=registered,\n",
238
+ ")\n",
239
+ "contribution = client.register_entity(contribution)"
240
+ ]
241
+ },
242
+ {
243
+ "cell_type": "code",
244
+ "execution_count": null,
245
+ "id": "5eea0777-2256-4c00-b387-3d8b9171ef63",
246
+ "metadata": {},
247
+ "outputs": [],
248
+ "source": [
249
+ "rprint(contribution)"
250
+ ]
251
+ },
252
+ {
253
+ "cell_type": "markdown",
254
+ "id": "c0d500bd",
255
+ "metadata": {},
256
+ "source": [
257
+ "## Upload assets"
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": null,
263
+ "id": "51d0c5b4-6251-4ee4-99ef-b6449a4d5da8",
264
+ "metadata": {},
265
+ "outputs": [],
266
+ "source": [
267
+ "with tempfile.TemporaryDirectory() as tdir:\n",
268
+ " file1 = Path(tdir, \"morph.h5\")\n",
269
+ " file1.write_text(\"h5\")\n",
270
+ "\n",
271
+ " file2 = Path(tdir, \"morph.swc\")\n",
272
+ " file2.write_text(\"swc\")\n",
273
+ "\n",
274
+ " # use a filepath to register first asset\n",
275
+ " asset1 = client.upload_file(\n",
276
+ " entity_id=registered.id,\n",
277
+ " entity_type=ReconstructionMorphology,\n",
278
+ " file_path=file1,\n",
279
+ " file_content_type=\"application/h5\",\n",
280
+ " )\n",
281
+ " rprint(asset1)\n",
282
+ "\n",
283
+ " # use an in-memory buffer to upload second asset\n",
284
+ " buffer = io.BytesIO(b\"morph bytes buffer\")\n",
285
+ "\n",
286
+ " asset2 = client.upload_content(\n",
287
+ " entity_id=registered.id,\n",
288
+ " entity_type=ReconstructionMorphology,\n",
289
+ " file_content=buffer,\n",
290
+ " file_name=\"buffer.h5\",\n",
291
+ " file_content_type=\"application/swc\",\n",
292
+ " )\n",
293
+ " rprint(asset2)"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "markdown",
298
+ "id": "1b5e396e-bf57-436d-9b06-ce198afc15ca",
299
+ "metadata": {},
300
+ "source": [
301
+ "## Retrieve it"
302
+ ]
303
+ },
304
+ {
305
+ "cell_type": "code",
306
+ "execution_count": null,
307
+ "id": "3a0f9360-a805-4ccf-ad7c-95f7237d0819",
308
+ "metadata": {},
309
+ "outputs": [],
310
+ "source": [
311
+ "# with assets and mtypes\n",
312
+ "fetched = client.get_entity(entity_id=registered.id, entity_type=ReconstructionMorphology)"
313
+ ]
314
+ },
315
+ {
316
+ "cell_type": "markdown",
317
+ "id": "b00725dc-ba90-4ddf-b3ba-dea612cd7720",
318
+ "metadata": {},
319
+ "source": [
320
+ "## Download asset"
321
+ ]
322
+ },
323
+ {
324
+ "cell_type": "code",
325
+ "execution_count": null,
326
+ "id": "c89e91f7-a9bb-4d09-b921-4659e338225c",
327
+ "metadata": {},
328
+ "outputs": [],
329
+ "source": [
330
+ "downloaded = client.download_assets(\n",
331
+ " fetched,\n",
332
+ " selection={\"content_type\": \"application/swc\"},\n",
333
+ " output_path=\"./my-file.h5\",\n",
334
+ ").one()\n",
335
+ "\n",
336
+ "content = client.download_content(\n",
337
+ " entity_id=fetched.id, entity_type=type(fetched), asset_id=downloaded.asset.id\n",
338
+ ")\n",
339
+ "\n",
340
+ "print(content)\n",
341
+ "print(Path(\"my-file.h5\").read_text())"
342
+ ]
343
+ },
344
+ {
345
+ "cell_type": "markdown",
346
+ "id": "6879c149-3f59-4ee6-b878-92bdc6038de9",
347
+ "metadata": {},
348
+ "source": [
349
+ "## Delete asset"
350
+ ]
351
+ },
352
+ {
353
+ "cell_type": "code",
354
+ "execution_count": null,
355
+ "id": "9a211674-54d2-498f-983a-ab3f3675087d",
356
+ "metadata": {},
357
+ "outputs": [],
358
+ "source": [
359
+ "for asset in fetched.assets:\n",
360
+ " if asset.content_type == \"application/swc\":\n",
361
+ " print(\"Deleting asset \", asset.id)\n",
362
+ " deleted_asset = client.delete_asset(\n",
363
+ " entity_id=fetched.id,\n",
364
+ " entity_type=type(registered),\n",
365
+ " asset_id=asset.id,\n",
366
+ " )\n",
367
+ " break\n",
368
+ "\n",
369
+ "rprint(deleted_asset)\n",
370
+ "\n",
371
+ "fetched = client.get_entity(entity_id=registered.id, entity_type=ReconstructionMorphology)\n",
372
+ "rprint(fetched.assets)"
373
+ ]
374
+ },
375
+ {
376
+ "cell_type": "markdown",
377
+ "id": "f15c808c-c454-4277-9ec4-587922ac74f3",
378
+ "metadata": {},
379
+ "source": [
380
+ "## Search it"
381
+ ]
382
+ },
383
+ {
384
+ "cell_type": "code",
385
+ "execution_count": null,
386
+ "id": "956cc4d7-9ca8-4bb4-9911-648b4ca18a49",
387
+ "metadata": {},
388
+ "outputs": [],
389
+ "source": [
390
+ "hits = client.search_entity(\n",
391
+ " entity_type=ReconstructionMorphology,\n",
392
+ " query={\"name__ilike\": \"my-morph\", \"page\": 1, \"page_size\": 2},\n",
393
+ " limit=None,\n",
394
+ ").all()\n",
395
+ "\n",
396
+ "print(\"Number of results: \", len(hits))"
397
+ ]
398
+ },
399
+ {
400
+ "cell_type": "code",
401
+ "execution_count": null,
402
+ "id": "4091c7a8-75b9-49d0-8c98-378b7fb5df6d",
403
+ "metadata": {},
404
+ "outputs": [],
405
+ "source": [
406
+ "rprint(hits[0])"
407
+ ]
408
+ }
409
+ ],
410
+ "metadata": {
411
+ "language_info": {
412
+ "name": "python"
413
+ }
414
+ },
415
+ "nbformat": 4,
416
+ "nbformat_minor": 5
417
+ }
@@ -145,22 +145,8 @@
145
145
  }
146
146
  ],
147
147
  "metadata": {
148
- "kernelspec": {
149
- "display_name": "Python 3 (ipykernel)",
150
- "language": "python",
151
- "name": "python3"
152
- },
153
148
  "language_info": {
154
- "codemirror_mode": {
155
- "name": "ipython",
156
- "version": 3
157
- },
158
- "file_extension": ".py",
159
- "mimetype": "text/x-python",
160
- "name": "python",
161
- "nbconvert_exporter": "python",
162
- "pygments_lexer": "ipython3",
163
- "version": "3.12.10"
149
+ "name": "python"
164
150
  }
165
151
  },
166
152
  "nbformat": 4,