Skip to main content

Official Python SDK for XCrawl - A powerful web scraping API service

Project description

XCrawl Python SDK

XCrawl Python SDK provides an interface to the XCrawl API, including scraping, search, sitemap discovery, and site crawling.

Table of Contents

Installation

Install from PyPI:

pip install xcrawl

Install from source:

git clone <repository-url>
cd <repo-dir>/xcrawl-sdk-py
pip install -e .

Quick Start

  1. Get an API key from xcrawl.com.
  2. Set XCRAWL_API_KEY or pass api_key directly.
export XCRAWL_API_KEY=your-api-key
from xcrawl import XcrawlClient

client = XcrawlClient()

# Sync scrape
sync_result = client.scrape('https://example.com', {
    'output': {'formats': ['markdown']}
})
print(sync_result['data']['markdown'])

# Async scrape + auto polling
job = client.scrape('https://example.com', {
    'mode': 'async',
    'output': {'formats': ['markdown', 'summary']}
})
result = client.wait_for_job(job['scrape_id'], timeout=60)
print(result['status'])

Core APIs

Scrape

result = client.scrape('https://example.com', {
    'proxy': {'location': 'US'},
    'request': {
        'device': 'desktop',
        'only_main_content': True,
        'block_ads': True,
    },
    'output': {
        'formats': ['html', 'markdown', 'links', 'screenshot'],
        'screenshot': 'full_page'
    }
})

Async Status Check

status = client.get_job_result('scrape-id-123')
if status['status'] == 'completed':
    print(status['data']['markdown'])
elif status['status'] == 'failed':
    print(status.get('message'))

Structured Extraction (json format)

output.json.prompt and output.json.json_schema are both optional.

result = client.scrape('https://example.com', {
    'output': {
        'formats': ['json'],
        'json': {
            'prompt': 'Extract product name and price',
            'json_schema': {
                'type': 'object',
                'properties': {
                    'name': {'type': 'string'},
                    'price': {'type': 'number'}
                }
            }
        }
    }
})

Search

result = client.search({
    'query': 'web scraping',
    'location': 'New York, NY',
    'language': 'en',
    'limit': 10
})
print(result['data']['organic_results'])

Map

result = client.map('https://example.com', {
    'filter': r'.*\.html$',
    'limit': 1000,
    'include_subdomains': True,
    'ignore_query_parameters': True
})
print(result['data']['links'])

Crawl

job = client.crawl('https://example.com', {
    'crawler': {
        'limit': 100,
        'max_depth': 3,
        'include': [r'.*\.html$'],
        'exclude': [r'.*/admin/.*']
    },
    'output': {'formats': ['markdown']}
})

crawl_status = client.get_crawl_status(job['crawl_id'])
print(crawl_status['status'])

Webhook (Async)

client.scrape('https://example.com', {
    'mode': 'async',
    'webhook': {
        'url': 'https://your-server.com/webhook',
        'events': ['completed', 'failed']
    }
})

Configuration

client = XcrawlClient(
    api_key='your-api-key',
    api_url='https://run.xcrawl.com',
    timeout=60,
    max_retries=3,
    backoff_factor=0.5,
)

Retry behavior:

  • Retries: HTTP 5xx and network failures
  • No retry: HTTP 4xx and validation errors

Output Formats

Supported values in output.formats:

  • markdown
  • html
  • raw_html
  • links
  • summary
  • screenshot
  • json

If output.formats is omitted or set to [], the response returns metadata only.

Error Handling

from xcrawl import XcrawlClient, XcrawlError, JobTimeoutError

client = XcrawlClient(api_key='your-api-key')

try:
    result = client.scrape('https://example.com', {
        'output': {'formats': ['markdown']}
    })
    print(result['data']['markdown'])
except JobTimeoutError as error:
    print(f'Job {error.job_id} timed out after {error.timeout_seconds}s')
except XcrawlError as error:
    print(error.code, error.message, error.status, error.request_id)

Requirements

  • Python >= 3.8

Development

pip install -e ".[dev]"
pytest
black xcrawl
mypy xcrawl

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

xcrawl-1.0.1.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

xcrawl-1.0.1-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xcrawl-1.0.1.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for xcrawl-1.0.1.tar.gz
Algorithm Hash digest
SHA256 403247277b47e62355a5281fbe37193fe72502917a366cd7946ccb5fc9ecf7cd
MD5 11a47cb27147fb3e1f711d178fc071fc
BLAKE2b-256 212afa4523743983e2fe2cce6d48d34781b43b7cfb884ff4a9ca79805fc25308

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xcrawl-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for xcrawl-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e40a57f17665a564e5109e0ddceaae43fb12dff936b69b5bdb14f5cca8e9464
MD5 d3a0eb5efdf20c6d5b1fcdc4e894f3ed
BLAKE2b-256 fe05b220fcda4195b99c9abe1cc93de7c3539204bfd71e8897b783f579348223

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