Find Asset and Event Creation
[1]:
# Find an Asset and create Events
#
# Main function, establishes a connection to RKVST using an App Registration then uses that
# to find an Asset and create Events.
#
# Note: The purpose of RKVST Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.
# The RKVST Python SDK is authored to work cleanly with more advanced coding techniques.
#
# RKVST Python SDK: https://github.com/rkvst/rkvst-python
#
[2]:
from json import dumps as json_dumps
from os import getenv
from warnings import filterwarnings
from dotenv import load_dotenv
from archivist.archivist import Archivist
from archivist.proof_mechanism import ProofMechanism
from archivist.logger import set_logger
[3]:
%reload_ext dotenv
%dotenv -o notebooks.env
[4]:
# RKVST_URL, RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET are environment variables that represent connection parameters.
#
# RKVST_URL = represents the url to the RKVST application
# RKVST_APPREG_CLIENT = represents the client ID from an Application Registration
# RKVST_APPREG_SECRET = represents the client secret from an Application Registration
# RKVST_UNIQUE_ID = is an environment variable that is a unique identifier
RKVST_URL = getenv("RKVST_URL")
RKVST_APPREG_CLIENT = getenv("RKVST_APPREG_CLIENT")
RKVST_APPREG_SECRET = getenv("RKVST_APPREG_SECRET")
RKVST_UNIQUE_ID = getenv("RKVST_UNIQUE_ID")
if not RKVST_UNIQUE_ID:
raise Exception("RKVST_UNIQUE_ID is undefined")
[5]:
"""
Main function of Asset and Event creation.
* Connect to RKVST with client ID and client secret
* Creates an Asset and two Events
* Prints response of Asset and Event creation
"""
# Optional call to set the logger level. The argument can be either
# "INFO" or "DEBUG". For more sophisticated logging control see our
# documentation.
set_logger("INFO")
# Initialize connection to RKVST
print("Connecting to RKVST")
print("RKVST_URL", RKVST_URL)
arch = Archivist(RKVST_URL, (RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET), max_time=300)
Connecting to RKVST
RKVST_URL https://app.rkvst.io
[6]:
def get_artist(arch, name, artistid):
"""
Finds existing Artist asset by name and unique id
"""
attrs = {
"arc_display_type": "Artists",
"arc_display_name": name,
"artistid": artistid,
}
return arch.assets.read_by_signature(attrs=attrs)
[7]:
def create_release(arch, asset, album_name, release):
"""
Creates an Event for existing Artist asset
"""
props = {"operation": "Record", "behaviour": "RecordEvidence"}
attrs = {
"arc_description": "Artist Information for existing Artist",
"arc_display_type": "Album Release for existing Artist",
"album_name": album_name,
"relase_year": release,
}
return arch.events.create(asset["identity"], props=props, attrs=attrs)
[8]:
# Finding existing artist by name and artist id
print("Finding Asset")
asset = get_artist(arch, "Adele Laurie Blue Adkins", RKVST_UNIQUE_ID)
print("Asset", json_dumps(asset, indent=4))
Finding Asset
Refresh token
Asset {
"identity": "assets/cbd21a61-c126-4c02-b525-add1a74fb802",
"behaviours": [
"RecordEvidence",
"Builtin",
"AssetCreator",
"Attachments"
],
"attributes": {
"arc_description": "British Soul Singer",
"arc_display_name": "Adele Laurie Blue Adkins",
"arc_display_type": "Artists",
"artistid": "666769323",
"genre": "Soul",
"stage_name": "Adele",
"arc_attachments": [
{
"arc_hash_alg": "SHA256",
"arc_hash_value": "cf0dd630dcfb6e2eac65c362bf7d5ff382a4241ebf45a69a2541ee43320d4af6",
"arc_attachment_identity": "blobs/9bfee457-b0ef-4fe9-a51f-16f96ddf8a8a",
"arc_display_name": "arc_primary_image"
}
]
},
"confirmation_status": "CONFIRMED",
"tracked": "TRACKED",
"owner": "0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce",
"at_time": "2023-01-16T11:54:18Z",
"storage_integrity": "TENANT_STORAGE",
"proof_mechanism": "SIMPLE_HASH",
"chain_id": "827586838445807967",
"public": false,
"tenant_identity": "tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866"
}
[9]:
# Create two Events that contain album release information for existing Artist
print("Creating Events for existing Asset")
event_one = create_release(arch, asset, album_name="25", release="2015")
print("Event for Album 25", json_dumps(event_one, indent=4))
event_two = create_release(arch, asset, album_name="30", release="2021")
print("Event for Album 30", json_dumps(event_two, indent=4))
Creating Events for existing Asset
Event for Album 25 {
"identity": "assets/cbd21a61-c126-4c02-b525-add1a74fb802/events/676e0177-c7a8-488e-adda-89438f2e3380",
"asset_identity": "assets/cbd21a61-c126-4c02-b525-add1a74fb802",
"event_attributes": {
"arc_description": "Artist Information for existing Artist",
"arc_display_type": "Album Release for existing Artist",
"relase_year": "2015",
"album_name": "25"
},
"asset_attributes": {},
"operation": "Record",
"behaviour": "RecordEvidence",
"timestamp_declared": "2023-01-16T11:54:23Z",
"timestamp_accepted": "2023-01-16T11:54:23Z",
"timestamp_committed": "2023-01-16T11:54:23.062210882Z",
"principal_declared": {
"issuer": "https://app.rkvst.io/appidpv1",
"subject": "437bd138-dade-4346-aadd-dfdfee51ddf4",
"display_name": "Test Notebooks",
"email": ""
},
"principal_accepted": {
"issuer": "https://app.rkvst.io/appidpv1",
"subject": "437bd138-dade-4346-aadd-dfdfee51ddf4",
"display_name": "Test Notebooks",
"email": ""
},
"confirmation_status": "CONFIRMED",
"transaction_id": "",
"block_number": 0,
"transaction_index": 0,
"from": "0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce",
"tenant_identity": "tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866"
}
Event for Album 30 {
"identity": "assets/cbd21a61-c126-4c02-b525-add1a74fb802/events/d20eb860-bd6b-4d29-951c-dbebb17e2839",
"asset_identity": "assets/cbd21a61-c126-4c02-b525-add1a74fb802",
"event_attributes": {
"relase_year": "2021",
"album_name": "30",
"arc_description": "Artist Information for existing Artist",
"arc_display_type": "Album Release for existing Artist"
},
"asset_attributes": {},
"operation": "Record",
"behaviour": "RecordEvidence",
"timestamp_declared": "2023-01-16T11:54:23Z",
"timestamp_accepted": "2023-01-16T11:54:23Z",
"timestamp_committed": "2023-01-16T11:54:24.009826690Z",
"principal_declared": {
"issuer": "https://app.rkvst.io/appidpv1",
"subject": "437bd138-dade-4346-aadd-dfdfee51ddf4",
"display_name": "Test Notebooks",
"email": ""
},
"principal_accepted": {
"issuer": "https://app.rkvst.io/appidpv1",
"subject": "437bd138-dade-4346-aadd-dfdfee51ddf4",
"display_name": "Test Notebooks",
"email": ""
},
"confirmation_status": "CONFIRMED",
"transaction_id": "",
"block_number": 0,
"transaction_index": 0,
"from": "0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce",
"tenant_identity": "tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866"
}
[ ]: