Overview
The Scrapingbypass Python SDK is built on the psf/requests and aiohttp libraries. It features an integrated session manager that automates TLS/JA3 fingerprint impersonation and cookie persistence, eliminating the need for manual header management.
Requirements: Python 3.6+
Installation
Install the SDK via pip:
python3 -m pip install scrapingbypass -i https://pypi.org/simple
Sync Implementation (Requests-based)
The Session class inherits from requests.Session and supports all standard methods (get, post, etc.).
Initialization Parameters
apikey: Your service key from the Scrapingbypass dashboard.proxy: Your proxy endpoint.api_host: (Optional) Custom service address for dedicated users.
Note: You can also configure these via environment variables: CB_APIKEY, CB_PROXY, and CB_APIHOST.
Standard Request Example
from scrapingbypass import Session
if __name__ == '__main__':
# Initialize session with credentials
with Session(apikey="<APIKEY>", proxy="http://proxy:port") as session:
resp = session.get("https://opensea.io/category/memberships")
print(f"Status: {resp.status_code}")
print(f"Bypass Status: {resp.headers.get('x-cb-status')}")
Handling JS Challenges (V2)
To access targets protected by Cloudflare JS Challenge or WAF (e.g., Etherscan), pass the part="0" parameter to trigger the V2 engine.
from scrapingbypass import Session
if __name__ == '__main__':
with Session(apikey="<APIKEY>", proxy="http://proxy:port") as session:
# 'part="0"' activates V2 challenge solving
resp = session.get("https://etherscan.io/accounts/label/lido", part="0")
print(resp.text)
Async Implementation (Aiohttp-based)
The AsyncSession class inherits from aiohttp.ClientSession.
import asyncio
from scrapingbypass import AsyncSession
async def fetch_data():
async with AsyncSession(apikey="<APIKEY>", proxy="http://proxy:port") as session:
resp = await session.get("https://etherscan.io/accounts/label/lido", part="0")
html = await resp.text()
print(f"Status: {resp.status} | Content: {html[:50]}...")
if __name__ == '__main__':
asyncio.run(fetch_data())
Account Management
Use these methods to monitor your credit balance.
| Method | Type | Description |
|---|---|---|
get_balance("<APIKEY>") | Sync | Returns current credit balance. |
async_get_balance("<APIKEY>") | Async | Awaitable balance check. |
Proxy Configuration Manager
The ScrapingbypassProxy (aliased as Proxy) class allows for granular control over proxy rotation and geographical targeting.
Method Reference
copy(): Duplicates the object to prevent mutation of the original instance.set_dynamic(): Configures the session for dynamic rotation.set_expire(int): Sets a TTL (Time-To-Live) for sticky sessions in seconds.set_region(str): Filters IP exit nodes by country code (e.g., 'US', 'GB').limit(int, format): Returns an iterator for a specific number of proxy strings.loop(int, format): Returns a circular iterator for continuous extraction.
Example: Proxy Rotation Logic
from scrapingbypass import Proxy
if __name__ == '__main__':
proxy_manager = Proxy("username-res:password")
# 1. Extract dynamic US proxy
dynamic_us = proxy_manager.set_dynamic().set_region('US')
print(f"Dynamic: {dynamic_us}")
# 2. Extract sticky session (30-minute expiration)
sticky_session = proxy_manager.copy().set_expire(1800).set_region('US')
print(f"Sticky: {sticky_session}")
# 3. Batch extraction
pool = proxy_manager.copy().set_expire(600).limit(5)
for proxy_str in pool:
print(f"Pool Member: {proxy_str}")
Technical Notes
- Auto-Redirection: The SDK handles HTTP redirects (301/302) automatically. Note that each redirected hop that reaches a target site consumes credits according to the API version used.
- Credentials: Retrieve your
APIKEYfrom the Scrapingbypass Dashboard.