Attach and Access a Secret in a Python Notebook Paragraph

As the ADMIN user, you can attach the credential created in Graph Studio to a notebook. You can then access the secret in a Python paragraph.

Ensure that you meet all the prerequistes described in Prerequisites to Use OCI Vault Secret Credentials.
Perform the following steps to attach and access a secret in a Python notebook paragraph:
  1. Click open a notebook in the Notebooks page.
  2. Click the credential_icon Credential icon on the top left of the page.

    The Attach credentials window opens as shown:



    The window displays the currently attached credentials to the notebook. It also allows you to attach a new credential.

  3. Click the Attach icon, shown highlighted in the preceding figure.
    The Attach new credential window opens as shown.


    Description of attach_new_credential_nb.png follows
    Description of the illustration attach_new_credential_nb.png

  4. Enter the Credential Alias and Credential Description.
  5. Click Select and choose a secret from the list.
  6. Click Attach.
    The newly added credential gets attached to the notebook.
  7. Access the secret in a Python paragraph by referencing it using the alias (provided earlier) as shown.

    Caution:

    The following code snippet is for illustrative purposes only. It is recommended that you do not print secrets in plain text in a paragraph output to maintain confidentiality.
    %python
    from ds_interpreter_client.context.ds_context import PyDataStudioContext
     
    ds = PyDataStudioContext()
    print('My secret: ' + ds.get_credential('my_secret'))

    The following shows the output on running the preceding code: