Metadata-Version: 2.5
Name: anaella
Version: 0.1.1
Summary: Python client for Anaella, one API for agents: find, explain and run tools, connect accounts, publish posts.
Project-URL: Homepage, https://anaella.com
Project-URL: Documentation, https://anaella.com/for-agents
License-Expression: MIT
License-File: LICENSE
Keywords: agents,anaella,api,automation,mcp,social media
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.25
Requires-Dist: typing-extensions>=4.6
Description-Content-Type: text/markdown

# anaella

A small Python client for the [Anaella](https://anaella.com) `/v1` API, one API for agents: typed
tools (web research, SEO, images and video, documents, phone, meetings) plus the accounts you
connect (mail, calendars, Drive, Slack, ads, payments, social, WordPress and Ghost sites, any MCP
server). It mirrors [`@anaella/client`](https://www.npmjs.com/package/@anaella/client): same
calls, same response shapes.

```sh
pip install anaella
```

One runtime dependency (`httpx`), Python 3.9+.

```python
from anaella import AnaellaClient

anaella = AnaellaClient()  # reads ANAELLA_API_KEY (create one under Settings → API keys)

tools = anaella.find("unread emails")                      # capabilities for a task
spec = anaella.explain("email.messages.list")              # its input schema and price
job = anaella.do("email.messages.list", {"query": "is:unread"})
done = anaella.wait_for_job(job["id"])                     # async tools return a queued job
```

Async code uses `AsyncAnaellaClient`, which has the same methods, awaited:

```python
from anaella import AsyncAnaellaClient

async with AsyncAnaellaClient() as anaella:
    job = await anaella.do("web.search", {"query": "anaella"})
```

## What it covers

- **Tools:** `find(q)`, `explain(id)`, `do(id, input)`, `job(id)`, `wait_for_job(id)`, `balance()`.
- **Accounts:** `list_channels()`, `create_connect_session()`, `connect_with_credentials()`,
  `import_connection()`, `delete_channel(id)`, `request()` for raw calls to a connected account's API.
- **Social posts:** `create_post`, `update_post`, `list_posts`, `get_post`, `delete_post`,
  `get_analytics`, `get_post_analytics`, plus `upload_urls` / `upload_files` for media.
- **Webhooks:** `create_webhook`, `list_webhooks`, `delete_webhook`, `get_webhook_deliveries`,
  and `verify_webhook_signature` for the requests Anaella sends you.

Responses are plain dicts with the API's own keys (`job["costUsd"]`), typed with `TypedDict`s in
`anaella.types` for editors and type checkers. Request bodies are plain dicts too, so a new API
field works before the client knows about it.

## Using it from an agent

If your agent can speak MCP, use the [MCP server](https://anaella.com/for-agents): the tools and
workflow skills arrive with no code. If you are writing the agent loop yourself, give the model
three function tools and keep the whole catalog behind them:

```python
from anaella import AnaellaApiError, AnaellaClient

anaella = AnaellaClient()

def anaella_find(query: str):            # "unread emails" -> ids, prices, input schemas
    return anaella.find(query, limit=8)

def anaella_do(id: str, input: dict, approved: bool = False):
    if not anaella.explain(id)["readOnly"] and not approved:
        return {"error": "not_approved"}  # sending, posting, editing: ask the user first
    try:
        job = anaella.do(id, input)
        return anaella.wait_for_job(job["id"])["output"]
    except AnaellaApiError as e:
        # `next` is a connect or reconnect link; `schema` is what the tool wanted
        return {"error": e.code, "message": e.message, "next": e.next, "schema": e.schema}
```

Returning API errors as data, not exceptions, lets the model fix its input or send the user a
connect link. The sdist ships complete versions in `examples/`: `agent_tools.py` (the three tools
as JSON Schema, for OpenAI-style or Anthropic-style function calling, with an approval hook),
`langchain_tools.py`, and `webhook_fastapi.py` (a signature-checked webhook receiver).

## Building for your own users

If your app lets *its* users connect their accounts, pass `external_user_id` on every call made
for one of them. Anaella then refuses a channel that isn't theirs (403 `end_user_mismatch`):

```python
link = anaella.create_connect_session(
    {"platform": "gmail", "externalUserId": "user_42", "returnUrl": "https://app.example.com/done"}
)
anaella.do("email.messages.list", {}, external_user_id="user_42")
anaella.list_channels(external_user_id="user_42")
```

## Errors

Any non-2xx response, and any network failure, raises `AnaellaApiError` with `status`, `code`,
`message`, and when present `details`, `next` (a connect or reconnect link) and `schema` (the JSON
Schema an `invalid_input` input should have matched):

```python
from anaella import AnaellaApiError

try:
    anaella.do("gsc.queries.list", {})
except AnaellaApiError as e:
    if e.code == "channel_required":
        print("Connect Search Console:", e.next)
    elif e.code == "reconnect_required":
        print("Reconnect:", e.next)
    else:
        raise
```

Reads retry a gateway error (502, 503, 504) on their own. A write is sent once, since it may
have run.

## Webhooks

```python
from anaella import verify_webhook_signature

# raw_body: the request body exactly as received, before JSON parsing
if not verify_webhook_signature(raw_body, request.headers["X-Anaella-Signature"], secret):
    return Response(status_code=401)
```

## Configuration

`AnaellaClient(api_key=None, *, base_url=None, timeout=60.0, http_client=None)`. The key falls
back to `ANAELLA_API_KEY` and the address to `ANAELLA_API_URL` (default
`https://api.anaella.com`). Pass your own `httpx.Client` / `httpx.AsyncClient` for proxies,
retries at the transport level, or tests. Use the client as a context manager (or call `close()`)
to release its connections.

## License

MIT
