Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.geekflare.com/llms.txt

Use this file to discover all available pages before exploring further.

The official geekflare-api SDK provides a Pythonic interface that handles auth and serialization. Raw requests examples are included for those who prefer no extra dependencies.

Prerequisites

  • Python 3.8+
  • pip or uv
  • A Geekflare API key — get one free

Installation

bash pip install geekflare-api

Set your API key

Create a .env file:
.env
GEEKFLARE_API_KEY=your_api_key_here
Load it in your script:
from dotenv import load_dotenv
import os

load_dotenv()
API_KEY = os.environ["GEEKFLARE_API_KEY"]
Never hardcode your API key. Add .env to .gitignore.

Initialize the client

from geekflare_api.client import GeekflareClient

client = GeekflareClient(api_key=os.environ["GEEKFLARE_API_KEY"])
The client is a context manager — use with to ensure the underlying HTTP session is closed:
with GeekflareClient(api_key=os.environ["GEEKFLARE_API_KEY"]) as client:
    # make calls here
    pass

Web Scraping

import os
from dotenv import load_dotenv
from geekflare_api.client import GeekflareClient
from geekflare_api.models import WebScrapeDto

load_dotenv()

with GeekflareClient(api_key=os.environ["GEEKFLARE_API_KEY"]) as client:
    result = client.web_scrape(
        WebScrapeDto(
            url="https://toscrape.com/",
            renderJS=True,
            blockAds=True,
            format="html,markdown",
            device="desktop",
        )
    )
    print(result)
Key parameters:
ParameterTypeDescription
urlstrRequired. The URL to scrape
renderJSboolWait for JavaScript to execute
blockAdsboolBlock ads before scraping
formatstrComma-separated: html, markdown
devicestr"desktop" or "mobile"
proxyCountrystrRoute via country code, e.g. "us"
stealthboolEnable stealth mode
waitTimefloatExtra wait time in seconds
Example response:
{
  "timestamp": 1779703261268,
  "apiStatus": "success",
  "apiCode": 200,
  "meta": {
    "url": "https://toscrape.com/",
    "device": "desktop",
    "format": ["html-llm"],
    "blockAds": true,
    "renderJS": true,
    "test": { "id": "mxqx9v9y0742lap6altwdteqd28t23nq" }
  },
  "data": "https://example.com/9bulgk075ed9m3vhua5vcrp0.html"
}
The data field is a URL to the scraped output file. See the Web Scraping endpoint reference.
import os
from dotenv import load_dotenv
from geekflare_api.client import GeekflareClient
from geekflare_api.models import SearchDto

load_dotenv()

with GeekflareClient(api_key=os.environ["GEEKFLARE_API_KEY"]) as client:
    result = client.search(
        SearchDto(
            query="best Python web frameworks",
            limit=10,
            location="us",
            source="web",
            time="m",
            format="json",
        )
    )
    print(result)
Key parameters:
ParameterTypeDescription
querystrRequired. The search query
limitintNumber of results (default: 10)
locationstrCountry code for localized results, e.g. "us"
sourcestr"web", "news", etc.
timestrRecency filter: "d" (day), "w" (week), "m" (month)
includeDomainslist[str]Only return results from these domains
excludeDomainslist[str]Exclude results from these domains

Screenshot

import os
from dotenv import load_dotenv
from geekflare_api.client import GeekflareClient
from geekflare_api.models import ScreenshotDto

load_dotenv()

with GeekflareClient(api_key=os.environ["GEEKFLARE_API_KEY"]) as client:
    result = client.screenshot(
        ScreenshotDto(
            url="https://example.com",
            type="png",
            fullPage=True,
            device="desktop",
            viewportWidth=1280,
            viewportHeight=800,
            blockAds=True,
            hideCookie=True,
            quality=90,
        )
    )
    print(result)

Error handling

import os
from dotenv import load_dotenv
from geekflare_api.client import GeekflareClient
from geekflare_api.models import WebScrapeDto
from geekflare_api.exceptions import ApiException

load_dotenv()

try:
    with GeekflareClient(api_key=os.environ["GEEKFLARE_API_KEY"]) as client:
        result = client.web_scrape(WebScrapeDto(url="https://toscrape.com/"))
        print(result)

except ApiException as e:
    print(f"API error {e.status}: {e.reason}")

    if e.status == 401:
        print("Invalid or missing API key.")
    elif e.status == 402:
        print("API credits exhausted. Top up at dash.geekflare.com.")
    elif e.status == 403:
        print("This endpoint is not available on your current plan.")
    elif e.status == 429:
        print("Rate limit exceeded. Back off and retry.")

except Exception as e:
    print(f"Unexpected error: {e}")

Common error codes

CodeMeaning
401Missing or invalid x-api-key
402API credits exhausted
403Endpoint requires a higher plan
404Wrong endpoint URL or HTTP method
429Rate limit exceeded

Next steps