pamoja-profile
Named, ready-to-run device profiles from plain data or a JSON manifest, run as a node in every language. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
pip install pamoja-profile
from pamoja import profile
This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.
Example
The script the test suite runs, spliced here as it ran.
From bindings/python/guides/profile.py:
from pathlib import Path
from pamoja.loopback import LoopbackBroker
from pamoja.profile import Node, Profile
# A profile is a file. This one ships in the catalog under profiles/: it holds a brooder at
# 32 C by switching a heat lamp, says what it reads, and says how a dashboard draws it.
text = Path("profiles/brooder-heater.json").read_text(encoding="utf-8")
profile = Profile.from_json(text)
print(
f"profile {profile.name} reads {profile.reads.quantity} in {profile.reads.unit} "
f"and reports on {profile.topic}"
)
async def example() -> bool:
# A node is the profile and the parts that make it run: a sensor, an output, and a link.
# A morning of readings stands in for the probe, and a dashboard listens on the same
# broker.
broker = LoopbackBroker()
link = broker.link()
dashboard = broker.link()
await link.connect()
await dashboard.connect()
await dashboard.subscribe(profile.topic)
morning = [27.5, 31.8, 32.6, 32.1, 31.4]
lamp = []
node = Node(profile, read=lambda: morning.pop(0), drive=lamp.append, link=link)
# Each tick reads, decides, switches the lamp, and publishes the reading. The lamp comes
# on at 31.5 C or below and goes off at 32.5 C or above, and in between it stays as it
# was; a reading more than 4 C from 32 raises an alert as well.
was = False
for _ in range(5):
tick = await node.tick()
on = tick.reaction.actuator is True
if on:
change = "lamp stays on" if was else "lamp on"
else:
change = "lamp off" if was else "lamp stays off"
alert = f", alert {tick.reaction.alert.kind}" if tick.reaction.alert else ""
print(f"{f'{tick.reading:g} C':<10}{change}{alert}")
was = on
# The dashboard heard every reading the node published.
heard = [f"{(await dashboard.recv()).number:g}" for _ in range(5)]
print(f"heard {', '.join(heard)} on {profile.topic}")
# Between ticks the node waits as long as its battery allows: often on a healthy charge,
# sparingly on a low one. run() does this until stopped, waiting each interval.
for charge in [0.8, 0.3, 0.1]:
mode, seconds = node.schedule(charge)
print(f"battery at {charge * 100:.0f}% it runs {mode} and waits {seconds:g} s")
# The same file says how a dashboard draws the node.
element = profile.presentation.elements[0]
low, high = element.band
print(
f"draws {element.key} in {element.unit} on a {element.viz}, "
f"safe from {low:g} to {high:g}"
)
return lamp[-1]
lamp_on = asyncio.run(example())
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-profile |
reference, docs.rs, install |
| TypeScript | @pamoja/profile |
reference, install |
| Python | pamoja-profile |
reference, install |
| C# | Pamoja.Profile |
reference, install |
Documentation
pamoja.profilereference, every class and function in this module.- The Device profiles guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Release files for pamoja-profile 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pamoja_profile-0.2.0.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pamoja_profile-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.8 kB
Release files / pamoja_profile-0.2.0.tar.gz
| Download URL | pamoja_profile-0.2.0.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19dcc599fa077e18475a5bc6ed11a96ba4ad9bfb58f1e06407487cc16150a4b7
|
|
BLAKE2b-256 checksum How to use checksums |
cd5e1dff3fee7f01584dd83245e8fbf07ba7c175debf7272361ccc69245d20ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / pamoja_profile-0.2.0-py3-none-any.whl
| Download URL | pamoja_profile-0.2.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e4045ae3578b92ab5e4c377da72edefe00dcb47d9ccf487f9a775f3c2708cb5
|
|
BLAKE2b-256 checksum How to use checksums |
7869a53959ca73f2df4a7925ce0141b368a74877719b5bd663d9b80a7d0d0f81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|