Async web search library supporting Google, Wikipedia, arXiv, NewsAPI, GitHub, and PubMed data sources.
Project description
Web Search
Async web search library supporting Google Custom Search, Wikipedia, arXiv, NewsAPI, GitHub, and PubMed data sources.
You can search across multiple sources and retrieve relevant, clean results in JSON format or as compiled text.
🌟 Features
- ⚡ Asynchronous Searching: Perform searches concurrently across multiple sources
- 🔗 Multi-Source Support: Query Google Custom Search, Wikipedia, arXiv, NewsAPI, GitHub, and PubMed
- 🧹 Content extraction and cleaning
- 🔧 Configurable Search Parameters: Adjust maximum results, preview length, and sources.
📋 Prerequisites
- 🐍 Python 3.8 or newer
- 🔑 API keys and configuration:
- Google Search: Requires a Google API key and a Custom Search Engine (CSE) ID.
- NewsAPI: Requires a free API key from newsapi.org.
- arXiv: No API key required.
- Wikipedia: No API key required.
- GitHub: No API key required.
- PubMed: No API key required.
Set environment variables:
export GOOGLE_API_KEY="your_google_api_key"
export CSE_ID="your_cse_id"
export NEWSAPI_KEY="your_newsapi_key"
📦 Installation
pip install async-web-search
🛠️ Usage
Example 1: Search across multiple sources
from web_search import WebSearch, WebSearchConfig
config = WebSearchConfig(sources=["google", "arxiv", "github", "newsapi", "pubmed"])
results = await WebSearch(config).search("quantum computing")
# results is a list of dicts with keys: url, title, preview, source
for result in results:
print(f"Title: {result['title']}")
print(f"URL: {result['url']}")
print(f"Preview: {result['preview']}")
print(f"Source: {result['source']}")
print("---")
Example 1.1: Compiled search results as string
from web_search import WebSearch, WebSearchConfig
config = WebSearchConfig(sources=["google", "arxiv", "github"])
compiled_results = await WebSearch(config).compile_search("quantum computing")
print(compiled_results) # Prints a formatted string with all results
Example 2: Google Search
from web_search import GoogleSearchConfig
from web_search.google import GoogleSearch
config = GoogleSearchConfig(
api_key="your_google_api_key",
cse_id="your_cse_id",
max_results=5
)
results = await GoogleSearch(config)._search("quantum computing")
for result in results:
print(result)
Example 3: Wikipedia Search
from web_search import BaseConfig
from web_search.wikipedia_ import WikipediaSearch
wiki_config = BaseConfig(max_results=5)
results = await WikipediaSearch(wiki_config)._search("deep learning")
for result in results:
print(result)
Example 4: ArXiv Search
from web_search import BaseConfig
from web_search.arxiv import ArxivSearch
arxiv_config = BaseConfig(max_results=3)
results = await ArxivSearch(arxiv_config)._search("neural networks")
for result in results:
print(result)
🔌 Plugin System
Need to search a data source that isn't bundled with the library? Create a plugin from PluginSearch and pass an instance via WebSearchConfig.plugins.
Example
from web_search import WebSearch, WebSearchConfig
from web_search.base import PluginSearch, SearchResult
class RedditSearch(PluginSearch):
slug = "reddit"
async def _search(self, query: str):
# ...implement Reddit search here...
return [
SearchResult(
url="https://reddit.com/r/MachineLearning/1",
title="AMA about quantum ML",
preview="I recently built a quantum ...",
source=self.slug,
)
]
# Option 1: Register the plugin in WebSearchConfig
config = WebSearchConfig(
sources=["google", "arxiv"],
plugins=[RedditSearch()]
)
results = await WebSearch(config).search("quantum computing")
# Option 2: add plugin after initializing Websearch
ws = WebSearch(config=WebSearchConfig(
sources=["google", "arxiv"],
))
ws.add_plugin(RedditSearch())
results = await ws.search("quantum computing")
Edge-cases handled automatically:
- Objects in the plugin list that do not inherit from
PluginSearchare ignored. - Exceptions raised inside a plugin are caught; other providers still return results.
🌐 Production API Server
A FastAPI-based production server is available for teams that want to use async web search as a web service. The server is hosted at https://awebs.veedo.ai and can be run locally as well.
See server/README.md for detailed API documentation, endpoints, and deployment instructions.
📘 API Overview
🔧 Configuration
- BaseConfig: Shared configuration for all sources (e.g., max_results and timeout).
- GoogleSearchConfig: Google-specific settings (e.g., api_key, cse_id).
- WebSearchConfig: Configuration for the overall search process (e.g., sources to query).
📚 Classes
- WebSearch: Entry point for performing searches across multiple sources.
- GoogleSearch: Handles searches via Google Custom Search Engine API.
- WikipediaSearch: Searches Wikipedia and retrieves article previews.
- ArxivSearch: Queries arXiv for academic papers.
⚙️ Methods
- search(query: str): Main search method for WebSearch.
- _search(query: str): Source-specific search logic for GoogleSearch, WikipediaSearch, and ArxivSearch.
🤝 Contributing
We welcome contributions! To contribute:
- Fork the repository.
- Create a new branch (git checkout -b feature-name).
- Commit your changes (git commit -am "Add new feature").
- Push to the branch (git push origin feature-name).
- Open a pull request.
🧪 Running Tests
pytest -v
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_web_search-1.2.1.tar.gz.
File metadata
- Download URL: async_web_search-1.2.1.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2280f75fd35a4f2fbfc1ddf902c22f10ddba0bcc945343dea9c3689ab46900bf
|
|
| MD5 |
a75495f2eaecb62f66b4362fd9244104
|
|
| BLAKE2b-256 |
a189d8c821c9873f8900214840bfbbd2f7bd47228613e5d7f35ad75dcc563179
|
Provenance
The following attestation bundles were made for async_web_search-1.2.1.tar.gz:
Publisher:
publish.yml on nwaughachukwuma/async-web-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_web_search-1.2.1.tar.gz -
Subject digest:
2280f75fd35a4f2fbfc1ddf902c22f10ddba0bcc945343dea9c3689ab46900bf - Sigstore transparency entry: 940842065
- Sigstore integration time:
-
Permalink:
nwaughachukwuma/async-web-search@afde233b740cb25f6e87a2dc3ebac540f43e51af -
Branch / Tag:
refs/tags/v1.2.1b - Owner: https://github.com/nwaughachukwuma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@afde233b740cb25f6e87a2dc3ebac540f43e51af -
Trigger Event:
push
-
Statement type:
File details
Details for the file async_web_search-1.2.1-py3-none-any.whl.
File metadata
- Download URL: async_web_search-1.2.1-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be6b34a9e7636269f9006672cee073f8ecf95c8e356d706e8fb883cb1256991
|
|
| MD5 |
063001e9bfd58d5003e6f8c18b3d1cf6
|
|
| BLAKE2b-256 |
060f85bd65fb1b8031f9cbc808f506049b0d39c4c41b38bb2d03f330b89bbc09
|
Provenance
The following attestation bundles were made for async_web_search-1.2.1-py3-none-any.whl:
Publisher:
publish.yml on nwaughachukwuma/async-web-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_web_search-1.2.1-py3-none-any.whl -
Subject digest:
8be6b34a9e7636269f9006672cee073f8ecf95c8e356d706e8fb883cb1256991 - Sigstore transparency entry: 940842070
- Sigstore integration time:
-
Permalink:
nwaughachukwuma/async-web-search@afde233b740cb25f6e87a2dc3ebac540f43e51af -
Branch / Tag:
refs/tags/v1.2.1b - Owner: https://github.com/nwaughachukwuma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@afde233b740cb25f6e87a2dc3ebac540f43e51af -
Trigger Event:
push
-
Statement type: