Metadata-Version: 2.4
Name: lvi-api-client
Version: 0.5.0
Summary: LogicVein API Client Library
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Dynamic: license-file

# LogicVein API Client

A Python client for interacting with the LogicVein API.

## Installation

From PyPI:

```bash
pip install lvi-api-client
```

From TestPyPI (pre-release / testing):

```bash
pip install \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  lvi-api-client
```

See [PUBLISHING.md](PUBLISHING.md) for instructions on publishing new releases.

## Usage

```python
from logicvein import LogicVeinAPIClient

client = LogicVeinAPIClient(host="your-lvi-server", api_token="your-token")
devices = client.search_devices_in_network()
```

Settings not passed as arguments are read from `LVI_HOST`, `LVI_API_TOKEN` (or `LVI_USERNAME`
and `LVI_PASSWORD`), `LVI_VERIFY_SSL` and `LVI_TIMEOUT`; `ignore_env_vars=True` reads none of
them.

### Logging in

With an API token there is no login: the token goes in a header of every call. With a username
and password and no token, the client logs in as it is created, and `authenticate()` logs in
again. A login that does not work raises:

- `LogicVeinAuthenticationError`: the server rejected the username or password (HTTP 401). It
  has `host` and `username`.
- `LogicVeinConnectionError`: the server could not be reached or did not answer as it should:
  connection refused, host name not found, TLS failure, timeout, too many redirects, any
  other HTTP error status, or a CA bundle path that does not exist. It has `host`, `reason`
  and, if the server answered, `status_code`.

```python
from logicvein import LogicVeinAPIClient, LogicVeinAuthenticationError, LogicVeinConnectionError

try:
    client = LogicVeinAPIClient(host="your-lvi-server", username="your-user", password="your-password")
except LogicVeinAuthenticationError as error:
    print(f"Wrong username or password: {error}")
except LogicVeinConnectionError as error:
    print(f"Server problem: {error}")
```

Neither error holds the password or the request URL, so both are safe to print and log.

The password login is a GET with the username and password in the URL's query string. They
are encrypted in transit like the rest of the request, but a URL is what servers and proxies
commonly write to their access logs, and the response `authenticate()` returns holds it in
`url`. Prefer an API token where you can.

### TLS verification

The client verifies the server's TLS certificate by default. For a server whose certificate
comes from a private CA, keep verification on and point `REQUESTS_CA_BUNDLE` at the CA's
certificate. `verify=False`, or `LVI_VERIFY_SSL=false`, turns verification off, and the API
token or password is then sent to whichever server answers. `LVI_VERIFY_SSL` accepts
true/false, 1/0, yes/no and on/off in any case; unset or empty means verify, and anything else
is an error.
