Unofficial Python client for GeeksforGeeks search API
Project description
gfg-search
gfg-search is an unofficial Python client for the GeeksforGeeks search API.
It wraps the endpoint:
https://www.geeksforgeeks.org/gfg-assets/_next/data/<build-id>/search.json?gq=<query>
and automatically discovers the current <build-id> from the GeeksforGeeks homepage.
Features
- Simple one-line search function.
- Reusable client class with connection/session reuse.
- Typed result model via
dataclass. - Raw response access when needed.
Installation
From PyPI (after publishing):
pip install gfg-search
From local source:
pip install .
Quick Start
from gfg_search import search
results = search("dsa", max_results=5)
for item in results:
print(item.title)
print(item.link)
print(item.snippet)
print("-")
Client Usage
from gfg_search import GFGSearchClient
client = GFGSearchClient(timeout=12)
results = client.search("python")
first = results[0]
print(first.title)
print(first.link)
Raw Response Usage
from gfg_search import GFGSearchClient
client = GFGSearchClient()
raw_items = client.search_raw("graph")
print(type(raw_items))
print(raw_items[0].keys())
API Reference
search(query, *, max_results=None, timeout=10.0)
query(str): Search text.max_results(int | None): Limit the number of returned results.timeout(float): Timeout (seconds) for HTTP requests.
Returns list[SearchResult].
GFGSearchClient(timeout=10.0, base_url="https://www.geeksforgeeks.org", session=None)
Methods:
search(query, *, max_results=None) -> list[SearchResult]search_raw(query) -> list[dict]
SearchResult
Main fields:
titlelinksnippetdisplay_linkformatted_urlhtml_titlehtml_snippetkindpagemap
Error Handling
from gfg_search import GFGSearchClient, GFGSearchHTTPError, GFGSearchParsingError
client = GFGSearchClient()
try:
print(client.search("dynamic programming", max_results=3))
except GFGSearchHTTPError as exc:
print("Network error:", exc)
except GFGSearchParsingError as exc:
print("Response format error:", exc)
Notes
- This package is unofficial and not affiliated with GeeksforGeeks.
- Since this endpoint is internal to their web app, response shape or route behavior may change in future.
Development
Run a local editable install:
pip install -e .
Build distribution artifacts:
python -m build
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 gfg_search-0.1.0.tar.gz.
File metadata
- Download URL: gfg_search-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09c49cd1b4881e97dc64cdb310dd44fcb4ac75aef1e91528a994997d12ab61a5
|
|
| MD5 |
f8a101115399f3ae16191b7a57e9059a
|
|
| BLAKE2b-256 |
19234e73b2901c3096d68d56732fc9abc8dcbfc5d1d8c32dd69c47671ffee4e2
|
File details
Details for the file gfg_search-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gfg_search-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
049a9c95f8e998a7c281e9413e2012dd665d16f233c7598c4f42f1379986d5c0
|
|
| MD5 |
bb9223f74a700442a9b1a27e28801df5
|
|
| BLAKE2b-256 |
e1f35afe11d15aa87ea493edc22009443daa36867a5b30dd55995faed3876e77
|