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'])

result['data'] is dynamic and may vary by backend response. Stable fields include credits_used and credits_detail.

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.1.0.tar.gz (20.5 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.1.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xcrawl-1.1.0.tar.gz
Algorithm Hash digest
SHA256 60e5f5cd7d452d7f9a1c6994e4fc9349ee6cfc89a3e24a639bff67dde3ae1629
MD5 78f5578d40ccebe905ba8323f2759726
BLAKE2b-256 50d2d5cbe1f9d06ebc4e36ee9234454d01a4b20ee9797ca29f3e0d02e8dc4ba8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xcrawl-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8dd45923a1bca5a06b13d6a624f82d069525b8ae216557831b4d1c29c32bcbe3
MD5 7e3fbe7b49720917ee75130b63bd9e14
BLAKE2b-256 fea10ecbbde068b8ae21896fc90e1cce2f878d217d3f6e5df6e9ec0d24ae25d8

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