everydeck 0.3.2__tar.gz → 0.4.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: everydeck
3
- Version: 0.3.2
3
+ Version: 0.4.1
4
4
  Summary: everydeck Python SDK: bounded buffer, background sender, flush on shutdown, reported data gaps
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://everydeck.ai
@@ -12,6 +12,8 @@ Provides-Extra: test
12
12
  Requires-Dist: pytest>=8; extra == "test"
13
13
  Requires-Dist: jsonschema[format]>=4.26; extra == "test"
14
14
  Requires-Dist: build>=1.2; extra == "test"
15
+ Requires-Dist: fastapi>=0.110; extra == "test"
16
+ Requires-Dist: httpx>=0.27; extra == "test"
15
17
  Dynamic: license-file
16
18
 
17
19
  # everydeck (Python SDK)
@@ -42,7 +44,9 @@ everydeck.signal("job.created", operation_id)
42
44
  - A buffer overflow is reported as a `gap` event, so everydeck shows a known data gap instead of silence.
43
45
  - `heartbeat_interval` sends `everydeck.sdk.heartbeat` from the sender thread. Give each component a stable `instance_id` (for example `"api"`, `"worker"`).
44
46
  - `release_key="auto"` derives the version from the deployment commit (`EVERYDECK_RELEASE_KEY`, `GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, `RENDER_GIT_COMMIT`, …) or local git.
47
+ - A server next to a hosted Supabase project (0.4.1): `Everydeck.from_supabase(supabase_admin, instance_id="api", heartbeat_interval=60)` reads endpoint, server key and manifest digest once at start from `public.everydeck_server_config()` through the server's own Supabase client (service key). everydeck adds that function after the owner's approval; only `service_role` may call it. Nothing to copy into the hosting dashboard. When `EVERYDECK_ENDPOINT`, `EVERYDECK_SERVER_KEY` and `EVERYDECK_MANIFEST_DIGEST` are all set, they win. If the call fails, the SDK switches itself off with a warning that names the function, never a value.
45
48
  - `everydeck.verify.verify_everydeck_request` checks everydeck's signature on bridge calls.
46
- - Read bridge (0.3.0): `everydeck.read_route.EverydeckReadBridge(endpoint, key, db)` is the ready-made route. It fetches its read scope from everydeck (`GET <endpoint>/v1/read-scope` with the bridge key) and uses it only with everydeck's signature; no read-scope file, no read role, no views. `db` is the connection the app already has: `PsycopgReadOnly(conninfo)` runs every query in `BEGIN READ ONLY`, `SupabaseReadOnly(client)` reads through the app's Supabase client with `select()` only (GET requests, which PostgREST runs read-only; only tables in schemas the Supabase API exposes).
49
+ - Read bridge on FastAPI or Starlette: `from everydeck.read_route import mount_read_bridge, SupabaseReadOnly` and `mount_read_bridge(app, SupabaseReadOnly(supabase_admin))` in the module that creates `app` add the route `/everydeck/read/{rest:path}` (outside the API schema); it reads `EVERYDECK_URL` and `EVERYDECK_READ_BRIDGE_TOKEN` from the environment when the first call arrives.
50
+ - Read bridge (0.3.0): `everydeck.read_route.EverydeckReadBridge(endpoint, key, db)` is the ready-made route for other frameworks. It fetches its read scope from everydeck (`GET <endpoint>/v1/read-scope` with the bridge key) and uses it only with everydeck's signature; no read-scope file, no read role, no views. `db` is the connection the app already has: `PsycopgReadOnly(conninfo)` runs every query in `BEGIN READ ONLY`, `SupabaseReadOnly(client)` reads through the app's Supabase client with `select()` only (GET requests, which PostgREST runs read-only; only tables in schemas the Supabase API exposes).
47
51
 
48
52
  No dependencies. Python 3.11 or newer. License: MIT.
@@ -0,0 +1,34 @@
1
+ # everydeck (Python SDK)
2
+
3
+ The Python server SDK of [everydeck](https://everydeck.ai): it reports the signals, errors and logs of your app's flows to everydeck.
4
+
5
+ ```bash
6
+ pip install everydeck
7
+ ```
8
+
9
+ ```python
10
+ import os
11
+ from everydeck import Everydeck
12
+
13
+ everydeck = Everydeck(
14
+ endpoint=os.environ["EVERYDECK_URL"],
15
+ credential="<server key of the environment>",
16
+ release_key="auto",
17
+ manifest_digest="<digest of the approved manifest>",
18
+ heartbeat_interval=60,
19
+ instance_id="api",
20
+ )
21
+ everydeck.signal("job.created", operation_id)
22
+ ```
23
+
24
+ - `signal()`, `error()` and `log()` never block and never raise: they enqueue into a bounded in-memory buffer; a background thread sends batches (at most 50 events, 64 KiB, gzip-compressed).
25
+ - Retries only on 429, 5xx, timeout and network errors; `Retry-After` is honoured; final rejections are dropped and counted, never reported as sent.
26
+ - A buffer overflow is reported as a `gap` event, so everydeck shows a known data gap instead of silence.
27
+ - `heartbeat_interval` sends `everydeck.sdk.heartbeat` from the sender thread. Give each component a stable `instance_id` (for example `"api"`, `"worker"`).
28
+ - `release_key="auto"` derives the version from the deployment commit (`EVERYDECK_RELEASE_KEY`, `GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, `RENDER_GIT_COMMIT`, …) or local git.
29
+ - A server next to a hosted Supabase project (0.4.1): `Everydeck.from_supabase(supabase_admin, instance_id="api", heartbeat_interval=60)` reads endpoint, server key and manifest digest once at start from `public.everydeck_server_config()` through the server's own Supabase client (service key). everydeck adds that function after the owner's approval; only `service_role` may call it. Nothing to copy into the hosting dashboard. When `EVERYDECK_ENDPOINT`, `EVERYDECK_SERVER_KEY` and `EVERYDECK_MANIFEST_DIGEST` are all set, they win. If the call fails, the SDK switches itself off with a warning that names the function, never a value.
30
+ - `everydeck.verify.verify_everydeck_request` checks everydeck's signature on bridge calls.
31
+ - Read bridge on FastAPI or Starlette: `from everydeck.read_route import mount_read_bridge, SupabaseReadOnly` and `mount_read_bridge(app, SupabaseReadOnly(supabase_admin))` in the module that creates `app` add the route `/everydeck/read/{rest:path}` (outside the API schema); it reads `EVERYDECK_URL` and `EVERYDECK_READ_BRIDGE_TOKEN` from the environment when the first call arrives.
32
+ - Read bridge (0.3.0): `everydeck.read_route.EverydeckReadBridge(endpoint, key, db)` is the ready-made route for other frameworks. It fetches its read scope from everydeck (`GET <endpoint>/v1/read-scope` with the bridge key) and uses it only with everydeck's signature; no read-scope file, no read role, no views. `db` is the connection the app already has: `PsycopgReadOnly(conninfo)` runs every query in `BEGIN READ ONLY`, `SupabaseReadOnly(client)` reads through the app's Supabase client with `select()` only (GET requests, which PostgREST runs read-only; only tables in schemas the Supabase API exposes).
33
+
34
+ No dependencies. Python 3.11 or newer. License: MIT.
@@ -48,7 +48,7 @@ from collections import deque
48
48
  from datetime import datetime, timezone
