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.19.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.19.0-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: placebrain_contracts-0.19.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.19.0.tar.gz
Algorithm Hash digest
SHA256 b462e93e248184450095d9d60698d5539b101174b53ad995c3a4fb30b8e9730a
MD5 32a5c7c8bf905a908076e41aef4dd7a6
BLAKE2b-256 d8659f12774d6c5c5c9d7ed797eb72523c869aa88c0114704f909129337f171e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: placebrain_contracts-0.19.0-py3-none-any.whl
  • Upload date:
  • Size: 41.6 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.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38f93903d6b9b3805a8967c0205ae896bcda9ef6ee77fc6f9d61a4233d592497
MD5 77873ce702eaeab874587eddcb8f0404
BLAKE2b-256 4d612559a0a4ac37e2944b5aedcead5b5d47b41cf2749e0cbd432d4ca20b743f

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