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.18.0.tar.gz (47.3 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.18.0-py3-none-any.whl (41.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: placebrain_contracts-0.18.0.tar.gz
  • Upload date:
  • Size: 47.3 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.18.0.tar.gz
Algorithm Hash digest
SHA256 a8afeb93052665fabc61560118b9b87aaa59f011f2cba947171410b0efb9f0c9
MD5 f33cdbd69a2abb6a1a14744621b4310b
BLAKE2b-256 066ad451207ebbe56a2453312c980680bb0b0ae9b5d1d361be830b8fe5489a8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: placebrain_contracts-0.18.0-py3-none-any.whl
  • Upload date:
  • Size: 41.8 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.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87eaee60c4937358d68a24a22929eb4a74a8f90f87981d461ea2157ef106c007
MD5 283ef285a9510e138f48e751159c5fc9
BLAKE2b-256 426d9269fa6a8dcf696f2f40884d19386c963894b8af78c8db3c75e923744060

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