Metadata-Version: 2.1
Name: kweo
Version: 5.0.0
Summary: Drive your real, signed-in kweo browser and use your own AI from Python — pages, forms, agents, an OpenAI-compatible endpoint, LangChain tools.
Home-page: https://kweo.ai/developers
Author: kweo.ai
License: Apache-2.0
Requires-Python: >=3.9
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Software Development :: Libraries
Project-URL: Homepage, https://kweo.ai/developers
Project-URL: Documentation, https://kweo.ai/developers
Keywords: browser,automation,ai,agents,llm,langchain,scraping,kweo
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.2; extra == "langchain"
Requires-Dist: langchain-openai>=0.1; extra == "langchain"
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == "openai"
Description-Content-Type: text/markdown

# kweo for Python

Drive your **real, signed-in kweo browser** and use **your own AI** from Python.

```python
import kweo

k = kweo.connect()                              # finds kweo on this computer
tab = k.open("https://github.com/notifications")
print(tab.text())                               # the page, as you see it — you're signed in
print(tab.ask("Which of these need my review?")) # your AI, about this page
```

- **Your sessions, not a headless robot.** Scripts work in your kweo — Gmail, banking, LinkedIn, internal dashboards — already signed in, past bot walls, no cookies to export.
- **Your AI, without keys in code.** Claude (through Claude Code), your ChatGPT or Copilot plan, Gemini, API keys, OpenCode's free models, on-device models: whatever you connected in kweo. kweo speaks the OpenAI API, so LangChain, LlamaIndex, CrewAI and the OpenAI SDK work too.
- **kweo's agent as a function.** `k.agent.run("…")` hands a whole job to kweo's agent and returns its answer (or the JSON you asked for).
- **Safe by default.** Localhost only, a key per app, the same safety checks as kweo's agent (risky clicks follow your autonomy setting, blocked sites stay blocked), saved passwords are typed by kweo and never reach Python, and everything a script does is in kweo's activity log.

No dependencies — standard library only, Python 3.9+.

## Install

```bash
pip install https://kweo.ai/downloads/kweo-5.0.0-py3-none-any.whl
```

kweo 5.0 or later must be running. Its API is on by default (**Settings → Developers**). kweo writes its address and a key to `~/.kweo/api.json`, readable only by you, so `kweo.connect()` needs no arguments. To use another key, set `KWEO_API_KEY` (and `KWEO_URL`), or pass `kweo.connect(key=…)`.

## Pages

```python
tab = k.open("https://news.ycombinator.com")     # a new background tab
tab = k.active_tab()                              # …or the one you're looking at
for t in k.tabs(): print(t.id, t.title, t.url)

tab.goto("https://example.com")                   # waits for the page to settle
tab.text(find="price")                            # visible text (optionally just matching lines)
tab.elements(interactive=True)                    # [N] role "name" — buttons, links, fields
tab.links(match="*/item?id=*")                    # [{"text", "url"}]
tab.screenshot("page.png", full_page=True)
tab.pdf("page.pdf")
tab.evaluate("document.title")                    # JavaScript (needs the "script" permission)
```

### Acting

Name an element by its **visible text** (`"Sign in"`), its **[N] index** from `elements()`, or an `Element`. kweo prefers the control you mean: the text box over its label, the button over its caption. When two different controls really match, you get `KweoAmbiguous` listing them, and you add `role=` or `nth=`.

```python
tab.type("Search", "wireless earbuds", submit=True)
tab.click("Add to cart")
tab.fill({"Email": "ada@example.com", "Name": "Ada"}, submit="Continue")
tab.select("Country", "India")
tab.press("Escape")
tab.scroll("down")
tab.wait(text="Order placed", seconds=30)
tab.fill_password("Password", submit=True)        # your saved password — never seen by Python
tab.upload("Attach resume", "~/Documents/cv.pdf")
```

Every action goes through kweo's safety checks. A risky click (pay, delete, send) may ask you first, depending on **Settings → AI & models → Agent autonomy**. If you decline, Python gets `KweoPermissionError`.

## AI on a page

```python
tab.ask("What's the cheapest option and its delivery date?")

rows = tab.extract({"title": str, "points": int, "comments": int}, many=True)

from pydantic import BaseModel
class Order(BaseModel):
    number: str
    total: float
    status: str
orders = k.open("https://www.amazon.in/your-orders").extract(Order, many=True)   # list[Order]
```

`extract` accepts a dict of types, a Pydantic model, a dataclass, a TypedDict, or a JSON schema. `model=` picks the AI. Without it, kweo uses the one you chose in kweo.

## Your AI, from anywhere

