<jupyter_start><jupyter_text>DataPath :: Data Update ExampleThis notebook demonstrates how to perform simple data manipulations.<jupyter_code>from deriva.core import ErmrestCatalog, get_credential<jupyter_output><empty_output><jupyter_text>This example uses a development server with a throw away catalog. You *will not* have sufficient permissions to be able to run this example. This notebook is for documentation purpose only.<jupyter_code>scheme = 'https'
hostname = 'dev.facebase.org'
catalog_number = 1<jupyter_output><empty_output><jupyter_text>Use DERIVA-Auth to get a `credential` or use `None` if your catalog allows anonymous access.<jupyter_code>credential = get_credential(hostname)<jupyter_output><empty_output><jupyter_text>Now, connect to your catalog and the `pathbuilder` interface for the catalog.<jupyter_code>assert scheme == 'http' or scheme == 'https', "Invalid http scheme used."
assert isinstance(hostname, str), "Hostname not set."
assert isinstance(catalog_number, int), "Invalid catalog number"
catalog = ErmrestCatalog(scheme, hostname, catalog_number, credential)
pb = catalog.getPathBuilder()<jupyter_output><empty_output><jupyter_text>For this example, we will create or modify entities of the "Dataset" table of a catalog that uses the FaceBase data model.<jupyter_code>dataset = pb.isa.dataset
dataset<jupyter_output><empty_output><jupyter_text>Insert exampleHere we will insert an entity into the dataset table.<jupyter_code>new_entity = {
    'title': 'A test dataset by derivapy', 
    'description': 'This was created by the deriva-py API.',
    'project': 311
}
entities = dataset.insert([new_entity], defaults={'id', 'accession'})<jupyter_output><empty_output><jupyter_text>The insert operation returns the inserted entities, which now have any system generated attributes filled in.<jupyter_code>list(entities)<jupyter_output><empty_output><jupyter_text>Update exampleHere we will change the description for the entity we inserted and update it in the catalog.<jupyter_code>entities[0]['description'] = 'A test dataset that was updated by derivapy'
updated_entities = dataset.update(entities)<jupyter_output><empty_output><jupyter_text>Similar to the insert operation, the update operation also returns the updated entities. Notice that the system-managed 'RMT' (Row Modified Timestamp) attribute has been update too.<jupyter_code>list(updated_entities)<jupyter_output><empty_output><jupyter_text>Update with custom correlation and targets specifiedYou can also specify which columns to use to correlate the input with the existing rows in the table and which columsn to be the targets of the update. Per the ERMrest protocol, extra data in the update payload (`entities`) will be ignored. The inputs must be `iterable`s of strings or objects that implement the `__str__` method.<jupyter_code>entities[0]['description'] = 'Yet another update using derivapy'
entities[0]['title'] = 'And a title change'
updated_entities = dataset.update(entities, [dataset.id], [dataset.description, 'title'])
list(updated_entities)<jupyter_output><empty_output><jupyter_text>Delete exampleUnlike `insert` and `update` which are performed within the context of a table, the `delete` operation is performed within the context of a data path.We know the `RID` from above, which is a single-column key for the entities in the `dataset` (and any other EMRrest) table. We can use this attribute to form a path to the newly inserted and updated entity.Note: Any filters could be used in this example; we do not have to use a key column only. We use the key only because we want to delete that specific entity which we just created. If we wanted to, we could link addition tables and apply additional filters to delete entities computed from a _complex_ path.<jupyter_code>path = dataset.filter(dataset.RID == entities[0]['RID'])<jupyter_output><empty_output><jupyter_text>On successful delete, no content will be returned.<jupyter_code>path.delete()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08133133133133133, 'fraction_numerical': 0.002002002002002002, 'mean_word_length': 6.883629191321499, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '495496', 'license': 'Apache-2.0', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1109, 'n_words': 430, 'path': 'docs/derivapy-datapath-update.ipynb', 'repo_name': 'emirdad/deriva-py', 'size': '3996'}