Skip to content

Commit e0fd7c7

Browse files
authored
Confirmation is now optional. (#270)
* Confirmation is now optional. AB#9779
1 parent b9290e8 commit e0fd7c7

32 files changed

+97
-135
lines changed

README.rst

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,34 @@ You can then use the examples code to create assets (see examples directory):
8484
# it does not start with arc_
8585
}
8686
#
87-
# The first argument are the attributes of the asset
88-
# The second argument is wait for confirmation:
89-
# If @confirm@ is True then this function will not
90-
# return until the asset is confirmed and ready
91-
# to accept events (or an error occurs)
87+
# There are 3 alternatives
9288
#
89+
# 1. Create the asset:
90+
# The first argument is the attributes of the asset
91+
return arch.assets.create(attrs=attrs)
92+
#
93+
# 2. alternatively one can wait for the asset to be confirmed in the
94+
# immutable store.
95+
# The second argument is wait for confirmation:
96+
# If @confirm@ is True then this function will not
97+
# return until the asset is confirmed.
98+
#
99+
# Confirmation guarantees that 3rd parties can retrieve and cryptographically
100+
# verify your Assets, which can take a few seconds to propagate. It is typically
101+
# not necessary to wait unless your workflow involves near-real-time
102+
# communication with 3rd parties and the 3rd party needs immediate cryptographic
103+
# verification of your new Asset.
93104
return arch.assets.create(attrs=attrs, confirm=True)
94-
# alternatively if some work can be done whilst the asset is confirmed then this call can be
95-
# replaced by a two-step alternative:
105+
#
106+
# 3. lastly if some work can be done whilst the asset is confirmed then this call
107+
# can be replaced by a two-step alternative:
96108
97-
# asset = arch.assets.create(props=props, attrs=attrs, confirm=False)
109+
asset = arch.assets.create(props=props, attrs=attrs)
98110
99111
# ... do something else here
100112
# and then wait for confirmation
101113
102-
# self.arch.assets.wait_for_confirmation(asset['identity']))
114+
return arch.assets.wait_for_confirmation(asset['identity']))
103115
104116
105117
def main():
@@ -238,7 +250,12 @@ Each step consists of control parameters (specified in the 'step' dictionary) an
238250
the yaml representation of the request body for an asset or event.
239251
240252
The confirm: field is a control variable for the PythonSDK that ensures that the
241-
asset or event is confirmed before returning.
253+
asset or event is confirmed before returning. This is optional and is only required
254+
3rd parties need to immediately retrieve and cryptographically
255+
verify your Assets, which can take a few seconds to propagate. It is typically
256+
not necessary to wait unless your workflow involves near-real-time
257+
communication with 3rd parties and the 3rd party needs instant cryptographic
258+
verification of your new Asset.
242259
243260
.. note::
244261
@@ -276,7 +293,6 @@ asset or event is confirmed before returning.
276293
radioactive: "true"
277294
radiation_level: "0"
278295
weight: "0"
279-
confirm: true
280296
281297
# setup the radiation bags to have a varing amount of radiactive waste
282298
# note the values to the events.create method are string representations of boolean
@@ -294,7 +310,6 @@ asset or event is confirmed before returning.
294310
asset_attributes:
295311
radiation_level: "3"
296312
weight: "1"
297-
confirm: true
298313
299314
Logging
300315
========

archivist/assets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def create(
120120
*,
121121
props: "dict[str, Any]|None" = None,
122122
attrs: "dict[str, Any]|None" = None,
123-
confirm: bool = True,
123+
confirm: bool = False,
124124
) -> Asset:
125125
"""Create asset
126126
@@ -143,7 +143,7 @@ def create(
143143
return self.create_from_data(data, confirm=confirm)
144144

145145
def create_from_data(
146-
self, data: "dict[str, Any]", *, confirm: bool = True
146+
self, data: "dict[str, Any]", *, confirm: bool = False
147147
) -> Asset:
148148
"""Create asset
149149
@@ -152,7 +152,7 @@ def create_from_data(
152152
153153
Args:
154154
data (dict): request body of asset.
155-
confirm (bool): if True wait for asset to be confirmed on DLT.
155+
confirm (bool): if True wait for asset to be confirmed.
156156
157157
Returns:
158158
:class:`Asset` instance
@@ -165,15 +165,15 @@ def create_from_data(
165165
return self.wait_for_confirmation(asset["identity"])
166166

167167
def create_if_not_exists(
168-
self, data: "dict[str, Any]", *, confirm: bool = True
168+
self, data: "dict[str, Any]", *, confirm: bool = False
169169
) -> "tuple[Asset, bool]":
170170
"""
171171
Creates an asset and associated locations and attachments if asset
172172
does not already exist.
173173
174174
Args:
175175
data (dict): request body of asset.
176-
confirm (bool): if True wait for asset to be confirmed on DLT.
176+
confirm (bool): if True wait for asset to be confirmed.
177177
178178
A YAML representation of the data argument would be:
179179
@@ -272,7 +272,7 @@ def create_if_not_exists(
272272
def wait_for_confirmation(self, identity: str) -> Asset:
273273
"""Wait for asset to be confirmed.
274274
275-
Waits asset to be confirmed.
275+
Waits for asset to be confirmed.
276276
277277
Args:
278278
identity (str): identity of asset

archivist/events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def create(
297297
attrs: "dict[str, Any]",
298298
*,
299299
asset_attrs: "dict[str, Any]|None" = None,
300-
confirm: bool = True,
300+
confirm: bool = False,
301301
) -> Event:
302302
"""Create event
303303
@@ -308,7 +308,7 @@ def create(
308308
props (dict): properties for this event.
309309
attrs (dict): attributes of created event.
310310
asset_attrs (dict): attributes of referenced asset.
311-
confirm (bool): if True wait for event to be confirmed on DLT.
311+
confirm (bool): if True wait for event to be confirmed.
312312
313313
Returns:
314314
:class:`Event` instance
@@ -323,7 +323,7 @@ def create(
323323
)
324324

325325
def create_from_data(
326-
self, asset_id: str, data: "dict[str, Any]", *, confirm: bool = True
326+
self, asset_id: str, data: "dict[str, Any]", *, confirm: bool = False
327327
) -> Event:
328328
"""Create event
329329

archivist/notebooks/Check Asset Compliance using CURRENT OUTSTANDING Policy.ipynb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@
169169
" \"arc_display_type\": \"Vault Door\",\n",
170170
" },\n",
171171
" },\n",
172-
" confirm=True,\n",
173172
" )\n",
174173
" print(\"DOOR:\", json_dumps(door, indent=4))\n",
175174
" return door"
@@ -197,7 +196,6 @@
197196
" \"arc_display_type\": \"Open\",\n",
198197
" \"arc_correlation_value\": f\"{tag}\",\n",
199198
" },\n",
200-
" confirm=True,\n",
201199
" )\n",
202200
" print(\"DOOR_OPENED:\", json_dumps(door_opened, indent=4))"
203201
]
@@ -224,7 +222,6 @@
224222
" \"arc_display_type\": \"Close\",\n",
225223
" \"arc_correlation_value\": f\"{tag}\",\n",
226224
" },\n",
227-
" confirm=True,\n",
228225
" )\n",
229226
" print(\"DOOR_CLOSED:\", json_dumps(door_closed, indent=4))"
230227
]