```python
k.ai.chat("Write a haiku about browsers")                       # your default model
k.ai.chat("Plan my week", model="claude-code:opus")             # Claude Code, a chosen model
k.ai.chat("Classify: ...", json={"label": str, "score": float})  # parsed JSON
for piece in k.ai.chat("Tell me a story", stream=True): print(piece, end="")
k.ai.models()                                                   # what's connected
```

**OpenAI-compatible:** base URL `http://127.0.0.1:7333/v1`, any kweo key.

```python
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:7333/v1", api_key=k.key)   # or k.ai.openai()
client.chat.completions.create(model="default", messages=[{"role": "user", "content": "Hi"}])
```

Model names:
- `default`: your pick in kweo.
- `claude-code`, `claude-code:opus`, `:sonnet`, `:haiku`.
- `opencode` and `opencode:<provider/model>`.
- kweo's own ids for everything else: `chatgpt:…`, `copilot:…`, `openai:gpt-4o`, `google:…`, `local:…`.

Tool calling works with every model. Claude Code and OpenCode get it through kweo's emulation, enforced with a JSON schema on Claude Code. `response_format` (JSON mode / JSON schema) works too.

## Agents

```python
run = k.agent.run("Find my last 3 Amazon orders and their totals",
                  url="https://www.amazon.in/your-orders",
                  output={"orders": [{"date": str, "total": float}]})
print(run.status, run.output)     # done {'orders': [...]}

run = k.agent.start("Compare prices for 'AirPods Pro' on three shops")   # don't wait
for event in run.events(): print(event)                                 # steps as they happen
run.stop()
```

The agent is kweo's own, running on Claude Code or OpenCode (`engine=`, `model=`). It works in a tab you can watch. If it needs you (a login, a CAPTCHA), it asks in kweo and the run waits (`status == "waiting"`).

## Workflows, routines, downloads, events

```python
k.workflows.list()
k.workflows.run("Weekly report", week="2026-W48")
k.routines.run("Morning inbox")
k.downloads()
k.wait_for_download(timeout=120)
for ev in k.events(): print(ev["type"], ev.get("tab"))   # tab.opened / navigated / loaded / closed, download.*
```

## LangChain / LangGraph

```bash
pip install langchain-openai langgraph
```

```python
from kweo.langchain import chat_model, kweo_tools
from langgraph.prebuilt import create_react_agent

agent = create_react_agent(chat_model("claude-code"), kweo_tools())
agent.invoke({"messages": [("user", "What's in my GitHub notifications?")]})
```

`kweo_tools()` gives the agent one tab of its own: `open_page`, `read_page`, `list_elements`, `click`, `type_text`, `page_links`, `extract_from_page`, `ask_about_page`, `run_browser_agent`. Any MCP-capable framework can also connect to kweo's MCP server at `http://127.0.0.1:7333/mcp`.

## Async

```python
from kweo.aio import connect
k = await connect()
tab = await k.open("https://example.com")
print(await tab.text())
```

## The `kweo` command

```bash
kweo status
kweo tabs
kweo text https://example.com --find price
kweo ask "What is this page about?" --url https://example.com
kweo chat "Summarize this:" - < notes.txt
kweo extract https://news.ycombinator.com --shape '{"title":"str","points":"int"}' --many
kweo run "Find a 4-star hotel in Lisbon under €150 for next Friday" --url https://booking.com
kweo shot https://example.com -o page.png --full
kweo workflows ; kweo workflow "Weekly report" -p week=2026-W48
```

## Keys and permissions

The **This computer** key (in `~/.kweo/api.json`) can do everything, the same as you. For a tool you don't fully trust, make a key in **Settings → Developers → New key** with only what it needs:

| Permission | Allows |
|---|---|
| `browse` | List and open tabs, go to pages, read text, elements and links, screenshots, downloads |
| `act` | Click, type, fill, select, press keys, upload, close tabs |
| `script` | Run JavaScript in pages |
| `ai` | Models, chat completions, ask/extract on pages |
| `agent` | Run kweo's agent |
| `workflows` | Run workflows and routines |

Revoke a key at any time. Ghost (private) windows and kweo's own pages are never reachable from scripts.

## Errors

All errors are `kweo.KweoError`, with `.status`, `.code` and `.message`. The subclasses:
- `KweoNotRunning`: kweo isn't open, or its API is off.
- `KweoAuthError`: the key is missing or wrong.
- `KweoPermissionError`: the key lacks the permission, the site is blocked, or you declined the action.
- `KweoNotFound`: no such tab, element, model, run or workflow.
- `KweoAmbiguous`: several elements match. `.details["candidates"]` lists them.
- `KweoTimeout`: kweo didn't answer in time.

## HTTP API

Everything above is plain HTTP and JSON on `http://127.0.0.1:7333/v1` with `Authorization: Bearer <key>`, so any language works. See https://kweo.ai/developers for the full reference.

Apache-2.0 · https://kweo.ai/developers
