Metadata-Version: 2.5
Name: api-everything
Version: 0.5.0
Summary: Serve a website's own internal JSON as an API by driving a real browser and reading the responses the page already receives.
Project-URL: Homepage, https://github.com/Abhinay-kal/Api-everything
Project-URL: Repository, https://github.com/Abhinay-kal/Api-everything
Project-URL: Issues, https://github.com/Abhinay-kal/Api-everything/issues
Author: Abhinay Kalkhanday
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: api,automation,browser,fastapi,json,mcp,playwright
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Requires-Dist: fastapi>=0.163.0
Requires-Dist: httpx>=0.28.1
Requires-Dist: jsonpath-ng>=1.16.0
Requires-Dist: mcp>=2.3.0
Requires-Dist: playwright>=1.65.2
Requires-Dist: psutil>=7.2.2
Requires-Dist: pydantic>=2.7
Requires-Dist: pyyaml>=6.0
Requires-Dist: uvicorn>=0.54.0
Description-Content-Type: text/markdown

# Api-everything

Serve a website's own internal JSON as an API. A warm pool of real Chrome browsers runs a
small YAML recipe (open this page, do these steps, capture the response that matches), and
the daemon returns the JSON the site's own page already received. It only reads
responses; it never forges or alters requests, so the browser itself produces any
tokens the site needs.

![Api-everything terminal demo](docs/demo.gif)

**Status: alpha.** The core works end to end (the daemon, warm browser pool with backpressure,
recipes, checks, logins, and the recipe-scaffolding pipeline), and **174 real-site recipes ship
`stable` out of the box** (starting with the 5 flagship reference recipes below, plus 169 more from
the [developer catalog](docs/CATALOG.md)), each verified with 5 consecutive passing live
checks. `reddit.search` and `quora.answers` remain `experimental` at the bottom of the recipe table
because those sites return HTTP 403 to automated Chrome. The mock-site latency targets have not
been validly measured on a quiet machine yet; see [bench/README.md](bench/README.md) for every
run, honestly reported.

- Design: [docs/PRD.md](docs/PRD.md)
- Writing recipes: [docs/RECIPES.md](docs/RECIPES.md)
- 100-site developer catalog: [docs/CATALOG.md](docs/CATALOG.md) ([catalog/sites.yaml](catalog/sites.yaml))
- Vocabulary: [GLOSSARY.md](GLOSSARY.md)
- What is planned and when: [ROADMAP.md](ROADMAP.md)

## Try it

