Skip to main content

Official Python SDK for CrawlGate Search Engine API

Project description

CrawlGate Python SDK

Official Python SDK for CrawlGate - AI-powered web scraping platform.

PyPI version Python versions License: MIT

Installation

pip install crawlgate

Quick Start

from crawlgate import CrawlGateClient

# Initialize client
client = CrawlGateClient(api_key="sk_live_...")

# Scrape a single URL
doc = client.scrape("https://example.com")
print(doc.markdown)

Features

  • Scrape - Extract content from any URL
  • Crawl - Recursively crawl websites
  • Map - Discover all URLs on a website
  • Search - Web search with optional scraping
  • Extract - LLM-powered structured data extraction

Usage Examples

Scrape a URL

from crawlgate import CrawlGateClient

client = CrawlGateClient(api_key="sk_live_...")

# Basic scrape
doc = client.scrape("https://example.com")
print(doc.markdown)

# With options
doc = client.scrape(
    "https://example.com",
    engine="dynamic",  # Use headless browser
    formats=["markdown", "html"],
    only_main_content=True
)
print(doc.html)

Crawl a Website

# Crawl and wait for completion
job = client.crawl(
    "https://example.com",
    limit=50,
    engine="dynamic"
)

print(f"Crawled {job.completed} pages")
for page in job.data:
    print(f"- {page.url}: {len(page.markdown or '')} chars")

Async Crawl (Manual Polling)

import time

# Start crawl job
response = client.start_crawl("https://example.com", limit=100)
print(f"Job started: {response.id}")

# Poll for status
while True:
    job = client.get_crawl_status(response.id)
    print(f"Status: {job.status}, Completed: {job.completed}/{job.total}")

    if job.status in ["completed", "failed"]:
        break

    time.sleep(2)

# Process results
for page in job.data:
    print(page.url)

Map a Website

# Discover all URLs
result = client.map("https://example.com")

print(f"Found {result.count} URLs:")
for url in result.links:
    print(url)

Web Search

# Search the web
results = client.search(
    "best python web scraping libraries 2024",
    limit=10,
    lang="en",
    country="us"
)

for result in results.data:
    print(f"{result.title}: {result.url}")

# Search with scraping
results = client.search(
    "python tutorials",
    limit=5,
    scrape_options={"formats": ["markdown"]}
)

for result in results.data:
    print(f"\n{result.title}")
    print(result.markdown[:500] if result.markdown else "No content")

LLM Extraction

# Extract structured data
result = client.extract(
    urls=["https://example.com/product"],
    schema={
        "type": "object",
        "properties": {
            "name": {"type": "string"},
            "price": {"type": "number"},
            "in_stock": {"type": "boolean"},
            "features": {
                "type": "array",
                "items": {"type": "string"}
            }
        },
        "required": ["name", "price"]
    },
    system_prompt="Extract product details from the page",
    provider="openai"
)

print(result.data)

Scrape with LLM Extraction

doc = client.scrape(
    "https://example.com/product",
    extract={
        "schema": {
            "type": "object",
            "properties": {
                "title": {"type": "string"},
                "price": {"type": "number"}
            }
        },
        "systemPrompt": "Extract the product info",
        "provider": "openai"
    }
)

print(doc.extract.data)

Batch Scrape

urls = [
    "https://example.com/page1",
    "https://example.com/page2",
    "https://example.com/page3"
]

# Scrape multiple URLs
job = client.batch_scrape(
    urls,
    options={"formats": ["markdown"], "engine": "smart"}
)

print(f"Scraped {job.completed} URLs")
for doc in job.data:
    print(f"- {doc.url}: {len(doc.markdown or '')} chars")

Usage Monitoring

# Check concurrency
concurrency = client.get_concurrency()
print(f"Using {concurrency.concurrency}/{concurrency.max_concurrency} slots")

# Check credits
credits = client.get_credit_usage()
print(f"Remaining credits: {credits.remaining_credits}")

Engine Types

Engine Description Best For
static Axios + Cheerio (fast) Simple pages, APIs
dynamic Headless browser (Playwright) JS-heavy sites
smart Auto-selects based on content General use, LLM extraction

Error Handling

from crawlgate import CrawlGateClient
from crawlgate.errors import (
    CrawlGateError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    TimeoutError
)

client = CrawlGateClient(api_key="sk_live_...")

try:
    doc = client.scrape("https://example.com")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except ValidationError as e:
    print(f"Invalid request: {e.message}")
except TimeoutError:
    print("Request timed out")
except CrawlGateError as e:
    print(f"Error: {e.message}")

Environment Variables

export CRAWLGATE_API_KEY="sk_live_..."
export CRAWLGATE_API_URL="https://api.crawlgate.io"  # Optional
# API key will be read from environment
client = CrawlGateClient()

API Reference

CrawlGateClient

CrawlGateClient(
    api_key: str = None,      # API key (or CRAWLGATE_API_KEY env)
    api_url: str = None,      # Base URL (or CRAWLGATE_API_URL env)
    timeout: int = 90,        # Request timeout in seconds
    max_retries: int = 3      # Max retry attempts
)

Methods

Method Description
scrape(url, **options) Scrape a single URL
crawl(url, **options) Crawl website and wait for completion
start_crawl(url, **options) Start async crawl job
get_crawl_status(job_id) Get crawl job status
cancel_crawl(job_id) Cancel crawl job
map(url, **options) Discover URLs on a website
search(query, **options) Web search
extract(urls, schema, **options) LLM extraction
batch_scrape(urls, **options) Batch scrape URLs
get_concurrency() Get concurrency usage
get_credit_usage() Get credit usage

License

MIT License - see LICENSE for details.

Support

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

crawlgate-1.0.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

crawlgate-1.0.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file crawlgate-1.0.1.tar.gz.

File metadata

  • Download URL: crawlgate-1.0.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for crawlgate-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8af30402cf7c40e79ade2ea8c6d0d7b93107d39bc0a4b2281ec777fc697723db
MD5 dbd9e2a9232000ec0f198a6fdd1f5b2f
BLAKE2b-256 de8554d7919aebfb0ee5a8d186ef84448c8bfe9da577699b01875ddcd45d8167

See more details on using hashes here.

File details

Details for the file crawlgate-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: crawlgate-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for crawlgate-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c57a0be6b267b261d811128c02324d8669c34c08ff88219a2e61fe52282bb05
MD5 fb0ad9e82815795aa902d37f55826b6d
BLAKE2b-256 33f53376e754572e68d3356f8ca99ac19b3b9ed68785368b938eb01da990c95d

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