Metadata-Version: 2.4
Name: sela-browse-sdk
Version: 1.0.1
Classifier: Development Status :: 3 - Alpha
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 :: Rust
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Summary: Sela Network Python SDK - P2P client for browser automation agents
Keywords: sela,p2p,libp2p,browser-automation,web-scraping,semantic
Author-email: Sela Network <dev@sela.network>
License: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: documentation, https://github.com/sela-network/sela-node-v2/tree/main/client-sdk
Project-URL: homepage, https://github.com/sela-network/sela-node-v2
Project-URL: repository, https://github.com/sela-network/sela-node-v2

# Sela Browse SDK

Python SDK for browsing the web through the Sela P2P network.

## Installation

```bash
pip install sela-browse-sdk
```

## Quick Start

```python
import asyncio
from sela_browse_sdk import SelaClient

async def main():
    client = await SelaClient.with_api_key("sk_live_xxx")

    try:
        await client.start()
        response = await client.browse("https://example.com", None)
        print(f"Title: {response.page.metadata.title}")
    finally:
        await client.stop()

asyncio.run(main())
```

## Getting an API Key

Contact the Sela team to get your API key (`sk_live_xxx`).

## API Reference

### SelaClient

```python
client = await SelaClient.with_api_key("sk_live_xxx")
await client.start()
response = await client.browse(url, options)
await client.stop()
```

### BrowseOptions

```python
from sela_browse_sdk import BrowseOptions

options = BrowseOptions(
    timeout_ms=180000,                      # Request timeout in ms
    count=100,                              # Number of items to fetch
    filters={"sort": "newest"},             # Platform-specific filters
)

response = await client.browse(url, options)
```

### Response Structure

```python
response.page.metadata.title       # Page title
response.page.page_type            # "search", "profile", "feed", etc.
response.page.content              # List of extracted items
```

Each item in `response.page.content`:

```python
import json

for item in response.page.content:
    fields = json.loads(item.fields_json)
    print(fields)  # {"title": "...", "author": "...", "likes": 123}
```

### Error Handling

```python
from sela_browse_sdk import SelaError

try:
    response = await client.browse(url, None)
except SelaError.TimeoutError:
    print("Request timed out")
except SelaError.BrowseError as e:
    print(f"Browse failed: {e}")
```

## Example

```python
import asyncio
import json
from sela_browse_sdk import SelaClient, BrowseOptions

async def main():
    client = await SelaClient.with_api_key("sk_live_xxx")

    try:
        await client.start()

        options = BrowseOptions(
            timeout_ms=180000,
            count=100,
            filters={"sort": "newest", "type": "video"}
        )
        response = await client.browse(
            "https://www.xiaohongshu.com/search_result?keyword=kpop",
            options
        )

        print(f"Title: {response.page.metadata.title}")
        print(f"Found: {len(response.page.content)} items")

        for item in response.page.content[:5]:
            fields = json.loads(item.fields_json)
            print(f"- {fields}")

    finally:
        await client.stop()

asyncio.run(main())
```

## License

MIT License

