Python Client for HMS Search Kit

Sezer BOZKIR
Huawei Developers
Published in
4 min readFeb 25, 2021

Hi everyone,

In this article, we will look at the Search Kit, one of the features that the HMS world provides us, and we will take a look at how we can use Python client using the Search Kit I wrote with python.

What is HMS Search Kit?

Today, many applications have the feature of searching within themselves. As an alternative to the tools we can use to do this search, we can mention Search Kit.

In the future, Huawei has also said that it will add a feature that will allow you to search within your site or database.

The features it provides for Android applications are as follows:

Selection Search

A feature that allows you to use the search engine features that we can integrate using the Rest API, which we can also benefit from using the python client, as native in the application. For the integration steps, you can see them here.

The types of search we can do using this structure:

  1. Web Search
  2. Image Search
  3. Video Search
  4. News Search

Custom Search

It is the feature that allows you to filter for search based on web page search or organize the search by various regions after your application integrates Search Kit. You can adjust the language, region, page number, and the number of search results returned on a page as needed. When you also specify a target domain name for the search, only results from that domain are returned.

See the steps to integrate it into your application here.

Auto Suggestion

Autocomplete feature within applications has become one of the standards of many applications. Thanks to this feature, it is possible to use the automatic suggestion system in sections such as EditText up to 10 words.

See the steps to integrate it into your application here.

Spelling Check

With this feature that comes to your rescue when you want to present incorrect word spelling or correction suggestions in your application, you can ensure that your users (for example: in a note application) keep much cleaner records.

See the steps to integrate it into your application here.

Python Client

While working with this kit, I said “if there was a structure that we can use directly with python, it would be possible to benefit from the search part in many areas” and I rolled up my sleeves to write a client. Using this client, it is possible to use all types of searches provided by “Selection Search”:

by the way, if you say “I am not working with parameters, I will just do a global search”, it is possible to search by specifying the words without any parameters you want to search:

Preparing Application Information for the Client

In order to use the search engine, you have to enter the Client ID and Client Secret information in the Client you created in the first step. To receive this information, you must have a Huawei developer account. You can see how to open an account here. After creating a developer account, you can easily create your first application by looking at the medium article here or here for official documentation for creating a new application.

Now that we have the app and developer account, we can activate the “Search Kit”:

AppGallery Console -> My Projects -> [PROJE_ADI] -> Project Settings -> Manage APIs -> Search Kit

Now that the backend side is ready, you can follow the article here to get the information on our application.

Installing Client in Python Projects

At this point, after downloading the Github repo, just run this code;

pip install .

or (Doesn’t matter GNU / Linux or Windows) in the terminal:

pip install git+https://github.com/Natgho/HMS-Search-Kit-Python-Client.git@master

You can include the library in your project.

2 lines are enough to use it in your application:

client = HMSSearchKit("CLIENT_ID", "CLIENT_SECRE")
client.full_search('aramak istediğiniz metin')

The function call result will return you a dictionary, in this dictionary:

  1. How many data is returned by the query (count)
  2. Query result data (search_results)
  3. Query (search_string)
  4. your search type (search_type)

A few examples of queries:

Apart from the features I have integrated, you can check out the other features of HMS Search Kit here: HMS Search Kit

Github repo: HMS Search Kit Python Client

You can ask what you are curious about on the Huawei developer forum or by reaching my email address admin@sezerbozkir.com

See you in another article… :)

--

--