Needs Python 3.11+, [uv](https://docs.astral.sh/uv/) and Google Chrome. No Chrome (a Linux
server, say)? Run `uvx --from api-everything playwright install --only-shell chromium` once and set
`browser: chromium` in your config; see [Choosing a browser](#choosing-a-browser).

```bash
uvx api-everything serve                      # the daemon on 127.0.0.1:8750 (no clone needed)
```

```bash
curl 'http://127.0.0.1:8750/v1/run/hackernews.search?q=playwright'
```

Or try the bundled token-gated local demo site (`127.0.0.1:8799`) from a local clone (`uv sync`):

```bash
uv run python -m api_everything.mock_site &   # a demo target on 127.0.0.1:8799
curl 'http://127.0.0.1:8750/v1/run/mock.items?q=Item%203'
```

```json
{"data":{"items":[{"id":3,"title":"Item 3"}]},"meta":{"recipe":"mock.items","status":200,"count":1}}
```

### Docker (Headless Chromium pre-installed)

Run the daemon with headless Chromium and all Linux dependencies encapsulated in a single container (an API token is required when binding `0.0.0.0`):

```bash
docker run --rm --init -p 8750:8750 \
  -e API_EVERYTHING_TOKEN=change-me \
  ghcr.io/abhinay-kal/api-everything
```

Or build locally and mount your own recipes:

```bash
docker build -t api-everything .
docker run --rm --init -p 8750:8750 \
  -e API_EVERYTHING_TOKEN=change-me \
  -v "$(pwd)/my-recipes:/recipes:ro" \
  -e API_EVERYTHING__RECIPES_DIR=/recipes \
  api-everything
```

The demo page mints a single-use token on every load, so replaying a captured request gets a
403 (the tests prove this). Loading the page in a real browser and reading its own response
works every time. Watch it happen with `uv run python bench/replay_demo.py`.

| Command | What it does |
|---|---|
| `api-everything serve` | Run the daemon: a warm pool of Chrome browsers serving `/v1` (pass `--docs` for interactive Swagger UI at `/docs`) |
| `api-everything validate` | Check every recipe without starting anything |
| `api-everything check NAME... \| --all` | Run recipes' live checks; goes through a running daemon |
| `api-everything login PROFILE` | Sign in by hand once for recipes that use a logged-in profile |
| `api-everything probe TARGET` | Inspect live XHR/fetch JSON calls from a URL or catalog site ID |
| `api-everything scaffold TARGET` | Generate a draft YAML recipe (with optional `--probe` auto-detection) |
| `api-everything promote NAME` | Run N consecutive live checks (default 5) and promote to `stable` |
| `api-everything chrome PROFILE` | Start the Chrome an *attached* profile connects to (see below) |
| `api-everything mcp` | Let an AI agent call your recipes as tools over MCP (see below) |
| `api-everything recipes pull\|diff\|apply\|remove` | Fetch shared recipes from git and apply the ones you approve |
| `api-everything repair NAME` | Draft a verified fix for a recipe whose check failed because the site changed |
| `api-everything record URL` | Browse a page once and generate a verified recipe for one of its JSON responses |

Endpoints: `GET|POST /v1/run/{recipe}`, `GET /v1/recipes`, `GET /v1/recipes/{name}`,
`GET /v1/stats` (token only), `GET /metrics` (Prometheus), and `GET /healthz`. Settings live in an optional
`api-everything.yaml` (see `api-everything.example.yaml`).

## Why Not X?

Modern web apps hydrate via internal JSON APIs, but traditional tools either parse fragile HTML, burn LLM tokens per page, or break when single-use anti-CSRF tokens cannot be replayed.

| Dimension | **Api-everything** | [Crawl4AI](https://github.com/unclecode/crawl4ai) / [ScrapeGraphAI](https://github.com/ScrapeGraphAI/Scrapegraph-ai) | [Browser-Use](https://github.com/browser-use/browser-use) | [Scrapy](https://github.com/scrapy/scrapy) / [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/) | Direct `curl` / `httpx` |
|---|---|---|---|---|---|
| **Output Type** | **Native wire JSON** (exact server schema) | LLM-parsed Markdown / extracted JSON | Agent text, actions, or screenshots | Scraped HTML / CSS-selected text | Raw HTTP response |
| **DOM Fragility** | **0%** (ignores HTML/CSS; breaks only on API schema drift) | **Medium** (depends on HTML-to-Markdown / DOM chunks) | **Medium–High** (relies on accessibility/DOM state) | **Very High** (breaks on any CSS class or layout change) | **0%** (no browser) |
| **LLM Cost / Run** | **$0** (0 runtime tokens; optional `repair` only on breakage) | **~$0.005–$0.02+ / page** (cloud LLM extraction; $0 with local Ollama) | **~$0.01–$0.05+ / task** (multi-step DOM/vision loops) | **$0** | **$0** |
| **Step Latency** | **Single browser lease** (warm pool, no LLM round-trips) | Browser render + LLM inference latency | **~3,000–8,000 ms / step** (LLM round-trip per action) | **< 100 ms** (HTTP only; fails on JS-rendered SPAs) | **< 50 ms** (fails on JS hydration) |
| **Request Forging** | **Never (100% passive)** — browser mints real tokens natively | N/A (renders page or replays) | Simulates user clicks via CDP | Manual header/cookie replay (403 on single-use tokens) | Manual replay (403 on single-use tokens) |
| **Determinism** | **100% deterministic** (same input -> same bytes; pinned by `check`) | Probabilistic when LLM extraction is used | Non-deterministic multi-step trajectories | Deterministic until HTML changes | Deterministic until tokens expire |
| **AI / MCP Tooling** | **Built-in stdio [MCP](https://modelcontextprotocol.io/) server** + `/v1` REST API | Python SDK + community MCP wrappers | Python agent framework | Custom Python pipelines | Custom scripts |

**When to choose what:**
- **Use Api-everything** when the target site already fetches clean JSON in the browser and you want a deterministic, zero-token REST API or [MCP](https://modelcontextprotocol.io/) tool.
- **Use [Crawl4AI](https://github.com/unclecode/crawl4ai) / [ScrapeGraphAI](https://github.com/ScrapeGraphAI/Scrapegraph-ai)** when data lives only in server-rendered HTML/articles and you want LLM-ready Markdown.
- **Use [Browser-Use](https://github.com/browser-use/browser-use)** for open-ended, multi-step tasks (filling out arbitrary forms or navigating unfamiliar sites).
- **Use [Scrapy](https://github.com/scrapy/scrapy)** for high-volume static HTML crawling where JS hydration and single-use request tokens are not required.

## Reference recipes and their status

| Recipe | Status | Last checked | Result |
|---|---|---|---|
| `hackernews.search` | stable | 2026-11-25 | Passes 5/5 live checks (captures `hn.algolia.com` Algolia XHR JSON) |
| `github.explore` | stable | 2026-11-25 | Passes 5/5 live checks (public `api.github.com/search/repositories` JSON) |
| `wikipedia.summary` | stable | 2026-11-25 | Passes 5/5 live checks (Wikimedia REST summary JSON) |
| `mastodon.explore` | stable | 2026-11-25 | Passes 5/5 live checks (captures `mastodon.social/explore` trends XHR JSON) |
| `substack.search` | stable | 2026-11-25 | Passes 5/5 live checks (captures `substack.com/search` fetch JSON) |
| `mock.items` | stable | 2026-11-15 | Passes (the local demo site) |
| `reddit.search` | experimental | 2026-11-16 | HTTP 403 block page for automated Chrome: headless, with a visible window, and through an attached Chrome (fresh profile) |
| `quora.answers` | experimental, unverified | 2026-11-15 | HTTP 403 with a Cloudflare "security verification" page; its matcher is a placeholder |

The agreed rule is: a reference recipe must pass its live check five times in a row, or ship
labelled experimental with its status written down. All five flagship recipes above (plus 169
more `stable` developer recipes in [docs/CATALOG.md](docs/CATALOG.md)) passed five consecutive
live checks; `reddit.search` and `quora.answers` did not pass and stay `experimental`. This project
deliberately does not solve CAPTCHAs or evade bot detection, so it does not try to get past those
blocks. `check --all` skips experimental recipes unless you pass `--include-experimental`. To write
a recipe that works, see [docs/RECIPES.md](docs/RECIPES.md), or use the
[100-site catalog](docs/CATALOG.md) with `probe`, `scaffold`, and `promote`.

## Scheduling live checks

`api-everything check --all` runs every stable recipe's live check and exits 1 if any fail, so a
scheduler can run it and a `notify_command` in your config can tell you. Run it on your own
machine, never from hosted CI: your home IP and your Chrome are what the sites accept. If a
daemon is running, the checks go through it.

With cron (every morning at 09:00; use the full path to `uvx` from `which uvx`):

```bash
0 9 * * * /opt/homebrew/bin/uvx api-everything check --all >> "$HOME/api-everything-checks.log" 2>&1
```

With launchd on macOS, save this as `~/Library/LaunchAgents/local.api-everything.check.plist`
and load it with `launchctl load`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
  <key>Label</key><string>local.api-everything.check</string>
  <key>ProgramArguments</key>
  <array><string>/opt/homebrew/bin/uvx</string><string>api-everything</string>
         <string>check</string><string>--all</string></array>
  <key>StartCalendarInterval</key><dict><key>Hour</key><integer>9</integer>
         <key>Minute</key><integer>0</integer></dict>
  <key>StandardOutPath</key><string>/tmp/api-everything-checks.log</string>
  <key>StandardErrorPath</key><string>/tmp/api-everything-checks.log</string>
</dict></plist>
```

Both examples follow the standard formats but have not been run under a real scheduler by the
author. A recipe that is blocked by its site (the experimental ones) is skipped unless you add
`--include-experimental`.

## Attaching to a Chrome you start

For a logged-in profile you can start the Chrome yourself and let the daemon attach to it,
instead of the daemon launching one:

```yaml
profiles:
  reddit:
    attach: http://127.0.0.1:9222   # this machine only; pick any free port
```

```bash
uv run api-everything chrome reddit   # a visible Chrome on its own folder; sign in by hand
uv run api-everything serve           # attaches to it; stopping the daemon leaves it open
```

Things to know. It is **not** your everyday Chrome: Chrome 136 and later ignores remote
debugging on the default profile, so this is a separate Chrome with its own folder. Anything on
this machine that can reach that port can control that Chrome, which is why only loopback
addresses are accepted. It is still an automated browser and does not hide that: sites that
block automation can block it too. If it is closed, runs answer `503 browser_unavailable` with
the command to start it again.

## Repair a recipe the site broke

```bash
uv run api-everything repair reddit.search     # drafts a fix; applies nothing
uv run api-everything repair apply reddit.search   # shows the diff, installs if you approve
```

It re-runs the recipe's check, loads the page again, and drafts a fix: the one response that still
satisfies the recipe's old assertions (**no AI**), or one Claude call that has **no tools** and sees
only structure (key names and types, never values). The draft is replayed live and saved only if it
works; it can change just the matcher and the assertions. It never tries to get around a site that
blocks you or an expired login. A recipe that reshapes its result (`extract`, `collect: all`) is refused. See [docs/RECIPES.md](docs/RECIPES.md#when-a-recipe-breaks-repair-it).

## Get shared recipes

```bash
uv run api-everything recipes pull     # fetch (changes nothing you use)
uv run api-everything recipes diff     # see exactly what would change
uv run api-everything recipes apply    # approve one recipe at a time
```

Recipes come from git repositories in `recipe_sources` (default: the community repo). They install
into a managed folder *below* your own recipes, which always win by name. Anything risky (a new
recipe, a new site, any change to a logged-in recipe, new actions) needs you to type the recipe's name; recipes
using `eval` are never applied. Nothing verifies who wrote a recipe, so read the diff. See
[docs/RECIPES.md](docs/RECIPES.md#getting-shared-recipes).

## Record a recipe instead of writing it

```bash
uv run api-everything record "https://shop.example.com/search?q=shoes" --param q
```

A visible browser opens; let the page load and press Enter. You pick which JSON response is the
data you want (the list shows key names and types, not values), and the recipe is replayed once
in a fresh browser before it is written and compared with what you picked, so a file on disk has either been verified or is marked
experimental. It captures network responses only, not your clicks or typing. See
[docs/RECIPES.md](docs/RECIPES.md#the-quick-way-record-it).

## Use it from an AI agent (MCP)

`api-everything mcp` is an [MCP](https://modelcontextprotocol.io) server on stdio. It is a thin
bridge to a **running daemon**: each recipe becomes one tool with typed parameters, and a call
goes to the daemon's `/v1` API, so the browsers, rate limits and token are shared. It never
starts a daemon or a browser.

```bash
uv run api-everything serve     # in one terminal, and leave it running
# Claude Code:
claude mcp add api-everything -- uv run --project /path/to/api-everything api-everything mcp
```

Claude Desktop (`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "api-everything": {
      "command": "uv",
      "args": ["run", "--project", "/path/to/api-everything", "api-everything", "mcp"]
    }
  }
}
```

By default an agent is offered only recipes that are `stable` and need no login. Add
`--include-experimental` for experimental ones and `--include-profiles` for logged-in recipes,
which run as your account, so turn that on only on purpose. If the daemon uses an API token, give
the bridge the same one with `API_EVERYTHING_TOKEN_FILE` (a path to a file holding it) rather than
pasting the token into an app's config. If the daemon is not running, the bridge still starts and
tells the agent to start it. The tool list comes from the daemon. If you start the daemon after the agent app, the agent may still show only the "not running" tool: the bridge announces the change to clients that listen for it, and otherwise refreshing the tools (or reconnecting the MCP server) picks the recipes up. GUI apps often lack your shell's `PATH`, so in Claude Desktop give `command` as the full path to `uv` (the Claude Desktop snippet above has not been tried in the app).

## Safe by default

- Listens on `127.0.0.1` only. Any other address needs an API token (`API_EVERYTHING_TOKEN`),
  and then every request must send `Authorization: Bearer <token>`.
- Without a token, requests addressed to any host name other than localhost are refused, so a
  web page cannot reach it through DNS rebinding. No CORS headers are ever sent.
- A recipe that uses a logged-in profile is refused unless a token is set, even on localhost.
- A busy daemon says so (HTTP 429 with `Retry-After`) instead of queueing without limit, and
  every run has one deadline covering the wait and the work.
- Logs hold metadata only: never response bodies, cookies, tokens or raw parameter values.

## Responsible use

This tool is for reading data from your own accounts and from public pages. You are
responsible for following each site's terms of service and robots.txt. Many sites forbid
automated access. Conservative defaults (per-domain rate limiting, no CAPTCHA solving,
no credential handling) ship on by default, and recipes must not change state on a site
(posting, deleting, submitting forms). Review any recipe before running it, especially
in a logged-in profile.

## Choosing a browser

Runs that need no login (`session: none`) use one shared browser. Which one is the operator's
choice, in the config file (or `API_EVERYTHING__BROWSER`), never in a recipe:

| `browser:` | What runs | Needs |
|---|---|---|
| `chrome` (default) | your installed Google Chrome, in Chrome's new headless mode | Google Chrome |
| `chromium` | Playwright's managed Chromium (the headless shell) | `uv run playwright install --only-shell chromium`, about 106 MB, once |

If the chosen browser is missing, `serve` exits with one line naming the fix (and a request
gets `503 browser_not_installed`) instead of retrying forever. Both options are plain
automated browsers: neither hides that it is one. Logged-in `profile:<name>` recipes always use
real Chrome, because Chrome and Chromium cannot share one profile's cookies. Speed is not a
reason to pick `chromium`: it has not been measured against Chrome on a quiet machine.

## Development

Working with an AI coding agent (Antigravity, Claude Code, ...)? Point it at [AGENTS.md](AGENTS.md)
first, and use `scripts/check` to verify a change (lint + fast tests in about 15 seconds;
`scripts/check full` for everything).


Requires Python 3.11+ and [uv](https://docs.astral.sh/uv/).

```bash
uv sync
uv run pytest
uv run ruff check
uv run api-everything validate   # load and check every recipe, then exit
```

The browser tests use your installed Google Chrome (or `uv run playwright install chrome`).
The tests of the `chromium` setting also need `uv run playwright install --only-shell chromium`;
locally they are skipped without it, in CI they fail.

If your project folder is synced by iCloud Drive (macOS "Desktop & Documents"), keep the
virtualenv outside it, for example `export UV_PROJECT_ENVIRONMENT=~/.venvs/api-everything`.
Synced files can be marked `hidden` (Python then silently skips the editable install) or
`dataless` (reading them blocks while macOS downloads them), which looks like missing
imports or tests that hang.

## License

Apache-2.0. See [LICENSE](LICENSE).
