Metadata-Version: 2.5
Name: heyarchie
Version: 2.1.0
Summary: Python SDK + CLI for Archie — accounting AI. `import heyarchie` for the SDK; `archie` for the CLI.
Project-URL: Homepage, https://heyarchie.com/developers
Project-URL: Documentation, https://heyarchie.com/developers
Project-URL: Source, https://github.com/heyarchie-ai/archie-platform-v2/tree/alpha/apps/sdk-python
Project-URL: Issues, https://github.com/heyarchie-ai/archie-platform-v2/issues
Author-email: Archie <hey@archie.ai>
License: MIT
Keywords: accounting,ai,api,archie,cli,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business :: Financial :: Accounting
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: click<9.0,>=8.1
Requires-Dist: httpx<1.0,>=0.28
Requires-Dist: pydantic<3.0,>=2.9
Requires-Dist: rich<15.0,>=13.7
Requires-Dist: tomli>=2.0; python_version < '3.11'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest-httpx>=0.30; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.22; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
Requires-Dist: langgraph>=0.2; extra == 'langchain'
Provides-Extra: openai-agents
Requires-Dist: openai-agents>=0.1; extra == 'openai-agents'
Description-Content-Type: text/markdown

# heyarchie

Python SDK **and** CLI for the [Archie Connect API](https://heyarchie.com/developers).
The package gives you `import heyarchie` (the SDK) and the `archie` command (the CLI).

## Install

**As a library** (`import heyarchie`) — in your project's virtualenv:

```bash
pip install heyarchie
```

**As a CLI** (the `archie` command) — installed isolated, on your PATH:

```bash
pipx install heyarchie     # brew install pipx first, if needed
# or, with uv:
uv tool install heyarchie
```

> On macOS a bare `pip install` may hit `externally-managed-environment` (PEP 668),
> because Homebrew guards the system Python. pipx and uv manage a virtualenv for you
> and sidestep it.

**Pre-release (built from `staging`, aimed at the staging API):**

```bash
pip install --pre heyarchie
```

`--pre` is required and is not a formality — the pre-release channel is
published as PEP 440 pre-release versions precisely so that a plain
`pip install heyarchie` can never pick one up by accident. Pin it if you want a
specific build: `pip install heyarchie==2.1.0`.

## Which host am I talking to?

There is no default. Archie is one hostname per region and per tier, so the SDK
and the CLI resolve a host and refuse if nobody named one — a baked-in default
is a wrong answer that nobody is asked to confirm, and your credential goes
with it.

Name it by URL, or by environment. The table has the four regions
(`uk`, `us`, `au`, `ca`, each `https://<name>.heyarchie.com`) and `staging`:

```bash
archie auth login --api-url https://<your-archie-host>
archie auth login --environment uk          # -> https://uk.heyarchie.com
archie auth login --environment staging     # -> https://gcp.staging.heyarchie.com

export ARCHIE_API_URL=https://<your-archie-host>
export ARCHIE_ENVIRONMENT=uk
```

`archie auth login` saves the resolved URL to `~/.archie/credentials.toml`, and
every later command reuses it. Order, highest first: `--api-url` →
`--environment` → `ARCHIE_API_URL` → `ARCHIE_ENVIRONMENT` → the saved profile.
Every one of those is something you typed; there is no step after them.

From Python:

```python
import heyarchie
from heyarchie.environments import api_url

archie = heyarchie.Archie(api_key="sk_...", base_url=api_url("uk"))
```

Names that we cannot currently stand behind are refused rather than dialled:
a name that is not in the table, or one marked anything but `live`, raises and
tells you what was measured and when. The table is
`heyarchie/environments.json`.

## Quick start

Archie serves **one hostname per region**, so the SDK has no default host —
you name the region you belong to, either as `base_url` or via the
`ARCHIE_API_URL` environment variable (the same one the `archie` CLI reads).
If neither is set, the client raises `ArchieConfigError` rather than guessing.

```python
import heyarchie

archie = heyarchie.Archie(
    api_key="sk_...",
    base_url="https://uk.heyarchie.com",   # or export ARCHIE_API_URL
    workspace_id="ws_...",                 # or export ARCHIE_WORKSPACE_ID
)
message = archie.messages.create(
    "Summarise the BAS for Q1 2026",
    client_id="client_test_growthwise",
)
print(message.content)
if message.citations:
    print(message.citations[0].standard)
```

A key that reaches several workspaces must name one, with `workspace_id` or
`ARCHIE_WORKSPACE_ID`.

## Async

```python
import asyncio
import heyarchie

async def main():
    async with heyarchie.AsyncArchie(
        api_key="sk_...",
        base_url="https://uk.heyarchie.com",
    ) as archie:
        message = await archie.messages.create("Summarise BAS Q1 2026")
        print(message.content)

asyncio.run(main())
```

## Documents, journal entries and reports

Each of these is a skill, so you call it as `archie.skills.<name>(...)`. The
call returns the server's reply as a dict, with the skill's result under
`output`.

To analyse a file, upload it first and pass the returned id (a `str` is a path;
`bytes` take `filename=` so Archie can tell the type):

```python
up = archie.files.upload("contract.pdf")
analysis = archie.skills.analyse_document(file_id=up.file_id, analysis_type="summarize")
pack = archie.skills.prepare_cfo_pack(client_id="<client id>", period="2026-06", output_format="pdf")
entry = archie.skills.record_journal_entry(
    client_id="<client id>",
    entries=[
        {"account_code": "1000", "debit": "100.00", "credit": "0"},
        {"account_code": "4000", "debit": "0", "credit": "100.00"},
    ],
    entry_date="2026-06-30",
)
print(analysis["output"], pack["output"], entry["output"])
```

With `AsyncArchie`, `await` the same methods, for example
`up = await archie.files.upload("contract.pdf")` then
`await archie.skills.analyse_document(file_id=up.file_id)`.

## Search, standards and drafts

These are skills too. Each call returns the skill's reply as a dict.

```python
found = archie.skills.search_knowledge(query="ASC 606 lease", sources=["standards"], jurisdiction="US")
research = archie.skills.research_standards(
    topic="revenue recognition",
    standard_references=["ASC 606"],
    jurisdiction="US",
    mode="research",
)
draft = archie.skills.prepare_communication(
    type="email",
    recipients=["alex@example.com"],
    subject="Q1 BAS",
    context="Remind about the BAS",
    tone="professional",
)
```

## Configuring the endpoint

Resolution order, highest first:

1. the `base_url=` argument
2. the `ARCHIE_API_URL` environment variable
3. nothing — `ArchieConfigError` is raised

```bash
export ARCHIE_API_URL=https://uk.heyarchie.com
```

```python
archie = heyarchie.Archie(api_key="sk_...")   # host comes from the env
```

Calls wait up to 920 seconds by default. Pass `timeout=` (seconds) to `Archie` or `AsyncArchie` to change it, and catch `ArchieTimeoutError`.

There is deliberately **no default host**. A default would mean that a
customer who upgrades the SDK without changing their code keeps talking to
whichever region the default names — a data-residency problem that surfaces no
error. Failing at construction makes that impossible.

## Workspace

The server refuses a signed-in request that does not name a workspace, so every call carries `X-Workspace-ID`:

```python
Archie(api_key=..., base_url=..., workspace_id="ws-1")   # or export ARCHIE_WORKSPACE_ID
```

With neither, the client lists your workspaces once and uses the only one. With several it raises `ArchieConfigError` naming them; it never guesses. The CLI does the same: `archie login --workspace ws-1` saves it with the sign-in (and a single workspace is saved for you), and `ARCHIE_WORKSPACE_ID` outranks the saved value.

## Agent-framework tools, and no streaming

`skills.as_langgraph_tools()`, `as_openai_tools()` (and `heyarchie.adapters.as_langchain_tools`) build tools that call `/api/v1/skills` with your key, name the workspace (`workspace_id=` or `ARCHIE_WORKSPACE_ID`, else your only one) and raise the typed `ArchieError` subclasses. Archie answers a skill or a message with one complete reply, so there is no streaming call: `skills.invoke_stream` is gone and `messages.create(..., stream=True)` raises `ValueError`. Workstream cycle events still stream through `workstreams.stream_cycle_events`.

## There is no sandbox

`sandbox=True` raises `ArchieConfigError`. The sandbox playground was removed
from the platform on 2026-05-06 and the concept dropped on 2026-06-03, but this
SDK went on advertising it — including a docstring saying a test key meant
sandbox and a live key meant live.

None of that was ever enforced. The API reads `X-Archie-Env` in exactly one
place, where it becomes a telemetry label, and reads the key prefix nowhere at
all; `GET /api/v1/topics` returns a byte-identical body with and without the
header. So `sandbox=True` wrote to live data. Failing at construction is the
only honest thing left to do with it.

Isolation in Archie is per **workspace**. Create a throwaway workspace, issue a
key scoped to it, and point the SDK at that key.
