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.
Balance
balance = client.get_balance()
print(balance['credits'])
print(balance['expire_at'])
print(balance['expire_at_utc'])
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
Metadata
Release files for xcrawl 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xcrawl-1.1.2.tar.gz | 21.7 kB | Without provenance | Details for xcrawl-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xcrawl-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for xcrawl-1.1.2-py3-none-any.whl |
Total release size: 46.5 kB
Release files / xcrawl-1.1.2.tar.gz
| Download URL | xcrawl-1.1.2.tar.gz |
|---|---|
| Size | 21.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35eacefca4b75c8899fcef0f5b579e15c6e6bd638b77f9026b5faaa8236e9f1f
|
|
BLAKE2b-256 checksum How to use checksums |
04b095e845026f2735d478f0d189220d5b174428ff408be8945533b81d940357
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Release files / xcrawl-1.1.2-py3-none-any.whl
| Download URL | xcrawl-1.1.2-py3-none-any.whl |
|---|---|
| Size | 24.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42b702fe75e1da6885a5bf53a40c3c5a9d7486a81f1b23a140a5e13ef83196a7
|
|
BLAKE2b-256 checksum How to use checksums |
61f0a8e1a927d3d452c8aa25e280454b0c428e9a44c0617d2d12dde7827d6887
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Security for xcrawl 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.