Metadata-Version: 2.4
Name: browserflare
Version: 0.1.0
Summary: Python library for Cloudflare Browser Rendering APIs
Author-email: Harish Garg <harish.garg@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/harish-garg/browserflare
Project-URL: Repository, https://github.com/harish-garg/browserflare
Project-URL: Issues, https://github.com/harish-garg/browserflare/issues
Keywords: cloudflare,browser-rendering,web-scraping,screenshot,pdf,crawl
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
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
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Dynamic: license-file

# browserflare

Python library for the [Cloudflare Browser Rendering APIs](https://developers.cloudflare.com/browser-rendering/).

## Install

```bash
pip install browserflare
```

## Setup

Add your Cloudflare credentials to `.env`:

```
CF_ACCOUNT_ID=your_account_id
CF_API_TOKEN=your_api_token
```

## Usage

```python
from browserflare import start_crawl, build_crawl_payload, poll_until_complete, save_results

# Build a crawl payload
payload = build_crawl_payload(
    url="https://harishgarg.com",
    limit=10,
    formats=["markdown"],
)

# Start the crawl
job_id, err = start_crawl(payload)

# Wait for completion
result, err = poll_until_complete(job_id)

# Save results
save_results(job_id, result, formats=["markdown"])
```

### Screenshots

```python
from browserflare import take_screenshot, build_screenshot_payload, save_screenshot

payload = build_screenshot_payload(url="https://harishgarg.com", full_page=True)
image_bytes, content_type, err = take_screenshot(payload)
filepath = save_screenshot("https://harishgarg.com", image_bytes, content_type)
```

### PDFs

```python
from browserflare import generate_pdf, build_pdf_payload, save_pdf

payload = build_pdf_payload(url="https://harishgarg.com", format="a4")
pdf_bytes, content_type, err = generate_pdf(payload)
filepath = save_pdf("https://harishgarg.com", pdf_bytes)
```

## Project Structure

```
src/browserflare/
  __init__.py              # Public re-exports
  exceptions.py            # MissingCredentialsError, etc.
  config.py                # .env loading, API config, constants
  api.py                   # HTTP: start, poll, paginate, cancel crawls
  jobs.py                  # crawl_jobs.json management
  output.py                # Save crawl results, search, stats, diff
  batch.py                 # Batch crawling from URL list
  payloads.py              # Payload builders for crawl, screenshot, PDF
  screenshot_api.py        # POST to /screenshot endpoint
  screenshot_output.py     # Save screenshots + JSON log
  pdf_api.py               # POST to /pdf endpoint
  pdf_output.py            # Save PDFs + JSON log
```
