Skip to main content

MrScraper Python SDK

An async Python client for MrScraper content fetching, Google SERP, and account status. Requires Python 3.9+.

Install and authenticate

python -m pip install -e .
export MRSCRAPER_API_TOKEN="YOUR_TOKEN"

These commands install the current checkout. To install version 0.6.0 from PyPI, run python -m pip install --upgrade mrscraper-sdk==0.6.0. The client reads MRSCRAPER_API_TOKEN automatically. You can also pass token="YOUR_TOKEN" to MrScraper. Pass http_client= if you want to reuse your own httpx.AsyncClient; otherwise the SDK creates one per request. All three methods are async and must be awaited.

Version 0.6.0

Version 0.6.0 restores await client.account() alongside scraper_api and web_search. Account status includes identity, subscription, token quota, and rate limits, with API keys and billing identifiers excluded.

Migrating to 0.5.0

Version 0.5.0 renames two public methods. Update existing calls as follows:

Previous method New method
client.fetch_content(...) client.scraper_api(...)
client.google_serp(...) client.web_search(...)

The previous method names have been removed. Arguments and response formats are unchanged from 0.4.0.

Scraper API

import asyncio
from mrscraper import MrScraper

async def main():
    client = MrScraper()
    result = await client.scraper_api("https://example.com")
    print(result["data"])

asyncio.run(main())

scraper_api sends a POST request to https://api.mrscraper.com. The JSON body contains the target URL, maxRetries, and optional tokenCap. Page options and the token are query parameters. The return value has status_code, data, and headers keys. The SDK parses JSON responses into Python values and returns other responses as text. Depending on the requested options, data may contain HTML, Markdown, a screenshot, or a combination; inspect the returned value before assuming it is an HTML string.

To request HTML, Markdown, and a screenshot together:

import asyncio
from mrscraper import MrScraper

async def main():
    client = MrScraper()
    result = await client.scraper_api(
        "https://example.com",
        html=True,
        markdown=True,
        screenshot=True,
        super=True,
    )
    print(result["data"])

asyncio.run(main())

Setting screenshot=True also enables browser rendering, even if browser_rendering=False is passed.

Option Default Description
url required Target URL
html, markdown True, False Request HTML, Markdown, or both
timeout 120 Page timeout in seconds, from 1 to 300
geo_code, proxy_country "US", None Geolocation country code and optional proxyCountry field
browser_rendering None True to force browser rendering, False to disable it, or None for automatic fallback
screenshot False Capture a screenshot; also forces browser rendering
super False Enable real device routing
use_proxy, proxy True, None Allow a proxy or supply username:password@host:port
home_page False Visit the site's root first; sent as warmStart=true
wait_for_selector None Wait for a CSS selector
block_resources, bypass_proxy False, False Block images, CSS, and fonts, or enable the API's proxy bypass behavior
cookie_jar, headers None, None Cookie configuration string and target request headers (dictionary or JSON string)
max_retries, token_cap 3, None Retry controls
stream None Request a streamed response, buffered by the SDK
discard_token_secret "" Value for the x-discard-token-secret header
import asyncio
from mrscraper import MrScraper

async def main():
    client = MrScraper()
    result = await client.web_search(
        "python web scraping",
        raw=False,
        region="us",
        language="en",
        page=1,
        format="json",
    )
    print(result["data"])

asyncio.run(main())

web_search sends a POST request to https://sync.scraper.mrscraper.com/api/google/serp/v2/sync. The first argument accepts query text or a full Google search URL; for a URL, the client extracts q, gl, hl, and start. Explicit options override values from the URL. The return value has status_code, data, and headers keys. raw=True is the default and requests HTML; set raw=False to use format.

Option Default Description
url required Search query or Google search URL
raw True Request HTML when true, regardless of format
format "json" "json" or "html" when raw=False
region, language None, None Country and language
page None One based results page
render_js False Render JavaScript features
timeout 600.0 Request timeout in seconds

Account status

import asyncio
from mrscraper import MrScraper

async def main():
    result = await MrScraper().account(timeout=30)
    print(result["data"]["subscription_status"])
    print(result["data"]["token_remaining"])
    print(result["data"]["user"]["email"])

asyncio.run(main())

account() sends GET https://api.app.mrscraper.com/api/v1/subscription-accounts using the client's token in Bearer and x-api-token headers. The timeout defaults to 30 seconds and must be positive. The response has status_code, data, and headers keys. data contains subscription_status, enterprise, token_usage, token_limit, token_remaining, usage_percent, rate_limit, rate_ttl, auto_renew, ends_at, and user (name, email, verified). Remaining tokens are clamped to zero when usage exceeds the limit. API keys, billing identifiers, and sensitive response headers are excluded.

Smoke test this checkout

file.py runs one live request per invocation. Set your token first, then run:

export MRSCRAPER_API_TOKEN="YOUR_MRSCRAPER_API_TOKEN"
python file.py account --timeout 30
python file.py fetch-content --url "https://example.com" --super
python file.py google-serp --query "site:example.com" --format json

The account command calls account() from the local SDK checkout. A successful request prints HTTP 200 followed by the account summary, including subscription status, token usage, remaining tokens, and user details. API or timeout errors print ERROR and exit with a nonzero status. Use your MrScraper API token from the app.

The fetch-content command calls scraper_api() and enables screenshot=true and warmStart=true by default. Pass --super to enable real device routing; the printed request URL should contain super=true. The google-serp command calls web_search() and requests JSON by default.

Use python file.py --help for the available options. Add --save-dir manual_results to save a full JSON response.

Publishing a release

Publishing is manual. Choose a version that has not been published to PyPI and set it in both pyproject.toml and src/mrscraper/__init__.py. This checkout is prepared for 0.6.0. From the repository root, run:

python -m pip install build twine pytest pytest-asyncio
python -m pip install -e .
python -m pytest -m "not integration" -q
python -m build --outdir dist/manual-0.6.0
ls dist/manual-0.6.0
python -m twine check dist/manual-0.6.0/mrscraper_sdk-0.6.0*
python -m twine upload --username __token__ dist/manual-0.6.0/mrscraper_sdk-0.6.0*

Before uploading, confirm that ls shows only the intended 0.6.0 files. Twine prompts for a PyPI API token as the password. Do not upload older files from dist/.

Errors

MrScraperError is the base exception. AuthenticationError indicates a missing or invalid token, APIError carries an HTTP status_code, and NetworkError indicates a connection or timeout failure.

Scraping login-protected pages can carry legal and compliance risks. Check the target site's terms and applicable law before automating access.

License

MIT © MrScraper

Metadata

Release files for mrscraper-sdk 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mrscraper-sdk 0.6.0
File Size Uploaded
mrscraper_sdk-0.6.0.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mrscraper-sdk 0.6.0
File Interpreter ABI Platform
mrscraper_sdk-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / mrscraper_sdk-0.6.0.tar.gz

Download URL mrscraper_sdk-0.6.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b654376286e3442638790f50147e4ecd8e63e50021e685b121b0b98c242bc68f
BLAKE2b-256 checksum
How to use checksums
02cd8ece7a9b0a64bf596b970f940dfa1ad1fd8fc0c93396811536b24946a811
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / mrscraper_sdk-0.6.0-py3-none-any.whl

Download URL mrscraper_sdk-0.6.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62bc17807b0f4d04777727baf5e8259848541c585c469f64da16407e31d2ebcf
BLAKE2b-256 checksum
How to use checksums
604912f7c452855a8b1b785066366d0bbd416561fc12367ae3c93e38c563a76b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page