Python SDK
The premip package wraps the API for wallet top-ups, orders, proxies, rotation, IP whitelist, IP checks, site checks and usage, and adds optional clients for the scraper and crawler you host yourself.
On this page
Install
pip install https://premip.com/downloads/premip-0.5.0-py3-none-any.whl
python -c "import premip; print(premip.__version__)"Python 3.10 or newer. The only dependency is httpx. The package is served from premip.com for now, so install it with the URL above. The version in the file name is the current release, 0.5.0. API reference
Quick start
from premip import PremipClient, ProxyEndpointClient
with PremipClient("premip_YOUR_KEY") as client:
print(client.proxies.verify()) # {"valid": True, "email": "..."}
proxy = client.proxies.list()[0]
# Send a request through your proxy with the dashboard credentials
with ProxyEndpointClient(proxy["username"], proxy["password"], proxy["host"], proxy["port"]) as p:
exit_ip = p.get("https://api.ipify.org").text
print(client.ip_checker.check(exit_ip)["score"])
client.proxies.rotate(proxy["id"])PremipClient
One client holds your key and exposes each API area as an attribute. Use it as a context manager so connections close cleanly.
| Argument | Purpose |
|---|---|
| api_key | Required. Must start with premip_. Create it in Dashboard → Settings → API keys. |
| base_url | Default https://api.premip.com. |
| scraper_url | Optional. Base URL of your Premip Scraper. Enables client.scraper. |
| crawler_url | Optional. Base URL of your Premip Crawler. Enables client.crawler. |
| service_token | Optional. Sent as X-Service-Token to the scraper and crawler for gated routes. |
| timeout | Seconds per request to the Premip API. Default 30. The scraper and crawler clients wait at least 60. |
client.wallet
Read the balance, top up with crypto and follow a payment until the network confirms it.
| Method | What it does |
|---|---|
| get() | Returns {"balance": 32.5, "currency": "USD"}. |
| top_up(amount_usd) | Creates a payment intent for 10 to 10000 USD. Open intent["checkoutUrl"] to pay. |
| wait_for_payment(intent_id, timeout=1800) | Polls until confirmed. Raises PremipApiError (PAYMENT_EXPIRED or PAYMENT_FAILED) or PremipTimeoutError. |
| payment_intent(id, sync=False) / payment_intents() | Read one payment or all of them. sync=True asks the provider first. |
| refresh_payment_intent(id) / payment_intent_events(id) | Refresh a stuck payment, read its confirmation timeline. |
| transactions() / transaction(id) | Deposits, purchases and refunds. |
client.catalog, client.orders and client.cart
Read products and locations, quote and place orders, and manage the cart. orders.create pays from the wallet when the balance covers the total, otherwise it returns a pending order with order["payment"].
| Method | What it does |
|---|---|
| catalog.products() / locations() | Packages, sizes and locations. Public routes. |
| catalog.quote(product_id, quantity, targeting=None) | Price one package size. |
| orders.quote(items, promo_code=None) | Price a list of items. Nothing is charged. |
| orders.create(items, promo_code=None) | Place the order. Items use the OrderItem type. |
| orders.list() / get(id) | Read orders and their payment. |
| orders.cancel(id) / refund(id) | Cancel a pending order. Refund your latest paid order within 14 days. |
| cart.list() / add_item(item) / update_item(id, **changes) / delete_item(id) / clear() | The dashboard cart. |
client.billing and client.usage
Plan quota, invoices and traffic analytics.
| Method | What it does |
|---|---|
| billing.plan() / cancel_plan() | Quota, traffic used and expiry. |
| billing.invoices() / invoice(id) | One invoice per order. |
| usage.analytics() | planUsedMB, planQuotaMB, proxyBreakdown and dailyUsage. |
client.proxies
List and configure proxies, rotate exit IPs, read rotating-plan data and browse the geo catalog.
| Method | What it does |
|---|---|
| verify() | Check the key. Returns {"valid": True, "email": ...}. |
| list() / get(id) | Proxy objects with credentials, current IP and settings. |
| set_active(id, active) | Enable or disable a proxy. |
| update_settings(id, ...) | sticky_ttl_sec, auto_rotate_enabled, auto_rotate_interval_min. |
| update_credentials(id, ...) | username and/or password. |
| rotate(id) | New exit IP. Raises PremipApiError with code PROXY_ROTATE_COOLDOWN during cooldown. |
| history(category) | Purchased pools by category. |
| rotating_credentials(payload) | Build rotating logins with geo and session type. |
| subscription() / session_options() / sub_users() | Rotating plan data. |
| geo_countries() / geo_regions() / geo_cities() / geo_zips() / geo_isps() | Location catalog. |
| readiness(id) / run_readiness(id) | Browser profile readiness. |
client.ip_whitelist
Manage which client IPs may authenticate to your proxies.
| Method | What it does |
|---|---|
| list() | All entries. |
| add(ip, label=None) | Whitelist an IP. |
| update(id, label) | Rename an entry. |
| remove(id) | Delete an entry. |
client.ip_checker and client.site_checks
Measure an exit IP and test target sites through a proxy. Both report results; neither changes how a site treats the proxy.
| Method | What it does |
|---|---|
| ip_checker.check(ip) | Fraud score, proxy and VPN flags, ISP, geo and reputation. |
| site_checks.catalog() | Site keys you can test. |
| site_checks.run(proxy_id, sites) | Up to 10 sites per run. |
| site_checks.stats(proxy_id=None, days=7) | Pass, CAPTCHA and block rates. days is 1, 7 or 30. |
| site_checks.runs(proxy_id=None, limit=10) | Recent runs. |
client.scraper
Talks to a Premip Scraper you host. Requires scraper_url. Job-based calls return a job id; scrape_page submits, waits and returns the first result.
| Method | What it does |
|---|---|
| scrape_page(payload) | Submit, wait, return one result. |
| submit_page / submit_pages | Return a job id for single or batch scrapes. |
| submit_preset_page / submit_preset_pages | Scrape with a named preset such as a search-results page. |
| job_status / job_results / wait_for_job / cancel_job | Job lifecycle. |
| search(payload) | Synchronous search-results fetch for google, bing or yandex. |
| list_presets() / get_preset(name) | Browse available presets. |
| create_session / list_sessions / login_session / … | Saved browser sessions for logged-in pages. Need service_token. |
client.crawler
Talks to a Premip Crawler you host. Requires crawler_url. A crawl walks a site from a seed URL; map lists URLs without visiting each page.
| Method | What it does |
|---|---|
| submit(payload) | Start a crawl. Returns a job id. |
| job(id) / results(id) | Status, stats and pages visited so far. |
| wait_for_job(id, timeout=300) | Poll until the crawl finishes. Raises PremipTimeoutError. |
| events(id, slim=False) | Iterate live events: stats, page, page_error, done, cancelled. |
| cancel(id, hard=False) | Stop scheduling new pages. hard=True aborts in-flight work. |
| map(payload) | Synchronous URL discovery from robots.txt, sitemaps and the seed page. |
Examples
from premip import PremipClient
with PremipClient("premip_YOUR_KEY") as client:
if client.wallet.get()["balance"] < 20:
intent = client.wallet.top_up(25)
print("Pay here:", intent["checkoutUrl"])
client.wallet.wait_for_payment(intent["id"])
order = client.orders.create([{
"productId": "mobile",
"location": "United States",
"countryCode": "US",
"trafficAmount": 5,
}])
print(order["orderNumber"], order["status"])
for proxy in client.proxies.list():
print(proxy["id"], proxy["location"], proxy["currentIp"])import time
from premip import PremipApiError, PremipClient
with PremipClient("premip_YOUR_KEY") as client:
try:
proxy = client.proxies.rotate("PROXY_ID")
except PremipApiError as err:
if err.code != "PROXY_ROTATE_COOLDOWN":
raise
time.sleep(err.retry_after_sec or 60)
proxy = client.proxies.rotate("PROXY_ID")
print(proxy["currentIp"])from premip import PremipClient
with PremipClient(
"premip_YOUR_KEY",
scraper_url="http://localhost:8100",
service_token="YOUR_SERVICE_TOKEN",
) as client:
page = client.scraper.scrape_page({
"url": "https://example.com",
"proxy_type": "prem_res_rotating",
"proxy_geo": {"country_code": "us"},
"formats": ["markdown"],
})
print(page["meta"]["status_code"], page["markdown"][:200])from premip import PremipClient
with PremipClient("premip_YOUR_KEY", crawler_url="http://localhost:8001") as client:
job_id = client.crawler.submit({
"seed_url": "https://example.com/docs",
"scope": {"mode": "same-domain", "max_depth": 2, "max_pages": 50, "per_domain_rps": 1.0},
"scrape_options": {"proxy_type": "none"},
"enable_scraping": True,
})
for event in client.crawler.events(job_id, slim=True):
if event["type"] == "page":
print(event["page"]["url"])
elif event["type"] == "done":
breakErrors
All SDK errors inherit from PremipError.
| Exception | Raised when |
|---|---|
| PremipAuthError | Missing or invalid key (HTTP 401), or a key that does not start with premip_. |
| PremipApiError | Any other error response. Has status_code, code and message, plus retry_after_sec for cooldowns. |
| PremipTimeoutError | A job wait ran past its timeout. |
Troubleshooting
| Symptom | Fix |
|---|---|
| 401 on every call | An expired key returns code API_KEY_EXPIRED. A revoked, unknown or malformed key returns UNAUTHORIZED. Create a new key. |
| Scraper unreachable on :8000 | The Premip backend also uses port 8000 on a shared host. Run the scraper on another port, for example PORT=8100, and set scraper_url to match. |
| 401 or 403 from scraper routes | The scraper has SERVICE_TOKEN set. Pass the same value as service_token. |
| PROXY_ROTATE_COOLDOWN | Wait for retry_after_sec and call rotate again. |