Metadata-Version: 2.4
Name: fethr
Version: 1.4.2
Summary: Fethr API client (every engine operation, API-key auth) and the helpers Python script steps use for outputs, metrics and logs.
Author: Fethr Health
License: Apache-2.0
Project-URL: Homepage, https://fethrhealth.com
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: amazon.ion
Requires-Dist: python-dateutil

# fethr

The Python package for [Fethr](https://fethrhealth.com): a client for the whole Fethr API, and the helpers
Python script steps use to send outputs, metrics and logs back to their run.

```
pip install fethr
```

## Calling the Fethr API

Create an API key in Fethr under **Settings › Developer**. Scripts always use an API key (or a service
account's key); a username and password does not work against Fethr.

```python
from fethr import FethrClient

fethr = FethrClient("https://fethr.example.org", token="fethr_usr_...")
# or set FETHR_URL and FETHR_API_TOKEN and call FethrClient()

fethr.me()                                            # who the key belongs to

run = fethr.run_flow("avmc", "adt_to_ehr", {"mrn": "12345"})   # start a flow and wait
print(run["state"]["current"])
print(fethr.run_logs(run["id"]))

fethr.connectors.list_connectors()
fethr.connectors.start_connector(id="...")
fethr.tables.list_table_rows(namespace="avmc", name="locations", size=100)
fethr.staging.publish_staged_changes(body={"items": [{"kind": "FLOW", "key": "avmc/adt_to_ehr"}]})
```

Every operation in the engine's API is there, grouped by area (`fethr.groups()` lists them,
`dir(fethr.tables)` lists one group's operations, and `help(fethr.tables.create_table)` shows its path and
parameters). Any operation can also be called by its id:

```python
fethr.call("getExecution", execution_id="7Yf3...")
fethr.describe("createTable")
```

- Keyword arguments are the operation's path, query and header parameters; `execution_id` works for
  `executionId`, `from_` for `from`.
- `body=` takes a dict or list (sent as JSON), a string (sent as YAML for flows, text otherwise) or bytes.
  `files=` / `data=` send multipart forms.
- Errors raise `FethrApiError` with `.status` and `.body`. GET requests retry on 429/502/503/504.
- `verify=False` or `verify="ca.pem"` for servers with a private certificate.

The full list of operations with their parameters is the engine's OpenAPI spec at `/swagger/fethr.yml`.

## Inside a Python script step

```python
from fethr import Fethr

Fethr.outputs({"patients": 12})
Fethr.counter("rows", 120, {"table": "adt"})
Fethr.logger().info("done")
```

The Fethr engine image ships this package, so script steps import it without installing anything.

To start another flow from a script and wait for it:

```python
from fethr import Flow

Flow().execute("avmc", "nightly_export", {"date": "2026-11-20"})
```

`Flow` reads `FETHR_URL` and `FETHR_API_TOKEN` (store the key as a Fethr secret and pass it in the step's `env`).
