Metadata-Version: 2.4
Name: dataguru-sdk
Version: 0.1.0
Summary: Official Python client for the DataGuru API: Amazon, Walmart, Google, TikTok, 1688 and 100+ other sites as JSON APIs.
Project-URL: Homepage, https://dataguru.cc
Project-URL: Documentation, https://dataguru.cc/documentation/
Project-URL: API catalog, https://dataguru.cc/apis
Project-URL: Dashboard, https://dashboard.dataguru.cc
Author: Developers 360 LLC
License-Expression: MIT
License-File: LICENSE
Keywords: amazon api,dataguru,ecommerce data,json api,scraping api,web scraping
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.24
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: respx>=0.20; extra == 'dev'
Description-Content-Type: text/markdown

# DataGuru Python SDK

The official Python client for [DataGuru](https://dataguru.cc). DataGuru turns websites like Amazon, Walmart, Google, TikTok and 1688 into JSON APIs.

```bash
pip install dataguru-sdk
```

```python
from dataguru import DataGuru

dg = DataGuru(api_key="YOUR_API_KEY")  # or set DATAGURU_API_KEY

product = dg.call(
    "amazon-products-search",
    product_url="https://www.amazon.com/dp/B0CHWRXH8B",
)
print(product["title"], product["price"])
```

Get an API key from the [dashboard](https://dashboard.dataguru.cc). Each call is billed to your balance at the API's listed price. You can browse every API, with its parameters and price, at [dataguru.cc/apis](https://dataguru.cc/apis).

## Find an API

The catalog is public, so these calls don't need a key.

```python
for api in dg.apis.search("walmart"):
    print(api["slug"], api["pricing"]["customer_price"], [p["name"] for p in api["parameters"]])

details = dg.apis.get("amazon-products-search")   # parameters, pricing, limits, sample_response, docs_url
everything = dg.apis.list(category="E-Commerce")
```

`dg.call()` takes an API's slug (`amazon-products-search`) or its endpoint path (`amazon/products/search`). You can pass parameters as keyword arguments or as a dict. The client checks them against the API's declared parameters before it sends anything.

## Async jobs

Use a job when you don't want to hold a connection open for a slow scrape. Funds are held when you submit and charged only if the job succeeds.

```python
job = dg.jobs.submit("amazon-products-search", {"product_url": "https://www.amazon.com/dp/B0CHWRXH8B"})
data = dg.jobs.wait(job["job_id"])        # polls; raises JobFailedError if it fails

data = dg.jobs.run("amazon-products-search", product_url="...")   # submit + wait
```

## Batches

Upload a CSV with one request per row. Its columns are the API's parameter names.

```python
batch = dg.batches.create("amazon-products-search", "products.csv")
dg.batches.wait(batch["batch_id"])                      # or poll dg.batches.get(...)["progress"]

for row in dg.batches.iter_results(batch["batch_id"]):  # streams JSON Lines
    print(row["status"], row.get("data"))

dg.batches.download(batch["batch_id"], "results.csv")   # json, jsonl or csv summary
dg.batches.cancel(batch["batch_id"])                    # unstarted rows are refunded
```

## Errors

Every error inherits from `dataguru.DataGuruError`. HTTP errors are `APIError` subclasses with `status_code`, `code`, `message`, `details` and `request_id`:

| Exception | When |
|---|---|
| `ValidationError` | 400: a parameter is missing or invalid (see `.details`) |
| `AuthenticationError` | 401/403: the key is missing, invalid or revoked |
| `InsufficientBalanceError` | 402: your balance is too low, so [top up](https://dashboard.dataguru.cc) |
| `NotFoundError` | 404 |
| `RateLimitError` | 429: `.retry_after` gives the wait in seconds |
| `ServerError` | 5xx |
| `JobFailedError` | an async job failed (failed jobs are not billed) |

```python
from dataguru import DataGuru, InsufficientBalanceError, ValidationError

try:
    dg.call("amazon-products-search", product_url="not a url")
except ValidationError as e:
    print(e.details)
```

The client retries read requests (catalog lookups, job and batch status) on 429, 5xx and connection errors. Billed requests are retried only when the connection failed before the request was sent, so a retry never charges you twice.

## Configuration

```python
DataGuru(
    api_key=None,       # default: $DATAGURU_API_KEY
    base_url=None,      # default: $DATAGURU_BASE_URL or https://api.dataguru.cc
    timeout=120.0,      # seconds per HTTP response
    max_retries=2,
)
```

`DataGuru` can be used as a context manager (`with DataGuru() as dg: ...`) and closes its connection pool on exit.

Requires Python 3.9+. Released under the MIT license.
