Metadata-Version: 2.5
Name: vetvise-vms-client
Version: 0.1.3
Summary: Python client for the VetVise VMS REST API
Project-URL: Homepage, https://vetvise.com
Project-URL: API Documentation, https://external.dev.apidoc.vetvise.dev/
Project-URL: Wiki, https://vetvise.atlassian.net/wiki/spaces/VMSWiki/overview?homepageId=2060910681
Author: VetVise GmbH
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: api-client,camera,livestock,vetvise,vms
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.12
Requires-Dist: cryptography>=50.0.2
Requires-Dist: numpy>=2.5.5
Requires-Dist: opencv-python
Requires-Dist: pandas>=3.1.1
Requires-Dist: pillow
Requires-Dist: urllib3>=2.8.0
Description-Content-Type: text/markdown

# vetvise-vms-client

Python client for the REST API of the VetVise Management System (VMS).

It handles service account authentication and wraps the most common endpoints:
cameras, still frames, recordings, timeseries data, artifacts, incidents, pens,
regions, reports and data collection.

- Website: [vetvise.com](https://vetvise.com)
- REST API documentation: [external.dev.apidoc.vetvise.dev](https://external.dev.apidoc.vetvise.dev/)
- VMS Wiki: [VMSWiki](https://vetvise.atlassian.net/wiki/spaces/VMSWiki/overview?homepageId=2060910681)

## Installation

```bash
pip install vetvise-vms-client
```

Requires Python 3.12 or newer.

## Configuration

Servers are configured in a JSON file, keyed by an alias of your choice:

```json
{
  "my-barn": {
    "protocol": "https",
    "hostname": "vms.example.com",
    "port": 443,
    "service_account_name": "my-service-account",
    "fingerprint": "<public key fingerprint>",
    "private_key": "/path/to/private_key.pem"
  }
}
```

`private_key` is either a path to a PEM file or the PEM content itself.
Keep this file out of version control.

Each entry can also have an optional `"tags": ["production", "barn", "chickens"]`
list to group servers:

```python
vms.get_instances_by_tags("production", "chickens")  # {alias: Server} with all given tags
vms.get_all_tags()                                   # every tag in the config
server.get_tags()                                    # tags of one server
server.has_tags("barn")                              # True / False
```

## Usage

```python
import time

from vms import VMS

vms = VMS("servers.json")
server = vms.get_instance("my-barn")

# Basic info
server.api.base.is_online()
server.api.base.get_version()

# Cameras and frames
camera_ids = server.api.cameras.get_camera_ids()
jpeg = server.api.frames.get_current_thumbnail_frame(camera_ids[0])
frame = server.api.frames.get_frame(camera_ids[0], time.time() * 1000)

# Timeseries data
server.api.timeseries.get_measurements()
df = server.api.timeseries.get_simple_measurement(
    "activity", "activity",
    start=(time.time() - 6 * 3600) * 1000,
    response_type="dataframe",
)

# Document collections support query / query_one / get_specific
latest = server.api.recordings.query_one({"order": {"timestamp": "desc"}})
reports = server.api.reports.query({"limit": 10})

# Archived artifacts (on a commander instance): query and download
commander = vms.get_instance("Commander Rex")
archived = commander.api.archived_artifacts.get_for_instance("<barn globalUniqueIdentifier>")
commander.api.archived_artifacts.download(archived[0]["archivedArtifactId"], file_path="artifact.bin")

# Regions
mappings = server.api.regions.get_mappings_for_camera(camera_ids[0])

# Pen state: is the barn full or empty, and since how many days?
pen_state = server.helpers.pen_state.get_pen_state()   # None if no pen state exists
print(pen_state)                                       # e.g. "Full, Day 9"
pen_state.is_full, pen_state.is_empty, pen_state.day

# Day of epoch (the filling day is day 0; None while the barn is empty)
server.helpers.pen_state.get_day_of_epoch(timestamp_ms)
# All absolute timespans that fell on day of epoch 1 to 3, over all epochs
for span in server.helpers.pen_state.get_timespans_for_days_of_epoch(1, 3):
    print(span.start_datetime, span.end_datetime)

# Stitch all cameras into one canvas image (PIL.Image)
canvas = server.helpers.canvas.build_canvas(image_source="stillFrame")
rotated = server.helpers.canvas.build_canvas(rotation=90)   # degrees, counter-clockwise
```

Authentication happens automatically on the first request and is renewed when
the access token expires. Failed requests raise `vms.RequestFailed`, which
carries the HTTP `status`, `reason` and response `body`.

Which endpoints a service account can use depends on the permissions it has
been granted in the VMS. For endpoints and query syntax not covered by this
client, see the [REST API documentation](https://external.dev.apidoc.vetvise.dev/).

## Releasing

The package version comes from git tags, and Bitbucket Pipelines publishes to PyPI when a
`v*` tag is pushed (the `UV_PUBLISH_TOKEN` repository variable holds the PyPI token).

```bash
git tag -a v0.1.0 -m "First release"
git push origin v0.1.0
```

- Tags must start with `v`; `v0.1.0` becomes version `0.1.0`.
- Use `vX.Y.Z`: bump Z for fixes, Y for new features (or breaking changes before 1.0),
  X for breaking changes after 1.0.
- Every version can be published only once. Never move or reuse a tag; if a release is
  broken, fix it and tag the next version.
- Only a pushed tag publishes. Running the tag pipeline manually on a branch fails on purpose.

## License

Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
Copyright 2026 VetVise GmbH.
