|
1 | | -**Note:** The readme/code you are seeing it's part of upcoming release: Algolia API Client Python **v2**. |
| 1 | +<p align="center"> |
| 2 | + <h4 align="center">The readme/code you are seeing it's part of upcoming release</h4> |
| 3 | + <h2 align="center">Algolia API Client Python v2</h2> |
| 4 | +</p> |
2 | 5 |
|
3 | | -# Algolia Search API Client for Python |
| 6 | +**[Algolia Search](https://www.algolia.com)** is a hosted search engine capable of delivering real-time results from the first keystroke. |
4 | 7 |
|
5 | | -[Algolia Search](https://www.algolia.com) is a hosted search engine capable of delivering realtime results from the first keystroke. |
| 8 | +This readme/code introduces the upcoming Algolia API Client Python v2, the next major release of our API Client. This release includes several new features along with the latest bug fixes and improvements: |
6 | 9 |
|
7 | | -The **Algolia Search API Client for Python** lets |
8 | | -you easily use the [Algolia Search REST API](https://www.algolia.com/doc/rest-api/search) from |
9 | | -your Python code. |
| 10 | +- Supports Python: 2.7, 3.4, 3.5, 3.6, and 3.7. |
| 11 | +- Works in synchronous and **asynchronous** environments. |
| 12 | +- Tons of new methods: waitable response objects, `replace_all_objects`,`clear_objects`, and more! |
10 | 13 |
|
11 | | -[](https://travis-ci.org/algolia/algoliasearch-client-python) |
12 | | -[](http://badge.fury.io/py/algoliasearch) |
| 14 | +**Development Status**: 4 - Beta. |
13 | 15 |
|
14 | | -## Getting Help |
| 16 | +**Changelog**: Comming soon. |
15 | 17 |
|
16 | | -- **Need help**? Ask a question to the [Algolia Community](https://discourse.algolia.com/) or on [Stack Overflow](http://stackoverflow.com/questions/tagged/algolia). |
17 | | -- **Found a bug?** You can open a [GitHub issue](https://github.com/algolia/algoliasearch-client-python/issues). |
| 18 | +You'd like to contribute? Before start, we want to let you know that your **feedback** is important to us! Please consider start using this `v2` today! Found a bug? Report it here: [github.com/algolia/algoliasearch-client-python/issues](https://github.com/algolia/algoliasearch-client-python/issues). |
| 19 | + |
| 20 | +### Example with synchronous usage: |
| 21 | + |
| 22 | +```py |
| 23 | +import os |
| 24 | + |
| 25 | +from algoliasearch.search_client import SearchClient |
| 26 | + |
| 27 | +client = SearchClient.create( |
| 28 | + 'ALGOLIA_APPLICATION_ID', |
| 29 | + 'ALGOLIA_ADMIN_KEY' |
| 30 | +) |
| 31 | + |
| 32 | +index = client.init_index('articles') |
| 33 | + |
| 34 | +index.save_objects([ |
| 35 | + {'objectID': 1, 'firstname': 'Jimmie', 'lastname': 'Barninger'}, |
| 36 | + {'objectID': 2, 'firstname': 'Warren', 'lastname': 'Speach'} |
| 37 | +]).wait() |
| 38 | + |
| 39 | +hits = index.search('Jimmie') |
| 40 | + |
| 41 | +print(hits) |
| 42 | +``` |
| 43 | + |
| 44 | +### Example with asynchronous usage: |
| 45 | + |
| 46 | +First, require asynchronous libraries: |
| 47 | + |
| 48 | +``` |
| 49 | +pip install 'asyncio>=3.4,<4.0' 'aiohttp>=2.0,<4.0' 'async_timeout>=2.0,<4.0' |
| 50 | +``` |
| 51 | + |
| 52 | +Then, asynchronous methods are available using the `async` suffix: |
| 53 | + |
| 54 | +| synchronous | asynchronous | |
| 55 | +|-------------- |-------------------- | |
| 56 | +| search | search_async | |
| 57 | +| save_objects | save_objects_async | |
| 58 | +| set_settings | set_settings_async | |
| 59 | +| save_synonyms | save_synonyms_async | |
| 60 | +| ... | ... | |
| 61 | + |
| 62 | + |
| 63 | +```py |
| 64 | +import asyncio |
| 65 | + |
| 66 | +from algoliasearch.search_client import SearchClient |
| 67 | +from algoliasearch.responses import MultipleResponse |
| 68 | + |
| 69 | +app_id = 'ALGOLIA_APPLICATION_ID' |
| 70 | +api_key = 'ALGOLIA_ADMIN_KEY' |
| 71 | + |
| 72 | +async def main(): |
| 73 | + async with SearchClient.create(app_id, api_key) as client: |
| 74 | + index = client.init_index('articles') |
| 75 | + |
| 76 | + results = await asyncio.gather( |
| 77 | + index.save_object_async({'objectID': 1, 'foo': 'bar'}), |
| 78 | + index.save_object_async({'objectID': 2, 'foo': 'foo'}) |
| 79 | + ) |
| 80 | + |
| 81 | + MultipleResponse(results).wait() |
| 82 | + |
| 83 | + print(await index.search_async('')) |
| 84 | + |
| 85 | +asyncio.run(main()) |
| 86 | + |
| 87 | +``` |
| 88 | + |
| 89 | +### License |
| 90 | + |
| 91 | +Algolia API Client Python is an open-sourced software licensed under the [MIT license](LICENSE). |
0 commit comments