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

python-sdk documentation update #27

Merged
merged 8 commits into from
Oct 5, 2022
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
Expand Down
72 changes: 37 additions & 35 deletions docs/source/jupyter/sdk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python-SDK\n",
"# MarketPlace SDK\n",
"\n",
"In order to easily and effectively communicate with a registered application in MarketPlace via Python, the Python Software Development Kit (SDK) can be used. Follow the instructions on the [application registration](../apps/registration.md) page to register an application with MarketPlace. Once the application is registered, you will find the `client_id` in the registration output.\n",
"\n",
"For further information about installation and usage, visit the [Python SDK repository](https://github.com/materials-marketplace/python-sdk)."
"The SDK is based on the [standard api](../apps/mp-api.md). For further information about installation and usage, visit the [Python SDK repository](https://github.com/materials-marketplace/python-sdk)."
]
},
{
Expand Down Expand Up @@ -50,7 +50,16 @@
"source": [
"The SDK requires two parameters to connect to the MarketPlace. These are the path to the MarketPlace instance, and an access token belonging to a user. Your token can be accessed in the _Advanced_ section of your MarketPlace profile.\n",
"\n",
"You can set these values as environment variables (`MP_HOST` and `MP_ACCESS_TOKEN` respectively) or send them to the constructor. Note that the MarketPlace instance corresponds to the main deployment (https://www.materials-marketplace.eu/), so it is not necessary to define it."
"We recommend that you set these values as environment variables (`MP_HOST` and `MP_ACCESS_TOKEN` respectively). Note that the MarketPlace instance corresponds to the main deployment (https://www.materials-marketplace.eu/), so it is not necessary to define it."
singhpranjali marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%export MP_ACCESS_TOKEN=\"<your access token>\""
]
},
{
Expand All @@ -67,11 +76,9 @@
}
],
"source": [
"from typing import List, Dict\n",
"from marketplace.app import MarketPlaceApp\n",
"from marketplace.app import get_app\n",
"\n",
"mp = MarketPlaceApp(client_id=\"<registered application's client_id>\",\n",
" access_token=\"<your access token>\")\n",
"mp = get_app(app_id=\"<registered application's client_id>\")\n",
"\n",
"print(mp.heartbeat())"
]
Expand All @@ -80,7 +87,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Example 1: starting a new transformation by calling the `newTransformation` capability with a configuration. \n",
"Example 1: starting a new transformation by calling the `newTransformation` capability with a configuration.\n",
"The POST request is created by the SDK automatically and sent with the payload"
]
},
Expand All @@ -101,18 +108,17 @@
}
],
"source": [
"config = {'configuration': 1}\n",
"transformation_id = mp.new_transformation(config)\n",
"from marketplace_standard_app_api.models.transformation import NewTransformationModel, TransformationId\n",
"\n",
"transformation_id: TransformationId = mp.new_transformation(parameters={\"some_parameter\": \"some_value\"}).id\n",
"transformation_id"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can now start the transformation with this `transformation_id`.\n",
"Optionally, you can also send additional arguments pertinent to your application.\n",
"The additional arguments (`**kwargs`) are sent as parameters along with the compulsory argument (in this case `transformation_id`)."
"You can now start the transformation with this `transformation_id`."
]
},
{
Expand All @@ -132,16 +138,16 @@
}
],
"source": [
"transformation_argument = 'xyz'\n",
"mp.start_transformation(transformation_id=transformation_id, \n",
" additional_argument=transformation_argument)"
"mp.start_transformation(transformation_id=transformation_id)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember that you can only access capabilities that are supported by the application. The application will support specific capabilities specified in the openAPI file used to register the application. Trying to access any unsupported capabilities throws a `NotImplemented` error."
"Remember that you can only access capabilities that are supported by the application.\n",
"The application will support specific capabilities specified in the openAPI file used to register the application.\n",
"Trying to access any unsupported capabilities throws a `NotImplemented` error."
]
},
{
Expand All @@ -163,7 +169,7 @@
}
],
"source": [
"mp.get_collection()"
"mp.list_collections()"
]
},
{
Expand All @@ -183,6 +189,7 @@
"metadata": {},
"outputs": [],
"source": [
"from marketplace.app.v0 import MarketPlaceApp\n",
"class MyMarketPlaceApp(MarketPlaceApp):\n",
" def heartbeat(self) -> str:\n",
" return f\"My app says hi: {super().heartbeat()}\""
Expand Down Expand Up @@ -212,37 +219,32 @@
}
],
"source": [
"my_mp_app = MyMarketPlaceApp(client_id=\"<registered application's client_id>\",\n",
" access_token=\"<your access token>\")\n",
"\n",
"transformation_id = my_mp_app.new_transformation(config)\n",
"my_mp_app = MyMarketPlaceApp(app_id=\"<registered application's client_id>\")\n",
"\n",
"transformation_id = my_mp_app.new_transformation(NewTransformationModel(parameters=config)).id\n",
"# Since this capability was not overridden, this will return the standard response\n",
"\n",
"my_mp_app.heartbeat()"
]
}
],
"metadata": {
"interpreter": {
"hash": "97ae724bfa85b9b34df7982b8bb8c7216f435b92902d749e4263f71162bea840"
},
"kernelspec": {
"display_name": "Python 3.8.3 64-bit (conda)",
"display_name": "Python 3.10.4 ('venv')",
"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.8.0"
"version": "3.10.4"
},
"orig_nbformat": 4
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "4b195c9ba378eb519b14e7f259b82f2dffeee53eaf931c5b8aa204642c58cd1a"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down