[Feature request] Make `async: True` do everything under the hood
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start by reading the example.py and async_search.py examples in the issue, then inspect the repository's existing asynchronous batch-search documentation and public search entry points. Define the intended API and completion behavior before changing anything; done should provide a supported user-facing helper that handles queueing and archive retrieval without requiring users to implement that flow.
Written by the indexing model from the issue text.
Description
From a user perspective, the less setup required the better. I personally find the second example (example.py) more user-friendly especially for non-very technical users.
The user has to just add an async: True and don't bother tinkering/figuring out stuff for another ~hour about how Queue or something else works.
@jvmvik @ilyazub @hartator what do you guys think?
@aliayar @marm123 @schaferyan have you guys noticed similar issues for the users or have any users requested similar things?
What if instead of this:
# async batch requests: https://github.com/serpapi/google-search-results-python#batch-asynchronous-searches
from serpapi import YoutubeSearch
from queue import Queue
import os, re, json
queries = [
'burly',
'creator',
'doubtful'
]
search_queue = Queue()
for query in queries:
params = {
'api_key': '...',
'engine': 'youtube',
'device': 'desktop',
'search_query': query,
'async': True, # ❗
'no_cache': 'true'
}
search = YoutubeSearch(params)
results = search.get_dict()
if 'error' in results:
print(results['error'])
break
print(f"Add search to the queue with ID: {results['search_metadata']}")
search_queue.put(results)
data = []
while not search_queue.empty():
result = search_queue.get()
search_id = result['search_metadata']['id']
print(f'Get search from archive: {search_id}')
search_archived = search.get_search_archive(search_id)
print(f"Search ID: {search_id}, Status: {search_archived['search_metadata']['status']}")
if re.search(r'Cached|Success', search_archived['search_metadata']['status']):
for video_result in search_archived.get('video_results', []):
data.append({
'title': video_result.get('title'),
'link': video_result.get('link'),
'channel': video_result.get('channel').get('name'),
})
else:
print(f'Requeue search: {search_id}')
search_queue.put(result)
Users can do something like this and we handle everything under the hood:
# example.py
# testable example
# example import: from serpapi import async_search
from async_search import async_search
import json
queries = [
'burly',
'creator',
'doubtful',
'minecraft'
]
# or as we typically pass params dict
data = async_search(queries=queries, api_key='...', engine='youtube', device='desktop')
print(json.dumps(data, indent=2))
print('All searches completed')
Under the hood code example:
# async_search.py
# testable example
from serpapi import YoutubeSearch
from queue import Queue
import os, re
search_queue = Queue()
def async_search(queries, api_key, engine, device):
data = []
for query in queries:
params = {
'api_key': api_key,
'engine': engine,
'device': device,
'search_query': query,
'async': True,
'no_cache': 'true'
}
search = YoutubeSearch(params)
results = search.get_dict()
if 'error' in results:
print(results['error'])
break
print(f"Add search to the queue with ID: {results['search_metadata']}")
search_queue.put(results)
while not search_queue.empty():
result = search_queue.get()
search_id = result['search_metadata']['id']
print(f'Get search from archive: {search_id}')
search_archived = search.get_search_archive(search_id)
print(f"Search ID: {search_id}, Status: {search_archived['search_metadata']['status']}")
if re.search(r'Cached|Success', search_archived['search_metadata']['status']):
for video_result in search_archived.get('video_results', []):
data.append({
'title': video_result.get('title'),
'link': video_result.get('link'),
'channel': video_result.get('channel').get('name'),
})
else:
print(f'Requeue search: {search_id}')
search_queue.put(result)
return data
Is there a specific reason we haven't done it before?
- Dominant language
- Python
- Stars
- 756
- Forks
- 118
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from serpapi/google-search-results-python
-
Broken link Open
Difficulty 1/5 Under an hour Newbie friendliness 68/100
serpapi/google-search-results-python#70 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
serpapi/google-search-results-python#84 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
serpapi/google-search-results-python#76 · 1 comment ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
serpapi/google-search-results-python#72 · 1 comment · 1 reaction ·
All issues in serpapi/google-search-results-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100