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
- Quick Start
- Core APIs
- Configuration
- Output Formats
- Error Handling
- Requirements
- Development
- License
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
- Get an API key from xcrawl.com.
- Set
XCRAWL_API_KEYor passapi_keydirectly.
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:
markdownhtmlraw_htmllinkssummaryscreenshotjson
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xcrawl-1.1.1.tar.gz.
File metadata
- Download URL: xcrawl-1.1.1.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7daeab6796bac0733cb917548fd0725dbc665fdfb64ebfd0ce539fa680059fc5
|
|
| MD5 |
ace7895cee88ba498b3f065f369b1d05
|
|
| BLAKE2b-256 |
898a5aa1bd68ff450ad31a2dc96a2fc6ea98a1d9c607327cc2ee7ae8a3985d29
|
File details
Details for the file xcrawl-1.1.1-py3-none-any.whl.
File metadata
- Download URL: xcrawl-1.1.1-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6748df9160e5c13a44880167757fd196aa6b28b224c8d5f7d49de2ed2b98e384
|
|
| MD5 |
b2d1c6cc44cc8f43d967c45fe2f24839
|
|
| BLAKE2b-256 |
ce0274ef5668e1a994c4c6f861c1c9867538ec3548671dd90ab3899e95e3aebb
|