plexus-python 0.11.2__py3-none-any.whl → 0.11.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
plexus/__init__.py CHANGED
@@ -23,7 +23,7 @@ from plexus.client import (
23
23
  )
24
24
  from plexus.config import RetryConfig
25
25
 
26
- __version__ = "0.11.2"
26
+ __version__ = "0.11.4"
27
27
  __all__ = [
28
28
  "AuthenticationError",
29
29
  "BatchSender",
@@ -61,7 +61,7 @@ Four things the gateway will reject you for. Get these right or nothing lands:
61
61
  1. **The array is `points`.** `"metrics": [...]` returns `400 {"error":"'points' array is required"}`.
62
62
  2. **Every point needs `class`**, either `"metric"` or `"event"`. There is no default.
63
63
  3. **`timestamp` is a number, never a string.** An ISO-8601 string returns `points[i].timestamp must be a number`. Epoch **milliseconds**; a positive value below `1e12` is read as **seconds** and scaled for you, so either unit works as long as it's numeric.
64
- 4. **`source_id` must match `^[a-z0-9][a-z0-9_-]{1,62}$`** and is not deduplicated — two devices declaring the same id merge into one source. This is what SD-card clones do when they all boot as `raspberrypi`.
64
+ 4. **`source_id` must match `^[a-z0-9][a-z0-9._-]*$` (max 256 chars)** and is not deduplicated — two devices declaring the same id merge into one source. This is what SD-card clones do when they all boot as `raspberrypi`.
65
65
 
66
66
  `timestamp` is optional. Omit it and the gateway stamps the point with its receive time — which is the right move on a device whose clock has never been NTP-synced. Per-point `tags` (a flat string→string map) are supported and optional.
67
67
 
plexus/cli.py CHANGED
@@ -31,6 +31,7 @@ import threading
31
31
  import urllib.parse
32
32
  import webbrowser
33
33
  from pathlib import Path
34
+ from typing import Any
34
35
 
35
36
  from . import config
36
37
 
@@ -428,8 +429,15 @@ def cmd_logout(_args: argparse.Namespace) -> int:
428
429
  return 0
429
430
 
430
431
 
431
- def cmd_whoami(_args: argparse.Namespace) -> int:
432
- """Print the prefix of the locally stored key + the configured endpoint."""
432
+ def cmd_whoami(args: argparse.Namespace) -> int:
433
+ """Report the local key, and whether the server still accepts it.
434
+
435
+ Printing the key alone was worse than printing nothing: a revoked or
436
+ expired credential produced confident-looking output and a zero exit, and
437
+ the 401s that followed from the SDK looked unrelated. `whoami` is what
438
+ someone runs precisely when they suspect their auth — it has to answer
439
+ that question rather than confirm a file exists.
440
+ """
433
441
  key = config.get_api_key()
434
442
  endpoint = config.get_endpoint()
435
443
  if not key:
@@ -438,7 +446,60 @@ def cmd_whoami(_args: argparse.Namespace) -> int:
438
446
  masked = f"{key[:8]}…{key[-4:]}" if len(key) > 12 else key
439
447
  print(f"key: {masked}")
440
448
  print(f"endpoint: {endpoint}")
441
- return 0
449
+
450
+ if args.no_verify:
451
+ return 0
452
+
453
+ status, body = _verify_key(endpoint, key)
454
+ if status == 200:
455
+ org = body.get("org_id") or "unknown"
456
+ scopes = ", ".join(body.get("scopes") or []) or "default"
457
+ print(f"org: {org}")
458
+ print(f"scopes: {scopes}")
459
+ print("status: valid")
460
+ return 0
461
+ if status == 401:
462
+ print("status: REJECTED — this key is invalid, revoked or expired.")
463
+ print(" Run `plexus init --force` to authorize this machine again.")
464
+ return 1
465
+ if status == 403:
466
+ print("status: DISABLED — the key is real but access is switched off.")
467
+ print(" Usually billing; check with your org admin.")
468
+ return 1
469
+ if status is None:
470
+ # Could not ask. Say so rather than implying either answer.
471
+ print(f"status: unknown — could not reach {endpoint} ({body})")
472
+ return 0
473
+ print(f"status: unexpected response ({status})")
474
+ return 1
475
+
476
+
477
+ def _verify_key(endpoint: str, key: str) -> tuple[int | None, Any]:
478
+ """Ask the server whether a key is good. Returns (status, parsed_or_reason).
479
+
480
+ A network failure returns (None, reason): unreachable is not the same as
481
+ rejected, and reporting one as the other is how a flaky connection gets
482
+ mistaken for a credentials problem.
483
+ """
484
+ import json as _json
485
+ import urllib.error
486
+ import urllib.request
487
+
488
+ req = urllib.request.Request(
489
+ f"{endpoint.rstrip('/')}/api/auth/verify-key",
490
+ headers={"x-api-key": key},
491
+ method="GET",
492
+ )
493
+ try:
494
+ with urllib.request.urlopen(req, timeout=10) as resp:
495
+ return resp.status, _json.loads(resp.read().decode() or "{}")
496
+ except urllib.error.HTTPError as e:
497
+ try:
498
+ return e.code, _json.loads(e.read().decode() or "{}")
499
+ except Exception:
500
+ return e.code, {}
501
+ except Exception as e: # DNS, TLS, timeout, offline
502
+ return None, str(e)
442
503
 
443
504
 
444
505
  def _bundled_skills_dir() -> Path | None:
@@ -507,11 +568,50 @@ def _default_skills_target(args: argparse.Namespace) -> Path:
507
568
  return Path.home() / ".claude" / "skills"
508
569
 
509
570
 
571
+ class _VersionAwareParser(argparse.ArgumentParser):
572
+ """Turns an unknown subcommand into a version diagnosis.
573
+
574
+ argparse says `invalid choice: 'skills'` and stops. When the real cause is
575
+ an old install — a pipx shim from months ago shadowing a fresh pip
576
+ install, say — that message sends people looking for a typo instead of at
577
+ their version. The command they were told to run genuinely does not exist
578
+ *here*, and the fix is an upgrade, so say which version is running and how
579
+ to move it.
580
+ """
581
+
582
+ def error(self, message: str) -> None: # type: ignore[override]
583
+ if "invalid choice" in message:
584
+ from plexus import __version__
585
+
586
+ self.print_usage(sys.stderr)
587
+ print(f"\n{self.prog}: error: {message}", file=sys.stderr)
588
+ print(
589
+ f"\nYou are running plexus-python {__version__}. If you were "
590
+ "following a doc that\nnames this command, your install is "
591
+ "probably older than the doc:\n"
592
+ "\n pip install --upgrade plexus-python"
593
+ "\n pipx upgrade plexus-python # if you installed with pipx"
594
+ "\n\nThen check with: plexus --version",
595
+ file=sys.stderr,
596
+ )
597
+ self.exit(2)
598
+ super().error(message)
599
+
600
+
510
601
  def build_parser() -> argparse.ArgumentParser:
511
- parser = argparse.ArgumentParser(
602
+ from plexus import __version__
603
+
604
+ parser = _VersionAwareParser(
512
605
  prog="plexus",
513
606
  description="Plexus CLI — auth, send, query telemetry from your terminal.",
514
607
  )
608
+ # The first thing anyone types when a CLI misbehaves, and previously an
609
+ # error: `plexus --version` demanded a subcommand and told you nothing.
610
+ parser.add_argument(
611
+ "--version",
612
+ action="version",
613
+ version=f"plexus-python {__version__}",
614
+ )
515
615
  sub = parser.add_subparsers(dest="command", required=True)
516
616
 
517
617
  init = sub.add_parser(
@@ -537,6 +637,11 @@ def build_parser() -> argparse.ArgumentParser:
537
637
  logout.set_defaults(func=cmd_logout)
538
638
 
539
639
  whoami = sub.add_parser("whoami", help="Show the local credential summary.")
640
+ whoami.add_argument(
641
+ "--no-verify",
642
+ action="store_true",
643
+ help="Skip the server check and only print what is stored locally.",
644
+ )
540
645
  whoami.set_defaults(func=cmd_whoami)
541
646
 
542
647
  skills = sub.add_parser(
plexus/ws.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """
2
2
  WebSocket transport for the Plexus Python SDK.
3
3
 
4
- Wire-compatible with the C SDK (`plexus_ws.c`). Targets the gateway's
4
+ Implements the gateway's device wire protocol. Targets its
5
5
  `/ws/device` endpoint and exchanges the same JSON frames:
6
6
 
7
7
  client → {"type": "device_auth", "api_key": ..., "source_id": ...,
@@ -392,7 +392,7 @@ class WebSocketTransport:
392
392
  command = msg.get("command") or ""
393
393
  params = msg.get("params") or {}
394
394
 
395
- # Ack immediately (matches C SDK: plexus_ws.c:275-280)
395
+ # Ack immediately, per the gateway wire contract
396
396
  self._send_frame({
397
397
  "type": "command_result",
398
398
  "id": cmd_id,
@@ -547,8 +547,7 @@ def _safe_json(raw: Any) -> dict[str, Any]:
547
547
 
548
548
 
549
549
  def _backoff_delay(attempt: int) -> float:
550
- """Exponential backoff with ±25% jitter, capped at BACKOFF_MAX_S.
551
- Matches plexus_ws.c:44-52."""
550
+ """Exponential backoff with ±25% jitter, capped at BACKOFF_MAX_S."""
552
551
  base = min(BACKOFF_BASE_S * (2 ** attempt), BACKOFF_MAX_S)
553
552
  jitter = base * 0.25 * (2 * random.random() - 1)
554
553
  return max(0.1, base + jitter)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: plexus-python
3
- Version: 0.11.2
3
+ Version: 0.11.4
4
4
  Summary: Thin Python SDK for Plexus — send telemetry in one line
5
5
  Project-URL: Homepage, https://plexus.company
6
6
  Project-URL: Documentation, https://docs.plexus.company
@@ -66,7 +66,7 @@ curl -sL https://app.plexus.company/setup | bash -s -- \
66
66
  --key plx_xxx --name drone-01
67
67
  ```
68
68
 
69
- The name must match `^[a-z0-9][a-z0-9_-]{1,62}$`. `setup.sh` refuses to run without `--name` (or without a TTY to prompt for one) — this is deliberate, because the previous `hostname` fallback silently merged telemetry from cloned SD-card images that all booted as `raspberrypi`.
69
+ The name must match `^[a-z0-9][a-z0-9._-]*$` (max 256 chars). `setup.sh` refuses to run without `--name` (or without a TTY to prompt for one) — this is deliberate, because the previous `hostname` fallback silently merged telemetry from cloned SD-card images that all booted as `raspberrypi`.
70
70
 
71
71
  **Names are not auto-deduplicated.** The gateway echoes back whatever `source_id` you declare, unchanged — pick a unique name per device (that's what `--name` and `source_id=...` are for). Two devices that declare the same name write into the same source.
72
72
 
@@ -252,7 +252,7 @@ px.send("temperature", 72.5, timestamp=t) # your timestamp, used as-is, no cor
252
252
 
253
253
  ## Transport
254
254
 
255
- By default the SDK connects over a **WebSocket** to `/ws/device` on the gateway — same wire protocol as the C SDK. This gives you:
255
+ By default the SDK connects over a **WebSocket** to `/ws/device` on the gateway — the gateway's device wire protocol. This gives you:
256
256
 
257
257
  - lower-latency streaming of telemetry,
258
258
  - live command delivery from the UI / API to the device.
@@ -1,19 +1,19 @@
1
- plexus/__init__.py,sha256=aKzqSESaFXWQ2mQ6XnckTtAsezjyYj4UpxhJEkWeOhk,808
1
+ plexus/__init__.py,sha256=3108jW9HO6oLnblXhpp7gpqyL2ZAE7uaMC5F18gwQ5c,808
2
2
  plexus/_log.py,sha256=3fjXrHFZghQ_17umMcvDUjjTH6aTQB3J4SpVDBiH03w,335
3
3
  plexus/batching.py,sha256=mPMa3m9xK-DCwRmuyL_aqaTltimIOtwoDzz4PfKWyh8,10452
4
4
  plexus/buffer.py,sha256=UNv_jEcrDwbkjJ6uhCehb7uBI2EuFEwO40waDpZn_5I,9579
5
- plexus/cli.py,sha256=TenKqhvh7Z-JhAUj4kjogrRGA2Hlrfd3TvBFo4S5tlk,17633
5
+ plexus/cli.py,sha256=YFkptze8LRc6mBmDgbsTeU8J6i8MMsdTWvtm3jCINiI,21773
6
6
  plexus/client.py,sha256=H69DR30pj3X8PiURZsViGTDHsIsQ2Kn4muHNECsioKw,53865
7
7
  plexus/config.py,sha256=RuDh5UdVGdVQld5kQlXZO6CVXO4tS0HBalyaoAlXNvc,4416
8
- plexus/ws.py,sha256=2kUCTPkS-tG1XpL9RAzTiytk4Dbck5ypqkbDRSKaTF8,19811
8
+ plexus/ws.py,sha256=xQhJCOizX-V34tF3-r7Zpzs_wnBbNSCeEoZeFFXWH7E,19763
9
9
  plexus/cameras/__init__.py,sha256=AVu1vE1xfYk9lz1cprHlTfi0ieHf84UhQh9Z92E05b8,490
10
10
  plexus/cameras/thermal.py,sha256=-klCEJQG5GlLtELaowWOPYomwMsLK8O5pmmX0PqUrTA,12022
11
11
  plexus/_skills/README.md,sha256=9TNo9mssmBiBPkrYBiA2JJHWOIAEw6DvCWCYAvfzmjM,3243
12
12
  plexus/_skills/plexus/SKILL.md,sha256=Q1ZYe9YH-gOhMcGYuMG5H9DkHMfQOr3OazCtlxtP9f8,13617
13
13
  plexus/_skills/plexus-dashboard/SKILL.md,sha256=8xjdvI3orM31XHTLv1fSAWstCGMwt1HnEbo0SlpTxV4,9508
14
- plexus/_skills/plexus-firmware/SKILL.md,sha256=IkUqNbg5sM5VaZEb189P_aOUkm9_PlSqd4JLH0Nv830,12081
15
- plexus_python-0.11.2.dist-info/METADATA,sha256=Cpqy4cAMWY7qa1J4ofKpGMVKkRCGAYDhLTDoFVp9vfI,13517
16
- plexus_python-0.11.2.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
17
- plexus_python-0.11.2.dist-info/entry_points.txt,sha256=YlkOtTn_7Q_IGuJaKdvpU-90dCeBSPx2p_UTGMAz5Zs,43
18
- plexus_python-0.11.2.dist-info/licenses/LICENSE,sha256=nm3qP1F-JAGcfLpRVtIX24L20LMnRpxmZ2oKZzFpLVo,10755
19
- plexus_python-0.11.2.dist-info/RECORD,,
14
+ plexus/_skills/plexus-firmware/SKILL.md,sha256=C5tOGu0_LOb76n8US2SLpWSdZdeHQIa4e_5fvkX4DGU,12093
15
+ plexus_python-0.11.4.dist-info/METADATA,sha256=wu8laMoqY4e-3NtQbbma-LQFg4C0C6f0-1MwVzskasY,13532
16
+ plexus_python-0.11.4.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
17
+ plexus_python-0.11.4.dist-info/entry_points.txt,sha256=YlkOtTn_7Q_IGuJaKdvpU-90dCeBSPx2p_UTGMAz5Zs,43
18
+ plexus_python-0.11.4.dist-info/licenses/LICENSE,sha256=nm3qP1F-JAGcfLpRVtIX24L20LMnRpxmZ2oKZzFpLVo,10755
19
+ plexus_python-0.11.4.dist-info/RECORD,,