archivist/notebooks/Check Asset Compliance using SINCE Policy.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
" \"arc_description\": \"Traffic flow control light at A603 North East\",\n",
165165
" \"arc_display_type\": \"Traffic Light\",\n",
166166
" },\n",
167-
" confirm=True,\n",
168167
" )\n",
169168
" print(\"TRAFFIC_LIGHT:\", json_dumps(traffic_light, indent=4))\n",
170169
" return traffic_light"
@@ -191,7 +190,6 @@
191190
" \"arc_description\": \"Maintenance performed on traffic light\",\n",
192191
" \"arc_display_type\": f\"Maintenance Performed {tag}\",\n",
193192
" },\n",
194-
" confirm=True,\n",
195193
" )\n",
196194
" print(\"MAINTENANCE_PERFORMED:\", json_dumps(maintenance_performed, indent=4))"
197195
]

archivist/notebooks/Create Artist and Album Release Info.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
" \"artistid\": artistid,\n",
138138
" }\n",
139139
"\n",
140-
" return arch.assets.create(attrs=attrs, confirm=True)"
140+
" return arch.assets.create(attrs=attrs)"
141141
]
142142
},
143143
{

archivist/notebooks/Create Event with Verified Domain.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
" # alternatively if some work can be done whilst the event is confirmed then this call can be\n",
189189
" # replaced by a two-step alternative:\n",
190190
"\n",
191-
" # event = arch.events.create(asset[\"identity\"], props=props, attrs=attrs, confirm=False)\n",
191+
" # event = arch.events.create(asset[\"identity\"], props=props, attrs=attrs)\n",
192192
"\n",
193193
" # ... do something else here\n",
194194
" # and then wait for confirmation\n",
@@ -232,8 +232,7 @@
232232
" # The first argument is the attributes of the asset\n",
233233
" # The second argument is wait for confirmation:\n",
234234
" # If @confirm@ is True then this function will not\n",
235-
" # return until the asset is confirmed and ready\n",
236-
" # to accept events (or an error occurs)\n",
235+
" # return until the asset is confirmed.)\n",
237236
" return arch.assets.create(attrs=attrs, confirm=True)"
238237
]
239238
},

archivist/runner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ def __call__(self, config: "dict[str, Any]"):
421421
"radiation_level": 0,
422422
"weight": 0,
423423
},
424-
"confirm": True,
425424
}
426425
]
427426
```

archivist/tenancies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, archivist_instance: "Archivist"):
6262
def __str__(self) -> str:
6363
return f"TenanciesClient({self._archivist.url})"
6464

65-
def _identity(self, identity) -> str:
65+
def _identity(self, identity: str) -> str:
6666
"""Returns identity suitable for endpoint"""
6767
prefix, uuid = identity.split("/")
6868
if prefix == TENANCIES_PREFIX:

docs/features.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ REST api (in any language):
1313
* versioned package for the python 3.8,3.9,3.10,3.11,3.12 ecosystem.
1414
* automatic confirmation of assets and events: just set **confirm=True** when
1515
creating the asset or event and a sophisticated retry and exponential backoff
16-
algorithm will take care of everything.
16+
algorithm will take care of everything (optional).
1717
* **list()** method: one can easily get an iterable of assets or events that
1818
correspond to a particular signature. The list method is optimized for use in
1919
loop (for a in arch.assets.list():...) but can easily be converted to a list
@@ -31,6 +31,6 @@ REST api (in any language):
3131
* easily extensible - obeys the open-closed principle of SOLID where new endpoints
3232
can be implemented by **extending** the package as opposed to modifying it.
3333
* fully unittested - 100% coverage.
34-
* code style managed and enforced using **pycodestyle**, **pylint** and **black**.
34+
* code style managed and enforced using **ruff**, **pycodestyle**, **pylint** and **black**.
3535

3636
See the **examples/** directory for example code.

0 commit comments

Comments
 (0)