Skip to main content

Protocol buffer contracts and event schemas package

Project description

contracts

The shared wire-format for PlaceBrain: gRPC proto files + Pydantic event schemas, published to PyPI as placebrain-contracts.

License: Apache 2.0 PyPI Python 3.14

Every PlaceBrain service depends on this package. It contains:

  • The .proto files for the four gRPC services (auth, places, devices, collector).
  • Generated Python stubs (*_pb2.py, *_pb2_grpc.py, *.pyi) produced by CI.
  • Pydantic event models for Kafka and MQTT payloads.
  • Centralised topic/constant names so no service hardcodes a string.

Role in PlaceBrain

PlaceBrain is an open-source IoT platform for smart buildings. See the organization profile for the full architecture.

  • Consumed by auth, places, devices, gateway, collector.
  • Never hand-generate protobuf code — the CI/CD workflow does the full build: generates stubs, fixes up imports, builds an sdist/wheel and publishes to PyPI on every push to main.

What's inside

proto/
├── auth.proto           gRPC: Register, Login, RefreshTokens, OTP, ValidateToken, ...
├── places.proto         gRPC: PlacesService (CRUD + members + role constants)
├── devices.proto        gRPC: DevicesService (Device/Sensor/Actuator/Threshold/Command + MQTT auth)
└── collector.proto      gRPC: internal readings methods

placebrain_contracts/
├── auth_pb2.py / auth_pb2_grpc.py            (generated)
├── places_pb2.py / places_pb2_grpc.py        (generated)
├── devices_pb2.py / devices_pb2_grpc.py      (generated)
└── events/
    ├── base.py          BaseEvent
    ├── places.py        MemberAdded, MemberRemoved, MemberRoleChanged, PlaceDeleted
    ├── devices.py       DeviceDeleted, DevicesBulkDeleted, ThresholdCreated, ThresholdDeleted
    ├── telemetry.py     EmqxTelemetryMessage, EmqxStatusMessage, TelemetryPayload
    └── topics.py        TOPIC_* constants — single source of truth for Kafka topic names

Usage

# gRPC: import the whole module, not individual classes.
from placebrain_contracts import auth_pb2 as auth_pb
request = auth_pb.LoginRequest(email=..., password=...)

# Kafka events: pass Pydantic models straight to the broker.
from placebrain_contracts.events import MemberAdded, TOPIC_MEMBER_ADDED

await broker.publish(
    MemberAdded(place_id=place.id, user_id=user_id, role=role.value),
    topic=TOPIC_MEMBER_ADDED,
    key=f"{place.id}:{user_id}".encode(),
)

How a contract change gets shipped

Automated end-to-end, no manual build/publish:

  1. Edit proto/*.proto or Pydantic event models.
  2. Bump version in pyproject.toml.
  3. Commit and push to main.
  4. CI runs publish.yaml: generates stubs, fixes imports, builds with uv build, publishes to PyPI with uv publish.
  5. In consuming services, bump the version in pyproject.toml and uv lock --upgrade-package placebrain-contracts. Clear the uv cache first (uv cache clean placebrain-contracts) if you just published a new version moments ago.

License

Apache License 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

placebrain_contracts-0.17.0.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

placebrain_contracts-0.17.0-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file placebrain_contracts-0.17.0.tar.gz.

File metadata

  • Download URL: placebrain_contracts-0.17.0.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for placebrain_contracts-0.17.0.tar.gz
Algorithm Hash digest
SHA256 98bb5c63a2cd9cb0c4358255a47c6792009a6b3248783e07f91a42a2f0883454
MD5 fbc7b33dd93a479ac23715f8fa9a2f50
BLAKE2b-256 8b169c1cfe9500e999820a151e9ea2f3cd9169a7d6f210c5d251470717566906

See more details on using hashes here.

File details

Details for the file placebrain_contracts-0.17.0-py3-none-any.whl.

File metadata

  • Download URL: placebrain_contracts-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 41.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for placebrain_contracts-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eee13bdb245c4ee90628bfdc99280241efb9cab2ea39db164226a9bb6fcd3a40
MD5 d92684b64c024cd0ec6d40951ebca6b6
BLAKE2b-256 a26818642607b5e62c9b2e5ce8e93ab24acc3f65624f58c3f343ad5851b103f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page