Metadata-Version: 2.5
Name: langchain-brewpage
Version: 0.2.0
Summary: LangChain tools for BrewPage: publish HTML, Markdown, JSON, KV stores and files to brewpage.app and get a shareable URL.
Project-URL: Homepage, https://brewpage.app
Project-URL: Repository, https://github.com/kochetkov-ma/langchain-brewpage
Project-URL: Issues, https://github.com/kochetkov-ma/langchain-brewpage/issues
Project-URL: Documentation, https://github.com/kochetkov-ma/langchain-brewpage#readme
Author-email: Maksim Kochetkov <apmatypa88@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: agent,brewpage,hosting,langchain,publish,tools
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Requires-Python: <4.0,>=3.10
Requires-Dist: httpx==0.28.1
Requires-Dist: langchain-core==1.7.6
Description-Content-Type: text/markdown

# langchain-brewpage

LangChain tools that publish HTML, Markdown, JSON, key-value stores and files to [BrewPage](https://brewpage.app) and return a shareable URL. Free, no account, no API key.

<p>
<a href="https://pypi.org/project/langchain-brewpage/"><img height="18" alt="PyPI" src="https://img.shields.io/pypi/v/langchain-brewpage"></a>
<a href="https://github.com/kochetkov-ma/langchain-brewpage/blob/main/LICENSE"><img height="18" alt="License" src="https://img.shields.io/pypi/l/langchain-brewpage"></a>
<a href="https://github.com/kochetkov-ma/langchain-brewpage/actions/workflows/ci.yml"><img height="18" alt="CI" src="https://github.com/kochetkov-ma/langchain-brewpage/actions/workflows/ci.yml/badge.svg"></a>
</p>

## Install

```bash
pip install langchain-brewpage==0.2.0
```

## Usage

```python
from langchain_brewpage import BrewPageToolkit

tools = BrewPageToolkit().get_tools()
page = tools[0].invoke({"content": "# Weekly report\n\nAll green.", "format": "markdown"})
print(page["url"])              # page link, share it
print(page["management_link"])  # private: edits or deletes the page
```

With an agent (any tool-calling chat model):

```python
from langchain.agents import create_agent
from langchain_brewpage import BrewPageToolkit

agent = create_agent(model, tools=BrewPageToolkit().get_tools())
agent.invoke({"messages": [{"role": "user", "content": "Write a one-page HTML changelog and publish it."}]})
```

## Tools

| Tool | API | Result |
|---|---|---|
| `brewpage_publish_page` (`BrewPagePublishPageTool`) | `POST /api/html` | HTML or Markdown page URL |
| `brewpage_publish_json` (`BrewPagePublishJsonTool`) | `POST /api/json` | JSON document URL |
| `brewpage_create_kv_store` (`BrewPageCreateKvStoreTool`) | `POST /api/kv` | Key-value store URL, one initial key |
| `brewpage_upload_file` (`BrewPageUploadFileTool`) | `POST /api/files` | Download or page URL for a local file |

`BrewPageToolkit` returns all four with one shared client. Every tool also takes `ttl_days`, `password` and `namespace` and returns a dict with `url`, `id`, `namespace`, `owner_token`, `management_link`, `expires_at`. API errors (rate limits, refused content) reach the agent as tool messages, not exceptions.

`url` is the page link. `management_link` is the management link with its key (`https://brewpage.app/manage/...#k=...`): anyone who has it can edit or delete the publication. The tool descriptions tell the agent to give the user both, to keep `owner_token` for later updates and show it on request, and never to post the management link or the token publicly (public page, repo, shared channel). `management_link` is `None` when the API returned an existing publication without a new key.

The first call gets an owner token; the toolkit reuses it, so all publications share one owner. To keep it across runs, pass it in:

```python
from langchain_brewpage import BrewPageClient, BrewPageToolkit

toolkit = BrewPageToolkit(client=BrewPageClient(owner_token="..."))
```

Environment: `BREWPAGE_OWNER_TOKEN`, `BREWPAGE_NAMESPACE`, `BREWPAGE_BASE_URL` (default `https://brewpage.app`).

## Page data and your domain

The page tool and `BrewPageClient.publish_page` also accept `state` (a settings object; `{}` enables defaults) and `domain` (an owned hostname). These options apply to HTML pages. Omit `state` or pass `None` to leave Page data settings unchanged. The HTML uses the [visitor SDK](https://brewpage.app/llms-page-data.txt); the declaration stays in the publish request.

This example requests private visitor replies and a custom hostname in one publication. For the hostname, set `BREWPAGE_OWNER_TOKEN` to an owner token already linked to your BrewPage profile before creating the client. For Page data alone, omit `domain`; no account is needed.

```python
from langchain_brewpage import BrewPageClient, BrewPageToolkit

html = """<!doctype html><meta charset="utf-8"><title>Event replies</title>
<form><label>Your reply <textarea name="reply" required></textarea></label><button>Send</button></form>
<p>What you enter is saved on BrewPage and can be read by this page's author.</p><p role="status"></p>
<script src="https://brewpage.app/js/state.js"></script>
<script>
document.querySelector("form").addEventListener("submit", async function (event) {
  event.preventDefault();
  const note = document.querySelector('[role="status"]');
  const store = await bp.state();
  if (!store) { note.textContent = "Saving is not available right now."; return; }
  try {
    await store.col("answers").add({text: this.elements.reply.value});
    note.textContent = "Saved.";
  } catch (error) { note.textContent = error.message; }
});
</script>"""

tools = BrewPageToolkit(client=BrewPageClient()).get_tools()
page = tools[0].invoke({
    "content": html,
    "state": {"collections": {"answers": {}}},
    "domain": "www.example.com",
})
print(page["url"])
print(page.get("custom_domain", {}).get("nextStep", page.get("notices", [])))
```

When either option is supplied, the receipt includes the service's available `notices`, `custom_domain`, `delivery_mode`, `delivery_mode_reason` and `delivery_notice` fields. The returned `url` is the actual BrewPage address. A domain request can leave the publication live while returning a notice explaining why the hostname was not attached. For a pending domain, create the returned DNS records, follow `nextStep`, check once after the change, then read status until it is `active`. This adapter does not change DNS or poll automatically. Without either option, the existing six-field receipt is unchanged.

The private `management_link` opens the publication's Data tab for the author. Visitor entries stay attached to the publication; do not put an owner token or management link in the HTML. To reopen a publication in a new process, retain its private receipt and supply the same owner token to the new client.

## Limits

- Hosting is temporary: publications expire after 15 days by default, `ttl_days` 1-30.
- Without `namespace` a publication is private: unlisted and not indexed, but anyone with the link can open it. Add `password` to restrict reads.
- `namespace="public"` lists pages in the public gallery and search engines. Never put secrets or personal data there.
- Size caps: HTML 5 MB, JSON 1 MB, KV value 1 MB, file 5 MB (video 20 MB). Current values: [brewpage.app/api/limits](https://brewpage.app/api/limits).

## Related

- [BrewPage](https://brewpage.app) and its [API](https://brewpage.app/api)
- [API reference](https://kochetkov-ma.github.io/brewpage-openapi/)
- [llama-index-tools-brewpage](https://github.com/kochetkov-ma/llama-index-tools-brewpage): the same tools for LlamaIndex ([PyPI](https://pypi.org/project/llama-index-tools-brewpage/))
- [brewpage-publish-plugins](https://github.com/kochetkov-ma/brewpage-publish-plugins): other integrations
- [brewpage-mcp](https://www.npmjs.com/package/brewpage-mcp): MCP server on npm; source and OpenAPI contract in [brewpage-openapi](https://github.com/kochetkov-ma/brewpage-openapi)
- [brewpage-action](https://github.com/kochetkov-ma/brewpage-action): GitHub Action that publishes CI artifacts ([Marketplace](https://github.com/marketplace/actions/publish-to-brewpage))
- [brewpage-cookbook](https://github.com/kochetkov-ma/brewpage-cookbook): interactive recipes published on BrewPage
- [brewpage-obsidian](https://github.com/kochetkov-ma/brewpage-obsidian): Obsidian plugin that publishes notes ([Obsidian community](https://community.obsidian.md/plugins/brewpage-publisher))
- [brewpage-browser-extension](https://github.com/kochetkov-ma/brewpage-browser-extension): browser extension that publishes pages, selections and files
- [brewpage-codex-plugin](https://github.com/kochetkov-ma/brewpage-codex-plugin): Codex plugin with the publishing skill and remote MCP

## Development

```bash
uv sync --group test
uv run pytest
BREWPAGE_LIVE=1 uv run pytest -m live   # publishes one private page on production
```

## Support

info@brewpage.app or [GitHub issues](https://github.com/kochetkov-ma/langchain-brewpage/issues).

## License

[MIT](https://github.com/kochetkov-ma/langchain-brewpage/blob/main/LICENSE)
