Skip to content

Commit fd3a3de

Browse files
committed
Updates readme
1 parent 7ddace7 commit fd3a3de

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

README.md

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
# Introducing Algolia's API Client Python v2
1+
**Note:** The readme/code you are seeing it's part of upcoming release: Algolia API Client Python v2.
22

3-
Release of v2: No date is set, but this should happen sometime in end-March/begin-April.
3+
Algolia's Python client provides the perfect starting point to integrate
4+
Algolia into your Python application. It is carefully crafted to simplify the usage
5+
of Algolia within your Python Project.
46

57
## Preface
68

7-
Big news, the Algolia's API Client Python v2 is coming! So, what changes can we look forward for this API Client?
9+
- Features tons of features: contains waitable response objects, up-to-date retry strategy, `replace_all_objects`,`clear_objects`, and more!
10+
11+
- Supports Python: **2.7 🥳**, 3.4, 3.5, 3.6, and 3.7.
12+
13+
- Strong test suite, 100% test coverage on `unittest` (tests === **30secs locally!** 🏎), `flake8`
14+
(linter), and `mypy` (static-analysis) to ensure the quality of the code.
815

9-
- Follows 100% of the **API Client v2 specs**, just like PHP v2, and c# v2: contains waitable response objects, up-to-date retry strategy, `replace_all_objects`,`clear_objects`, and more
10-
- Supports Python: **2.7 🥳**, 3.4, 3.5, 3.6, and 3.7
11-
- Strong test suite, 100% test coverage on `unittest` (tests === **30secs locally!** 🏎), `flake8` (linter), and `mypy` (static-analysis) to ensure the quality of the code.
1216
- Supports synchronous and **asynchronous** environments. 👉🏻 **Yes, in the same client and with support Python 2. It's amazing!** Asynchronous methods are available using the `async` suffix:
1317

1418
| synchronous | asynchronous |
@@ -21,11 +25,10 @@ Big news, the Algolia's API Client Python v2 is coming! So, what changes can we
2125

2226
Thank you for considering to contribute to Algolia's API Client Python v2. Here is the list of tasks that I would love to get your help:
2327

24-
1. Using Python v1 within Algolia for non-critical projects? Start using this v2 today! Found a bug? Report it here: [https://github.com/algolia/algoliasearch-client-python](https://github.com/algolia/algoliasearch-client-python).
25-
2. Have experience in Python? Check if the code/structure *Pythonic*
26-
3. Coming from Java, or another robust language? Take a moment to analyze the quality of the code
27-
4. Are you a test addicted like me? Take a moment to analyze the quality of tests
28-
5. Play with the client.
28+
1. Using Python v1 within Algolia for non-critical projects? Start using this v2 today!
29+
3. Analyze the code quality
30+
4. Analyze the quality of tests
31+
5. Create a [free account](https://www.algolia.com/users/sign_up/hacker) at Algolia, and play with this client.
2932

3033
## Get started locally
3134

@@ -34,12 +37,21 @@ Thank you for considering to contribute to Algolia's API Client Python v2. Here
3437

3538
First, use [Homebrew](https://brew.sh) to install Python 3.7:
3639
```bash
37-
brew install python
38-
```
40+
# Install Python 3
41+
brew install python3
3942

40-
Then, install `pip`:
41-
```
42-
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py
43+
# Create your Python project directory
44+
mkdir my-new-project
45+
cd my-new-project
46+
47+
# Create a Python Virtual Environment inside your directory
48+
python3 -m venv venv
49+
50+
# Activate the Python Virtual Environment
51+
source venv/bin/activate
52+
53+
# At any time, use the following command to deactivate it
54+
deactivate
4355
```
4456

4557
Finally, install `algoliasearch` - API Client Python v2:
@@ -82,40 +94,34 @@ pip install 'asyncio>=3.4,<4.0' 'aiohttp>=2.0,<4.0' 'async_timeout>=2.0,<4.0'
8294

8395

8496
```py
97+
import asyncio
8598
import os
8699

87100
from algoliasearch.search_client import SearchClient
88101
from algoliasearch.exceptions import AlgoliaException
89102
from algoliasearch.responses import MultipleResponse
90103

91-
client = SearchClient.create(
92-
os.environ.get('ALGOLIA_APPLICATION_ID_1'),
93-
os.environ.get('ALGOLIA_ADMIN_KEY_1')
94-
)
104+
app_id = os.environ.get('ALGOLIA_APPLICATION_ID_1')
105+
api_key = os.environ.get('ALGOLIA_ADMIN_KEY_1')
95106

96-
index = client.init_index('articles')
97-
98-
try:
99-
index.clear_objects().wait()
100-
except AlgoliaException: # Index not found
101-
pass
102-
103-
import asyncio
104107

105-
loop = asyncio.get_event_loop()
108+
async def main():
109+
async with SearchClient.create(app_id, api_key) as client:
110+
index = client.init_index('articles')
106111

107-
tasks = [
108-
index.save_object_async({'objectID': 1, 'foo': 'bar'}),
109-
index.save_object_async({'objectID': 2, 'foo': 'bar'}),
110-
]
112+
try:
113+
(await index.clear_objects_async()).wait()
114+
except AlgoliaException: # Index not found
115+
pass
111116

112-
MultipleResponse(
113-
loop.run_until_complete(asyncio.gather(*tasks))
114-
).wait()
117+
results = await asyncio.gather(
118+
index.save_object_async({'objectID': 1, 'foo': 'bar'}),
119+
index.save_object_async({'objectID': 2, 'foo': 'foo'})
120+
)
115121

116-
result = loop.run_until_complete(index.search_async(''))
122+
MultipleResponse(results).wait()
117123

118-
loop.close()
124+
print(await index.search_async(''))
119125

120-
print(result)
126+
asyncio.run(main())
121127
```

0 commit comments

Comments
 (0)