Skip to main content

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:

  • title
  • link
  • snippet
  • display_link
  • formatted_url
  • html_title
  • html_snippet
  • kind
  • pagemap

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gfg_search-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gfg_search-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

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

Hashes for gfg_search-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09c49cd1b4881e97dc64cdb310dd44fcb4ac75aef1e91528a994997d12ab61a5
MD5 f8a101115399f3ae16191b7a57e9059a
BLAKE2b-256 19234e73b2901c3096d68d56732fc9abc8dcbfc5d1d8c32dd69c47671ffee4e2

See more details on using hashes here.

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

Hashes for gfg_search-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 049a9c95f8e998a7c281e9413e2012dd665d16f233c7598c4f42f1379986d5c0
MD5 bb9223f74a700442a9b1a27e28801df5
BLAKE2b-256 e1f35afe11d15aa87ea493edc22009443daa36867a5b30dd55995faed3876e77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page