49
49
  from typing import Any, Callable, Literal
50
50
 
51
- __all__ = ["Everydeck", "AfterCommit", "SCHEMA_VERSION", "BATCH_MAX", "error_class_of", "scrub_text", "answer_of"]
51
+ __all__ = ["Everydeck", "AfterCommit", "SCHEMA_VERSION", "BATCH_MAX", "error_class_of", "scrub_text", "answer_of", "server_config_from_supabase"]
52
52
 
53
53
  SCHEMA_VERSION = "1.3-r0"
54
54
  # origin of every event: a server key always reports the platform `server`
@@ -722,6 +722,40 @@ class Everydeck:
722
722
  except Exception:
723
723
  pass
724
724
 
725
+ @classmethod
726
+ def from_supabase(cls, client: Any, *, release_key: str = "auto", on_warning: Callable[[str], None] | None = None, **kwargs: Any) -> "Everydeck":
727
+ """A client for a server of its own next to a hosted Supabase project: endpoint, server key and manifest digest come from
728
+ public.everydeck_server_config() through the Supabase client the server already has (service key), unless all three
729
+ environment variables are set. Release key "auto" (the commit the host sets, e.g. RENDER_GIT_COMMIT). If the call fails, the
730
+ client is switched off with a warning that names the function and never a value; the app works unchanged.
731
+ """
732
+ warn = on_warning or (lambda m: _log.warning(m))
733
+ try:
734
+ cfg = server_config_from_supabase(client)
735
+ except Exception as e:
736
+ warn(f"everydeck: disabled: could not read public.everydeck_server_config() ({type(e).__name__}); nothing is sent to everydeck")
737
+ cfg = {"endpoint": "", "server_key": "", "manifest_digest": ""}
738
+ return cls(cfg.get("endpoint") or "", cfg.get("server_key") or "", release_key=release_key,
739
+ manifest_digest=cfg.get("manifest_digest") or "", on_warning=warn, **kwargs)
740
+
741
+
742
+ _CONFIG_ENV = (("endpoint", "EVERYDECK_ENDPOINT"), ("server_key", "EVERYDECK_SERVER_KEY"), ("manifest_digest", "EVERYDECK_MANIFEST_DIGEST"))
743
+
744
+
745
+ def server_config_from_supabase(client: Any) -> dict[str, Any]:
746
+ """everydeck settings of a server of its own: the three environment variables when all are set, else one call of
747
+ public.everydeck_server_config() with the server's Supabase client (supabase-py; only service_role may call it).
748
+ Returns endpoint, server_key and manifest_digest (a value may be None before everydeck wrote it). Raises when the call fails."""
749
+ env = {k: os.environ.get(v, "") for k, v in _CONFIG_ENV}
750
+ if all(env.values()):
751
+ return env
752
+ data = client.rpc("everydeck_server_config").execute().data
753
+ if isinstance(data, list):
754
+ data = data[0] if data else None
755
+ if not isinstance(data, dict):
756
+ raise ValueError("everydeck_server_config returned no object")
757
+ return {k: data.get(k) for k, _ in _CONFIG_ENV}
758
+
725
759
 
