Package: osiris-sdk
osiris-sdkInstallingGetting StartedData application registrationPrerequisitesStepsCreate an App RegistrationCreate a Service Principal and credentialsGrant access to the datasetUsageUploadDownloadIngress AdapterInstalling$pipinstallosiris-sdkThe SDK requires Python 3.Getting StartedTo get started with the SDK you will need the URL to the Osiris-ingress API and the tenant ID for the
organisation who runs the API. Furthermore, you will need to register your application withing the tenant
using Azure App Registration. You will also need to create a dataset in the DataPlatform.Data application registrationAn App Registration with credentials are required to upload data to the DataPlatform through the Osiris Ingress API.PrerequisitesThe dataset has been created throughthe Data Platform.The Azure CLI is installed on your workstationStepsLogin with the Azure CLI with the following command:azloginYou can also specify a username and password with:azlogin-u<username>-p<password>Create an App RegistrationThe App Registration serves as a registration of trust for your application (or data publishing service) towards the Microsoft Identity Platform (allowing authentication).This is the "identity" of your application.
Note that an App Registration is globally unique.Run the following command:azadappcreate--display-name"<YOUR APP NAME>"The application name should be descriptive correlate to the application/service you intend to upload data with.Take note of theappIdGUID in the returned object.Create a Service Principal and credentialsThe Service Principal and credentials are what enables authorization to the Data Platform.Create a Service Principal using theappIdGUID from when creating the App Registration:azadspcreate--id"<appID>"Then create a credential for the App Registration:azadappcredentialreset--id"<appID>"NOTE:Save the output somewhere secure. The credentials you receive are required to authenticate with the Osiris Ingress API.Grant access to the datasetThe application must be granted read- and write-access to the dataset onthe Data Platform.Add the application you created earlier, using the<YOUR APP NAME>name, to the read- and write-access lists.UsageHere are some simple examples on how to use the SDK.UploadThe following is a simple example which shows how you can upload files using the Osiris SDK:fromosiris.apis.ingressimportIngressfromosiris.core.azure_client_authorizationimportClientAuthorizationclient_auth=ClientAuthorization(tenant_id=<TENANT_ID>,client_id=<CLIENT_ID>,client_secret=<CLIENT_SECRET>)ingress=Ingress(client_auth=client_auth,ingress_url=<INGRESS_URL>,dataset_guid=<DATASET_GUID>)file=open('test_file.json','rb')# Without schema validation and a JSON fileingress.upload_json_file(file,False)# With schema validation and a JSON fileingress.upload_json_file(file,True)# With schema validation, a JSON file and event timeingress.upload_json_file_event_time(file,'2021-01-01',True)# Arbitrary fileingress.upload_file(file)# Save state filewithopen('state.json','r')asstate:ingress.save_state(state)# Retrieve statestate=ingress.retrieve_state()DownloadThe following is a simple example which shows how you can download files using the Osiris SDK:fromosiris.apis.egressimportEgressfromosiris.core.azure_client_authorizationimportClientAuthorizationclient_auth=ClientAuthorization(tenant_id=<TENANT_ID>,client_id=<CLIENT_ID>,client_secret=<CLIENT_SECRET>)egress=Egress(client_auth=client_auth,egress_url=<EGRESS_URL>,dataset_guid=<DATASET_GUID>)# JSON filecontent_json=egress.download_json_file('2021-01-01','2021-01-03')The full list of methods available in Egress can be found in the source code.Ingress AdapterThe following is a simple example which shows how you can create a new ingress adapter.importjsonfromosiris.adapters.ingress_adapterimportIngressAdapterclassMyAdapter(IngressAdapter):defretrieve_data(self)->bytes:returnjson.dumps('Hello World').encode('UTF-8')defmain():client_auth=ClientAuthorization(tenant_id=<TENANT_ID>,client_id=<CLIENT_ID>,client_secret=<CLIENT_SECRET>)adapter=MyAdapter(client_auth=client_auth,ingress_url=<INGRESS_URL>,dataset_guid=<DATASET_GUID>)# as json dataadapter.upload_json_data(schema_validate=False)# or as arbitrary dataadapter.upload_data()# or json data with a path corresponding to the given event timeadapter.upload_json_data_event_time(schema_validate=False)# or data with a path corresponding to the given event timeadapter.upload_data_event_time()if__name__=='__main__':main()