Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example notebook for Schema class. Minor fix to existing notebook #1001

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/python-beta/examples/create_model.py

This file was deleted.

213 changes: 213 additions & 0 deletions lib/python-beta/notebooks/access_requests_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Managing Access Requests"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The Bailo python client enables intuitive interaction with the Bailo service, from within a python environment. This example notebook will run through the following concepts:\n",
"\n",
"* Creating a new access request on Bailo.\n",
"* Retrieving an existing access request from the service.\n",
"* Making changes to an access request.\n",
"* Deleting an access request.\n",
"\n",
"Prerequisites:\n",
"\n",
"* Python 3.8.1 or higher (including a notebook environment for this demo).\n",
"* A local or remote Bailo service (see https://github.com/gchq/Bailo)."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The Bailo python client is split into two sub-packages: **core** and **helper**.\n",
"\n",
"* **Core:** For direct interactions with the service endpoints.\n",
"* **Helper:** For more intuitive interactions with the service, using classes (e.g. Model) to handle operations.\n",
"\n",
"In order to create helper classes, you will first need to instantiate a `Client()` object from the core. By default, this object will not support any authentication. However, Bailo also supports PKI authentication, which you can use from Python by passing a `PkiAgent()` object into the `Client()` object when you instantiate it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Necessary import statements\n",
"\n",
"from bailo import AccessRequest, Model, Client\n",
"\n",
"# Instantiating the PkiAgent(), if using.\n",
"# agent = PkiAgent(cert='', key='', auth='')\n",
"\n",
"# Instantiating the Bailo client\n",
"\n",
"client = Client(\"http://127.0.0.1:8080\") # <- INSERT BAILO URL (if not hosting locally)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a new access request"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, we'll create a new access request using the `AccessRequest.create()` classmethod. On the Bailo service, an access request must consist of at least 3 parameters upon creation. These are **model_id**, **schema_id** and **metadata**. Below, we use the `Client()` object created before when instantiating the new `AccessRequest()` object. We'll also need to create a new model on the service, which our access request will be for."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = Model.create(client=client, name=\"YOLOv5\", description=\"YOLOv5 model for object detection.\", team_id=\"uncategorised\")\n",
"model_id = model.model_id\n",
"\n",
"metadata = {\"overview\": {\"entities\": [\"user\"], \"name\": \"test\", \"endDate\": \"1970-01-01\"}}\n",
"access_request = AccessRequest.create(client=client, model_id=model_id, schema_id=\"minimal-access-request-general-v10-beta\", metadata=metadata)\n",
"\n",
"access_request_id = access_request.access_request_id"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Retrieving an access request"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using the .from_id() method"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, we'll retrieve our previous access request using the `AccessRequest.from_id()` classmethod. This will create your `AccessRequest()` object as before, but using existing information retrieved from the service."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"access_request = AccessRequest.from_id(client=client, model_id=model_id, access_request_id=access_request_id)\n",
"\n",
"access_request.metadata"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Making changes to an access request"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"You can make changes to an access request by editing the **metadata** attribute directly, and then calling the `.update()` method. This is demonstrated below with a name change."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"new_metadata = access_request.metadata\n",
"new_metadata[\"overview\"][\"name\"] = \"newname\"\n",
"\n",
"access_request.metadata = new_metadata\n",
"access_request.update()\n",
"\n",
"access_request.metadata"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deleting an access request"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also delete access requests by simply calling the `.delete()` method, as demonstrated below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"access_request.delete()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 1 addition & 2 deletions lib/python-beta/notebooks/models_and_releases_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"source": [
"# Necessary import statements\n",
"\n",
"from bailo.helper import Model\n",
"from bailo.core import Client, PkiAgent\n",
"from bailo import Model, Client\n",
"\n",
"# Instantiating the PkiAgent(), if using.\n",
"# agent = PkiAgent(cert='', key='', auth='')\n",
Expand Down
Loading