Metadata-Version: 2.5
Name: web-traffic-api
Version: 1.0.1
Summary: Top website / web traffic leaderboard via the Trends API live feeds. Competitive intel as JSON.
Project-URL: Homepage, https://trendsapi.ai
Project-URL: Documentation, https://trendsapi.ai/#quickstart
Project-URL: Repository, https://github.com/trendsapi-ai/web-traffic-api
Project-URL: Bug Tracker, https://github.com/trendsapi-ai/web-traffic-api/issues
Project-URL: Get API key, https://trendsapi.ai/#get-key
Author-email: Trends API <hello@trendsapi.ai>
License-Expression: MIT
License-File: LICENSE
Keywords: competitive-intelligence,trendsapi,web-traffic,website-rank
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: trendsapi>=1.0.0
Description-Content-Type: text/markdown

# Website traffic-rank API

Top website / web traffic leaderboard via the Trends API live feeds. Competitive intel as JSON.

[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![PyPI](https://img.shields.io/pypi/v/web-traffic-api.svg)](https://pypi.org/project/web-traffic-api/)
[![Python](https://img.shields.io/badge/python-3.9%2B-yellow.svg)](https://trendsapi.ai)

Key: [trendsapi.ai/#get-key](https://trendsapi.ai/#get-key). HTTP contract: [trendsapi-ai/trendsapi](https://github.com/trendsapi-ai/trendsapi).

JS: [`web-traffic-api`](https://www.npmjs.com/package/web-traffic-api).

## Authentication

```bash
pip install web-traffic-api
export TRENDSAPI_KEY=your_key
```

Python 3.9+. The wrapper re-exports `TrendsAPI`, `AsyncTrendsAPI`, and `TrendsAPIError` from the official client.

```python
from web_traffic_api import TrendsAPI

client = TrendsAPI()                    # TRENDSAPI_KEY
# client = TrendsAPI(api_key="YOUR_KEY")
```

`get_top_websites()` presets `type: "Top Websites"`. Official full client (every source, no preset): [`trendsapi`](https://pypi.org/project/trendsapi/).

## Methods

| Method | REST `mode` | Returns |
|---|---|---|
| `get_top_websites(limit=, offset=, category=)` | `get_top_trends` | `GetTopTrendsResponse` |
| `get_top_trends(type=, ...)` | `get_top_trends` | `GetTopTrendsResponse` |

`source` is lowercase (`google search`). `type` is exact (`Top Websites`). Mixing them is a 400.

```python
from web_traffic_api import TrendsAPI

client = TrendsAPI()                    # TRENDSAPI_KEY
# client = TrendsAPI(api_key="YOUR_KEY")

sites = client.get_top_websites(limit=25)
print(sites.data[0])                    # [1, "google.com"]
```

```python
sites = client.get_top_websites(limit=25)
```

| Field | Meaning |
|---|---|
| `as_of_ts` | Snapshot time |
| `type` | Feed name |
| `limit`, `offset`, `count` | Pagination |
| `data` | `[rank, label]` rows |

Python: `hot.data`. JS: `hot.data`. Optional `offset=` and `category=` (`Amazon Best Sellers by Category`, `Top Websites` only).


## Async

```python
import asyncio
from web_traffic_api import AsyncTrendsAPI

async def main():
    client = AsyncTrendsAPI()
    return await client.get_top_websites(limit=25)

asyncio.run(main())
```

Each 200 is one billed request.

## Call (curl)

| Field | Value |
|---|---|
| Endpoint | `POST https://api.trendsapi.ai/api` |
| Auth | `Authorization: Bearer $TRENDSAPI_KEY` |
| Mode | `get_top_trends` |
| `type` | `Top Websites` (exact capitalization) |
| Optional | `category`, `limit`, `offset` |

```bash
curl -sS -X POST https://api.trendsapi.ai/api \
  -H "Authorization: Bearer $TRENDSAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode":"get_top_trends","type":"Top Websites","limit":25}'
```

## Source notes

- There is no `source: web traffic` (that string is 400).
- Parsed `data` is `[rank, hostname]` pairs.
- This is third-party rank estimation, not Google Analytics.

## Errors

| HTTP | Client |
|---|---|
| 200 | Parsed payload. Python dataclasses / JS typed objects |
| 400 | Raises. Fix `source` or `type` spelling |
| 401 | Raises. Check `TRENDSAPI_KEY` |
| 404 | Raises. No series for that keyword. Do not retry |
| 429 | Raises. Quota |
| 5xx | Client retries, then raises |

The HTTP `body` field is a JSON string. SDKs decode it. Raw curl must parse `body` a second time.

Site: [https://trendsapi.ai/trends/web-traffic](https://trendsapi.ai/trends/web-traffic). GitHub: [trendsapi-ai/web-traffic-api](https://github.com/trendsapi-ai/web-traffic-api).

## License

MIT. See [LICENSE](LICENSE).