726
760
  def _safe_id(line: str) -> str | None:
727
761
  try:
@@ -1,6 +1,14 @@
1
1
  """The read bridge as a ready-made route: Python version of @everydeck/sdk/read-bridge, same behavior.
2
2
 
3
- The app mounts it with the connection it already has; no reader role, no views, no read scope file in the repo:
3
+ FastAPI or Starlette: two lines in the module that creates `app`, with the connection the app already has (no helper module, no reader role,
4
+ no views, no read scope file in the repo):
5
+
6
+ # everydeck read bridge: everydeck reads only the data the owner approved, read-only, and only with everydeck's signature
7
+ from everydeck.read_route import mount_read_bridge, SupabaseReadOnly
8
+ mount_read_bridge(app, SupabaseReadOnly(supabase_admin)) # or PsycopgReadOnly(os.environ["DATABASE_URL"])
9
+
10
+ It adds the route /everydeck/read/{rest:path} (not in the API schema) and reads EVERYDECK_URL and EVERYDECK_READ_BRIDGE_TOKEN from the environment
11
+ when the first call arrives. Other frameworks call the bridge themselves:
4
12
 
5
13
  from everydeck.read_route import EverydeckReadBridge, SupabaseReadOnly # or PsycopgReadOnly(os.environ["DATABASE_URL"])
6
14
  bridge = EverydeckReadBridge(os.environ["EVERYDECK_URL"], os.environ["EVERYDECK_READ_BRIDGE_TOKEN"], SupabaseReadOnly(supabase_admin))
@@ -233,3 +241,39 @@ class EverydeckReadBridge:
233
241
  if isinstance(out, str):
234
242
  return 503, {"error": out}
235
243
  return out[1].handle(method, path, query, authorization, headers=headers, body=body, url=url)
244
+
245
+
246
+ READ_ROUTE = "/everydeck/read/{rest:path}"
247
+
248
+
249
+ def mount_read_bridge(app: Any, db: Any, **options: Any) -> None:
250
+ """Mounts everydeck's read bridge on a FastAPI or Starlette app at /everydeck/read/{rest:path}, outside the API schema.
251
+
252
+ `db` is the connection the app already has: SupabaseReadOnly(<the app's Supabase client>) or PsycopgReadOnly(<database URL>). The route only
253
+ answers calls signed by everydeck, reads only the approved columns and never writes (see EverydeckReadBridge). EVERYDECK_URL and
254
+ EVERYDECK_READ_BRIDGE_TOKEN come from the environment when the first call arrives; `options` go to EverydeckReadBridge."""
255
+ import os
256
+
257
+ from starlette.concurrency import run_in_threadpool
258
+ from starlette.requests import Request
259
+ from starlette.responses import JSONResponse
260
+
261
+ holder: list[EverydeckReadBridge] = []
262
+ lock = threading.Lock()
263
+
264
+ def bridge() -> EverydeckReadBridge:
265
+ with lock:
266
+ key = os.environ.get("EVERYDECK_READ_BRIDGE_TOKEN")
267
+ if not holder or (key and key not in holder[0].keys):
268
+ holder[:] = [EverydeckReadBridge(os.environ.get("EVERYDECK_URL"), key, db, **options)]
269
+ return holder[0]
270
+
271
+ async def everydeck_read(request: Request) -> JSONResponse:
272
+ b = bridge()
273
+ status, body = await run_in_threadpool(b.handle, request.method, request.url.path, dict(request.query_params),
274
+ request.headers.get("authorization"), request.headers, await request.body(), str(request.url))
275
+ return JSONResponse(body, status_code=status)
276
+
277
+ # a plain Starlette route (FastAPI takes it as well): the handler gets the request itself, FastAPI resolves no parameters for it
278
+ from starlette.routing import Route
279
+ app.router.routes.append(Route(READ_ROUTE, everydeck_read, methods=["GET", "POST", "PUT", "PATCH", "DELETE"], include_in_schema=False))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: everydeck
3
- Version: 0.3.2
3
+ Version: 0.4.1
4
4
  Summary: everydeck Python SDK: bounded buffer, background sender, flush on shutdown, reported data gaps
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://everydeck.ai
@@ -12,6 +12,8 @@ Provides-Extra: test
12
12
  Requires-Dist: pytest>=8; extra == "test"
13
13
  Requires-Dist: jsonschema[format]>=4.26; extra == "test"
14
14
  Requires-Dist: build>=1.2; extra == "test"
15
+ Requires-Dist: fastapi>=0.110; extra == "test"
16
+ Requires-Dist: httpx>=0.27; extra == "test"
15
17
  Dynamic: license-file
16
18
 
17
19
  # everydeck (Python SDK)
@@ -42,7 +44,9 @@ everydeck.signal("job.created", operation_id)
42
44
  - A buffer overflow is reported as a `gap` event, so everydeck shows a known data gap instead of silence.
43
45
  - `heartbeat_interval` sends `everydeck.sdk.heartbeat` from the sender thread. Give each component a stable `instance_id` (for example `"api"`, `"worker"`).
44
46
  - `release_key="auto"` derives the version from the deployment commit (`EVERYDECK_RELEASE_KEY`, `GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, `RENDER_GIT_COMMIT`, …) or local git.
47
+ - A server next to a hosted Supabase project (0.4.1): `Everydeck.from_supabase(supabase_admin, instance_id="api", heartbeat_interval=60)` reads endpoint, server key and manifest digest once at start from `public.everydeck_server_config()` through the server's own Supabase client (service key). everydeck adds that function after the owner's approval; only `service_role` may call it. Nothing to copy into the hosting dashboard. When `EVERYDECK_ENDPOINT`, `EVERYDECK_SERVER_KEY` and `EVERYDECK_MANIFEST_DIGEST` are all set, they win. If the call fails, the SDK switches itself off with a warning that names the function, never a value.
45
48
  - `everydeck.verify.verify_everydeck_request` checks everydeck's signature on bridge calls.
46
- - Read bridge (0.3.0): `everydeck.read_route.EverydeckReadBridge(endpoint, key, db)` is the ready-made route. It fetches its read scope from everydeck (`GET <endpoint>/v1/read-scope` with the bridge key) and uses it only with everydeck's signature; no read-scope file, no read role, no views. `db` is the connection the app already has: `PsycopgReadOnly(conninfo)` runs every query in `BEGIN READ ONLY`, `SupabaseReadOnly(client)` reads through the app's Supabase client with `select()` only (GET requests, which PostgREST runs read-only; only tables in schemas the Supabase API exposes).
49
+ - Read bridge on FastAPI or Starlette: `from everydeck.read_route import mount_read_bridge, SupabaseReadOnly` and `mount_read_bridge(app, SupabaseReadOnly(supabase_admin))` in the module that creates `app` add the route `/everydeck/read/{rest:path}` (outside the API schema); it reads `EVERYDECK_URL` and `EVERYDECK_READ_BRIDGE_TOKEN` from the environment when the first call arrives.
50
+ - Read bridge (0.3.0): `everydeck.read_route.EverydeckReadBridge(endpoint, key, db)` is the ready-made route for other frameworks. It fetches its read scope from everydeck (`GET <endpoint>/v1/read-scope` with the bridge key) and uses it only with everydeck's signature; no read-scope file, no read role, no views. `db` is the connection the app already has: `PsycopgReadOnly(conninfo)` runs every query in `BEGIN READ ONLY`, `SupabaseReadOnly(client)` reads through the app's Supabase client with `select()` only (GET requests, which PostgREST runs read-only; only tables in schemas the Supabase API exposes).
47
51
 
48
52
  No dependencies. Python 3.11 or newer. License: MIT.
@@ -3,3 +3,5 @@
3
3
  pytest>=8
4
4
  jsonschema[format]>=4.26
5
5
  build>=1.2
6
+ fastapi>=0.110
7
+ httpx>=0.27
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "everydeck"
3
- version = "0.3.2"
3
+ version = "0.4.1"
4
4
  description = "everydeck Python SDK: bounded buffer, background sender, flush on shutdown, reported data gaps"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -13,7 +13,7 @@ Homepage = "https://everydeck.ai"
13
13
  Repository = "https://github.com/everydeck/everydeck"
14
14
 
15
15
  [project.optional-dependencies]
16
- test = ["pytest>=8", "jsonschema[format]>=4.26", "build>=1.2"]
16
+ test = ["pytest>=8", "jsonschema[format]>=4.26", "build>=1.2", "fastapi>=0.110", "httpx>=0.27"]
17
17
 
18
18
  [build-system]
19
19
  requires = ["setuptools>=77"]
everydeck-0.3.2/README.md DELETED
@@ -1,32 +0,0 @@
1
- # everydeck (Python SDK)
2
-
3
- The Python server SDK of [everydeck](https://everydeck.ai): it reports the signals, errors and logs of your app's flows to everydeck.
4
-
5
- ```bash
6
- pip install everydeck
7
- ```
8
-
9
- ```python
10
- import os
11
- from everydeck import Everydeck
12
-
13
- everydeck = Everydeck(
14
- endpoint=os.environ["EVERYDECK_URL"],
15
- credential="<server key of the environment>",
16
- release_key="auto",
17
- manifest_digest="<digest of the approved manifest>",
18
- heartbeat_interval=60,
19
- instance_id="api",
20
- )
21
- everydeck.signal("job.created", operation_id)
22
- ```
23
-
24
- - `signal()`, `error()` and `log()` never block and never raise: they enqueue into a bounded in-memory buffer; a background thread sends batches (at most 50 events, 64 KiB, gzip-compressed).
25
- - Retries only on 429, 5xx, timeout and network errors; `Retry-After` is honoured; final rejections are dropped and counted, never reported as sent.
26
- - A buffer overflow is reported as a `gap` event, so everydeck shows a known data gap instead of silence.
27
- - `heartbeat_interval` sends `everydeck.sdk.heartbeat` from the sender thread. Give each component a stable `instance_id` (for example `"api"`, `"worker"`).
28
- - `release_key="auto"` derives the version from the deployment commit (`EVERYDECK_RELEASE_KEY`, `GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, `RENDER_GIT_COMMIT`, …) or local git.
29
- - `everydeck.verify.verify_everydeck_request` checks everydeck's signature on bridge calls.
30
- - Read bridge (0.3.0): `everydeck.read_route.EverydeckReadBridge(endpoint, key, db)` is the ready-made route. It fetches its read scope from everydeck (`GET <endpoint>/v1/read-scope` with the bridge key) and uses it only with everydeck's signature; no read-scope file, no read role, no views. `db` is the connection the app already has: `PsycopgReadOnly(conninfo)` runs every query in `BEGIN READ ONLY`, `SupabaseReadOnly(client)` reads through the app's Supabase client with `select()` only (GET requests, which PostgREST runs read-only; only tables in schemas the Supabase API exposes).
31
-
32
- No dependencies. Python 3.11 or newer. License: MIT.
File without changes
File without changes
File without changes