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

Uploaded Python 3

File details

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

File metadata

  • Download URL: placebrain_contracts-0.20.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.20.0.tar.gz
Algorithm Hash digest
SHA256 2175af5973f37d83965df5d20171ee9a3a11d4b9ddd8b9605c7936173956dd96
MD5 ae1ca4b72d54cd311e9d3a1b5abe0f9e
BLAKE2b-256 f5e9f5e6cc1b20b4bdb1333e52662e4e5507247dbdc23bcac83f54970033d428

See more details on using hashes here.

File details

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

File metadata

  • Download URL: placebrain_contracts-0.20.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.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f37e2454baeb84deb159f5dacccaf0269a4a91b9c4f55efe049f157d5667425
MD5 a9dc99d9fe58de779387e6f91cda37c4
BLAKE2b-256 f8e3e339b51ab409f0cb2f1670ebfdd71ea7ab4beb45865a65cdec018cb240c9

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