From 9cd8fc3173a93e2c84daac48e0eec1eb23f3bf4e Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com> Date: Mon, 10 Jun 2024 21:06:20 +0200 Subject: [PATCH] last update --- README.md | 25 +++++++++++++++++++------ molharbor/checker.py | 7 +++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8613474..eb1990b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # MolHarbour -MolHarbour is a Python wrapper for the Molport REST API. It allows you to search for chemical compounds and retrieve information about them. +MolHarbour is a unofficial Python wrapper for the Molport REST API. It allows you to search for chemical compounds and retrieve information about them. Additionally, MolHarbour unifies the Molport API variables names and verifies the response data using wonderful [Pydantic](https://github.com/pydantic/pydantic) models. This library is not affiliated with Molport in any way. Molport is a registered trademark of Molport SIA. @@ -104,7 +104,7 @@ molport.find("O=C(O)c1ccccc1", search_type=SearchType.SUBSTRUCTURE, max_results= MolHarbour design to simplify commonn tasks so `.find()` method returns a list of `MolportCompound` objects (which itself is a dataclass object with `smiles`, `molport_id` and `link` field). However, you can access the raw response using the `return_response` parameter. Returned `Response` object inherits from Pydantic `BaseModel` and contains all the fields from the Molport API response with type validation provided by Pydantic. -All the fields have the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. Shipment Type -> shipment_type) +All the fields have the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. `Shipment Type` -> `shipment_type`) ```python from molharbor import SearchType @@ -120,16 +120,29 @@ molport.find("O=C(O)c1ccccc1", search_type=SearchType.SUBSTRUCTURE, max_results= [Response(result=Result(status=1, message='Substructure search completed!'), data=Data(molecules=[Molecule(id=45........ ``` -### Supliers search +### Suppliers search -Having a Molport ID, you can search for suppliers using the `get_suppliers` method. Similar too `find()` method, you could either recieve a raw pydantic response with all the fields having the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. Shipment Type -> shipment_type) or processed dataframe with most important fields +Having a Molport ID, you can search for suppliers using the `get_suppliers` method. Similar too `find()` method, you could either recieve a raw pydantic response with all the fields having the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. `Shipment Type` -> `shipment_type`) or processed dataframe with most important fields -#### Processed dataframe +```python +df = molport.get_suppliers("Molport-001-794-639") +``` + +Or you could use id values of `MolportCompound` objects returned by `find()` method +```python +result = molport.find("C[C@H](CS)C(=O)N1CCC[C@H]1C(O)=O", search_type=SearchType.EXACT, max_results=1)[0] +result +MolportCompound(smiles='C[C@H](CS)C(=O)N1CCC[C@H]1C(O)=O', molport_id='Molport-001-794-639', link=... + +df = molport.get_suppliers(result.molport_id) +``` +#### Processed dataframe + +Returned dataframe contains all the fields from the Molport API response with type validation provided by Pydantic. The fields are renamed to be more human-readable and to be consistent with the Molport API docs. Below is an example of the most important fields. ```python -df = molport.get_suppliers("Molport-001-794-639") df[["supplier_name", "supplier_type", "amount", "measure", "price", "currency", "delivery_days", "stock", "stock_measure", "last_update_date_exact"]].head() diff --git a/molharbor/checker.py b/molharbor/checker.py index 087b905..59f8df8 100644 --- a/molharbor/checker.py +++ b/molharbor/checker.py @@ -165,13 +165,12 @@ def get_suppliers( """ credentials = self.credentials url = "https://api.molport.com/api/molecule/load?molecule={}" - if "API Key" in credentials: + if "api_key" in credentials: url += "&apikey={}" - url = url.format(molport_id, self.api_key) + url = url.format(molport_id, credentials["api_key"]) else: - url += "&username={}&password={}" + url += "&username={}&authenticationcode={}" url = url.format(molport_id, self.username, self.password) - response = self.client.get(url) if response.status_code != 200: raise ValueError(f"Error code: {response.status_code}\n{response.text}")