Metadata-Version: 2.4
Name: sapient-msg
Version: 0.1.4
Summary: SAPIENT protobuf bindings (BSI Flex 335 v2.0)
Project-URL: Repository, https://github.com/nbowisdar/sapient-msg
Project-URL: Homepage, https://github.com/nbowisdar/sapient-msg
Project-URL: Documentation, https://github.com/nbowisdar/sapient-msg/blob/main/IntegrationGuide.md
Author-email: Virtuoz <virtuoz@demo-iot.technology>
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: protobuf<7,>=4.25
Description-Content-Type: text/markdown

# sapient-msg

Python protobuf bindings for the SAPIENT protocol (BSI Flex 335 v2.0).

Repository: https://github.com/nbowisdar/sapient-msg

## Install

From PyPI:

```bash
pip install sapient-msg
```

```bash
uv add sapient-msg
```

From GitHub:

```bash
uv add "sapient-msg @ git+https://github.com/nbowisdar/sapient-msg.git@v0.1.4"
```

For local development:

```bash
uv add --editable /path/to/sapient-msg
```

## Documentation

See [IntegrationGuide.md](IntegrationGuide.md) for connection setup, message flows, and compliance requirements.

## Usage

Import protobuf modules directly from the package root:

```python
from sapient_msg import sapient_message_pb2, registration_pb2
```

Create a registration message:

```python
from sapient_msg import registration_pb2

registration = registration_pb2.Registration(
    name="sensor-01",
    short_name="s01",
    icd_version="BSI Flex 335 v2.0",
)
```

Wrap it in a SAPIENT envelope:

```python
from datetime import datetime, timezone

from google.protobuf.timestamp_pb2 import Timestamp
from sapient_msg import sapient_message_pb2, registration_pb2

timestamp = Timestamp()
timestamp.FromDatetime(datetime.now(timezone.utc))

message = sapient_message_pb2.SapientMessage(
    timestamp=timestamp,
    node_id="sensor-01",
    registration=registration_pb2.Registration(name="sensor-01"),
)
```

Serialize and parse:

```python
from sapient_msg import sapient_message_pb2

data = message.SerializeToString()
parsed = sapient_message_pb2.SapientMessage()
parsed.ParseFromString(data)
```

Version-specific imports still work when needed:

```python
from sapient_msg.bsi_flex_335_v2_0 import sapient_message_pb2
from sapient_msg.latest import registration_pb2
```

## Regenerate bindings

Requires `grpcio-tools`:

```bash
uv pip install grpcio-tools
./scripts/generate.sh
```

## Release

Push a version tag to publish to PyPI via GitHub Actions (trusted publishing):

```bash
git tag v0.1.4
git push origin v0.1.4
```