Visitar URL original
Python SDK - Introduction
Skip to main content
View the Python SDK GitHub repository for the latest installation instructions, examples, and source code.
Build typed scraping workflows for search engines, eCommerce platforms, social media, AI tools, and more with the official Decodo Python SDK.
  • Fully typed targets and parameters with IDE autocomplete
  • Sync, async, and batch scraping methods
  • Web search, site mapping, and crawling through the Web Data API
  • Built on httpx; requires Python 3.12 or later
  • Typed error hierarchy for safer integrations

What is the Decodo Python SDK?

The Decodo Python SDK provides a typed interface for interacting with Decodo targets like Google, Amazon, TikTok, YouTube, ChatGPT, Perplexity, and more. Instead of manually constructing HTTP requests and validating payloads, you work with fully typed methods and target-specific parameter classes directly in your editor.

Why use the SDK?

  • Typing and autocomplete – target parameters are fully typed for better editor support and fewer mistakes.
  • Unified scraping interface – work with search engines, eCommerce platforms, social media, and AI tools through one SDK.
  • Async and batch workflows – create scraping tasks, poll task status, and process batches at scale.
  • Typed errors – handle authentication, validation, timeout, and rate-limit failures safely.
  • Minimal setup – single dependency on httpx, no additional HTTP client required.

Requirements

  • Python 3.12+

Installation

Quick start

Create a new project:
Copy your Web Data API key from your Web Data API subscription on the Decodo dashboard. Keep it out of your source by storing it in an environment variable:
Older plans only have a basic authentication token. Pass it as token instead of api_key – see Configuration.
Every target has a corresponding parameter class. Import the one you need, fill in its fields, and pass it to scrape():
Run the script:
Parameter classes are bundled with the package, so no extra step is needed after pip install decodo-sdk. Each class pins its own target and accepts only the fields that target supports - your IDE flags misspelled or unsupported fields, and runtime validation catches them before the request is sent.

Alternative: dictionary payloads

Scraping methods also accept a plain Python dictionary, validated against the bundled schema before the request is sent. Nothing is checked while you write the code, so typos surface only at runtime:
Use the Target enum instead of a raw string to avoid mistyping the target name. Typed parameter classes are recommended for anything beyond a quick experiment.

Updating types to a newer schema

The types bundled in the package reflect the schema at release time. To update them without waiting for a new release, run the type generator:
Then import from that directory instead:
The directory name passed to --out-dir becomes the import namespace, so ./decodo_generated gives you from decodo_generated.targets import .... Any name works, but keep it consistent across your project.

Configuration

Pass either api_key or token, never both:
Setting both raises ValueError: web_scraping_api accepts either token or api_key, not both. Provide only one. Setting neither raises ValueError: web_scraping_api requires api_key or token in DecodoConfig.Which credential you pass also decides which API the SDK calls. An api_key uses the Web Data API at data.decodo.com, which is the only way to reach search, map, and crawl. A token uses the older Web Scraping API at scraper-api.decodo.com, which supports scraping only.

Scraping

Access the API via client.web_scraping_api.

Sync scrape

Waits for the scraping result before returning:

Async scrape

Creates a scraping task and returns immediately. You then poll for its status and results:
get_status returns pending, done, or faulted.

Batch scrape

Send multiple inputs in a single request using the batch variant of a target’s parameter class. The primary input accepts a list:

Web Data API: search, map, and crawl

These methods are served by the Web Data API at data.decodo.com and require an api_key. Calling them on a client configured with a basic authentication token raises ValueError. They live on the same client.web_scraping_api namespace. Parameters are plain dictionaries. SearchRequest, MapRequest, and CrawlRequest are TypedDicts you can use for editor completion - they are always importable and need no code generation. Bodies are validated against the bundled schema before the request is sent, just like scrape. Runs a web search and returns the parsed result document:
A search that ran but could not be scraped still answers with HTTP 200 and status: "failed" plus a message. Check result["status"] before reading the other fields.

Map

Discovers the links on a site, from its pages and its sitemap:

Crawl

crawl() starts a crawl, waits for it to finish, and returns every page with its content:
A crawl that stops early because of max_duration or a vendor limit ends with status truncated, and crawl() returns the pages it did collect. Each page carries its own status (pending, done, or faulted) and, when the fetch failed, a content_error instead of content. The lower-level methods let you drive a crawl yourself - for example, start it in one process and collect it in another:
get_crawl_status returns pending, done, faulted, cancelled, or truncated, with a reason when the crawl stopped early.

Targets and parameter classes

Every target in the Target enum has a matching parameter class. The enum member name is followed by Params – for example, Target.GoogleSearch → GoogleSearchParams and Target.Chatgpt → ChatgptParams. For batch calls, insert Batch before Params, as in GoogleSearchBatchParams. You don’t need to pass a target explicitly because each parameter class already pins its own target. For example, GoogleSearchParams(query="coffee shops") is sufficient on its own. The Target enum remains useful for dictionary payloads and for reading the target field from a response.
One target breaks the naming rule: Target.Target maps to TargetStoreParams (not TargetParams), to avoid a name clash. Every other target follows the pattern.
Each target accepts one primary input parameter (url, query, product_id, or prompt) together with optional configuration.

Search engines

eCommerce

Social media

AI tools

Other

Universal scraping

For the full target list and parameter details, see Target list and Parameters.

Error handling

The SDK raises typed errors that map to API error codes:
TimeoutError sits outside the DecodoError hierarchy, so except DecodoError won’t catch it. Handle it separately. Importing it from decodo also shadows the built-in TimeoutError in that module.Typed parameters can also fail before a request is sent. An unknown field or incorrect type raises pydantic.ValidationError when the parameter object is created.

  • CLI – Run Decodo scraping workflows from the command line.
  • TypeScript SDK – Integrate the Decodo APIs into TypeScript and JavaScript projects.
  • Go SDK – Integrate the Decodo APIs into Go projects.
  • MCP Server – Connect AI agents and MCP-compatible tools to Decodo.
  • GitHub repository – View the Python SDK source code, examples, and latest releases.

Support

Need help or just want to say hello? Our support is available 24/7.
You can also reach us anytime via email at support@decodo.com.

Feedback

Can’t find what you’re looking for? Request an article!
Have feedback? Share your thoughts on how we can improve.