relay-runtime 0.1.0__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.
- relay_runtime-0.1.0/LICENSE +17 -0
- relay_runtime-0.1.0/PKG-INFO +103 -0
- relay_runtime-0.1.0/README.md +90 -0
- relay_runtime-0.1.0/pyproject.toml +33 -0
- relay_runtime-0.1.0/src/relay_runtime/__init__.py +10 -0
- relay_runtime-0.1.0/src/relay_runtime/py.typed +0 -0
- relay_runtime-0.1.0/src/relay_runtime/typing.py +73 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2026 Relay Contributors
|
|
5
|
+
|
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU General Public License
|
|
17
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: relay-runtime
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python library and public handler interfaces for Relay applications.
|
|
5
|
+
Keywords: relay,application-development,handlers
|
|
6
|
+
Author: Relay Contributors
|
|
7
|
+
License-Expression: GPL-3.0-or-later
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Typing :: Typed
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# relay-runtime
|
|
15
|
+
|
|
16
|
+
The official Python library for developing Relay applications and using Relay's
|
|
17
|
+
public handler interfaces.
|
|
18
|
+
|
|
19
|
+
The package is optional for Relay's execution. Add it as a normal application
|
|
20
|
+
dependency when your handlers import it. Its initial release publishes the
|
|
21
|
+
`HandlerContext` structural Protocol; Relay's Python bootstrap constructs the
|
|
22
|
+
actual context object for each invocation and passes it to the handler.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
With uv:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
uv add relay-runtime
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or with pip:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pip install relay-runtime
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The library supports Python 3.14 and newer.
|
|
39
|
+
|
|
40
|
+
## Handler example
|
|
41
|
+
|
|
42
|
+
Relay calls a handler with the event as its first argument and the context as
|
|
43
|
+
its second:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from relay_runtime.typing import HandlerContext
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def handler(event: dict, context: HandlerContext) -> None:
|
|
50
|
+
print(
|
|
51
|
+
f"request {context.request_id} "
|
|
52
|
+
f"has {context.get_remaining_time_ms()}ms left"
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`HandlerContext` is a public `typing.Protocol`, not the concrete context
|
|
57
|
+
implementation. Relay's Python bootstrap creates and supplies that actual
|
|
58
|
+
per-invocation object. The current release provides `HandlerContext`; later
|
|
59
|
+
releases may add application-development utilities.
|
|
60
|
+
|
|
61
|
+
## Contract
|
|
62
|
+
|
|
63
|
+
`HandlerContext` provides:
|
|
64
|
+
|
|
65
|
+
| Member | Type | Meaning |
|
|
66
|
+
| ------------------------- | ------------- | --------------------------------------------- |
|
|
67
|
+
| `request_id` | `str` | Stable identity for one logical invocation |
|
|
68
|
+
| `attempt` | `int` | 1-based attempt number |
|
|
69
|
+
| `max_attempts` | `int` | Configured total attempt budget |
|
|
70
|
+
| `deadline` | `datetime` | Absolute, timezone-aware cancellation instant |
|
|
71
|
+
| `message_id` | `str \| None` | Source message identity when one exists |
|
|
72
|
+
| `trace_id` | `str \| None` | W3C trace ID when tracing is enabled |
|
|
73
|
+
| `app` | `str` | Owning app name |
|
|
74
|
+
| `handler` | `str` | Handler identity |
|
|
75
|
+
| `get_remaining_time_ms()` | `int` | Milliseconds left, clamped at zero |
|
|
76
|
+
|
|
77
|
+
`max_attempts` is the configured budget, not an upper bound on `attempt`: a
|
|
78
|
+
configuration change can leave a claimed attempt above the current budget.
|
|
79
|
+
|
|
80
|
+
The package version is independent of the Relay release version. Future
|
|
81
|
+
releases may add exports, and existing members keep their documented meaning.
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
The package is managed with [uv](https://docs.astral.sh/uv/) and uses a `src`
|
|
86
|
+
layout with the `uv_build` backend.
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
cd packages/python
|
|
90
|
+
uv lock
|
|
91
|
+
uv sync --locked
|
|
92
|
+
uv run mypy
|
|
93
|
+
uv build
|
|
94
|
+
uv run pytest
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`uv.lock` is committed so installs and checks resolve the same versions. The
|
|
98
|
+
`dev` dependency group contains mypy and pytest only; neither is required by
|
|
99
|
+
handlers or by the package at runtime.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
GPL-3.0-or-later. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# relay-runtime
|
|
2
|
+
|
|
3
|
+
The official Python library for developing Relay applications and using Relay's
|
|
4
|
+
public handler interfaces.
|
|
5
|
+
|
|
6
|
+
The package is optional for Relay's execution. Add it as a normal application
|
|
7
|
+
dependency when your handlers import it. Its initial release publishes the
|
|
8
|
+
`HandlerContext` structural Protocol; Relay's Python bootstrap constructs the
|
|
9
|
+
actual context object for each invocation and passes it to the handler.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
With uv:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
uv add relay-runtime
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or with pip:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install relay-runtime
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The library supports Python 3.14 and newer.
|
|
26
|
+
|
|
27
|
+
## Handler example
|
|
28
|
+
|
|
29
|
+
Relay calls a handler with the event as its first argument and the context as
|
|
30
|
+
its second:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from relay_runtime.typing import HandlerContext
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
async def handler(event: dict, context: HandlerContext) -> None:
|
|
37
|
+
print(
|
|
38
|
+
f"request {context.request_id} "
|
|
39
|
+
f"has {context.get_remaining_time_ms()}ms left"
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`HandlerContext` is a public `typing.Protocol`, not the concrete context
|
|
44
|
+
implementation. Relay's Python bootstrap creates and supplies that actual
|
|
45
|
+
per-invocation object. The current release provides `HandlerContext`; later
|
|
46
|
+
releases may add application-development utilities.
|
|
47
|
+
|
|
48
|
+
## Contract
|
|
49
|
+
|
|
50
|
+
`HandlerContext` provides:
|
|
51
|
+
|
|
52
|
+
| Member | Type | Meaning |
|
|
53
|
+
| ------------------------- | ------------- | --------------------------------------------- |
|
|
54
|
+
| `request_id` | `str` | Stable identity for one logical invocation |
|
|
55
|
+
| `attempt` | `int` | 1-based attempt number |
|
|
56
|
+
| `max_attempts` | `int` | Configured total attempt budget |
|
|
57
|
+
| `deadline` | `datetime` | Absolute, timezone-aware cancellation instant |
|
|
58
|
+
| `message_id` | `str \| None` | Source message identity when one exists |
|
|
59
|
+
| `trace_id` | `str \| None` | W3C trace ID when tracing is enabled |
|
|
60
|
+
| `app` | `str` | Owning app name |
|
|
61
|
+
| `handler` | `str` | Handler identity |
|
|
62
|
+
| `get_remaining_time_ms()` | `int` | Milliseconds left, clamped at zero |
|
|
63
|
+
|
|
64
|
+
`max_attempts` is the configured budget, not an upper bound on `attempt`: a
|
|
65
|
+
configuration change can leave a claimed attempt above the current budget.
|
|
66
|
+
|
|
67
|
+
The package version is independent of the Relay release version. Future
|
|
68
|
+
releases may add exports, and existing members keep their documented meaning.
|
|
69
|
+
|
|
70
|
+
## Development
|
|
71
|
+
|
|
72
|
+
The package is managed with [uv](https://docs.astral.sh/uv/) and uses a `src`
|
|
73
|
+
layout with the `uv_build` backend.
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
cd packages/python
|
|
77
|
+
uv lock
|
|
78
|
+
uv sync --locked
|
|
79
|
+
uv run mypy
|
|
80
|
+
uv build
|
|
81
|
+
uv run pytest
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`uv.lock` is committed so installs and checks resolve the same versions. The
|
|
85
|
+
`dev` dependency group contains mypy and pytest only; neither is required by
|
|
86
|
+
handlers or by the package at runtime.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
GPL-3.0-or-later. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "relay-runtime"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Official Python library and public handler interfaces for Relay applications."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "GPL-3.0-or-later"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.14"
|
|
9
|
+
authors = [{ name = "Relay Contributors" }]
|
|
10
|
+
keywords = ["relay", "application-development", "handlers"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Typing :: Typed",
|
|
14
|
+
]
|
|
15
|
+
dependencies = []
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["uv_build>=0.9.26,<0.10.0"]
|
|
19
|
+
build-backend = "uv_build"
|
|
20
|
+
|
|
21
|
+
[dependency-groups]
|
|
22
|
+
dev = [
|
|
23
|
+
"mypy>=1.11",
|
|
24
|
+
"pytest>=8.3",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.mypy]
|
|
28
|
+
python_version = "3.14"
|
|
29
|
+
strict = true
|
|
30
|
+
files = ["src"]
|
|
31
|
+
|
|
32
|
+
[tool.pytest.ini_options]
|
|
33
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Official public interfaces for developing Python handlers on Relay.
|
|
2
|
+
|
|
3
|
+
The initial release publishes the ``HandlerContext`` Protocol. Relay's Python
|
|
4
|
+
bootstrap constructs the actual per-invocation context object.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from relay_runtime.typing import HandlerContext
|
|
8
|
+
|
|
9
|
+
__all__ = ["HandlerContext"]
|
|
10
|
+
__version__ = "0.1.0"
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Public handler interfaces for Python applications running on Relay.
|
|
2
|
+
|
|
3
|
+
The initial release exposes ``HandlerContext``, a Protocol describing the
|
|
4
|
+
context object Relay passes to each handler. Relay's Python bootstrap
|
|
5
|
+
constructs the concrete per-invocation value.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from typing import Protocol
|
|
10
|
+
|
|
11
|
+
__all__ = ["HandlerContext"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class HandlerContext(Protocol):
|
|
15
|
+
"""Metadata Relay supplies for exactly one handler invocation.
|
|
16
|
+
|
|
17
|
+
A handler receives a fresh instance as its second argument. Implementations
|
|
18
|
+
are structural: any object with these attributes and method satisfies the
|
|
19
|
+
contract, and handlers should treat the values as read-only.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def request_id(self) -> str:
|
|
24
|
+
"""Stable identity for one logical invocation.
|
|
25
|
+
|
|
26
|
+
Retries, redeliveries, and worker restarts reuse it for the same invocation.
|
|
27
|
+
State-free executions such as manual invocations and dead-letter replays get
|
|
28
|
+
a fresh identity.
|
|
29
|
+
"""
|
|
30
|
+
...
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def attempt(self) -> int:
|
|
34
|
+
"""1-based attempt number, starting at 1 for the initial execution."""
|
|
35
|
+
...
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def max_attempts(self) -> int:
|
|
39
|
+
"""Configured total attempt budget (initial attempt plus retries).
|
|
40
|
+
|
|
41
|
+
A configuration change can leave :attr:`attempt` above this value, so it is
|
|
42
|
+
not an upper bound for the current attempt.
|
|
43
|
+
"""
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def deadline(self) -> datetime:
|
|
48
|
+
"""Absolute, timezone-aware instant when the invocation is cancelled."""
|
|
49
|
+
...
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def message_id(self) -> str | None:
|
|
53
|
+
"""Source stream message identity, or ``None`` when no source exists."""
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def trace_id(self) -> str | None:
|
|
58
|
+
"""W3C trace ID for the invocation, or ``None`` when tracing is absent."""
|
|
59
|
+
...
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def app(self) -> str:
|
|
63
|
+
"""Name of the app that owns the handler."""
|
|
64
|
+
...
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def handler(self) -> str:
|
|
68
|
+
"""Handler identity, in the same form used by the app manifest."""
|
|
69
|
+
...
|
|
70
|
+
|
|
71
|
+
def get_remaining_time_ms(self) -> int:
|
|
72
|
+
"""Return milliseconds left before :attr:`deadline`, clamped at zero."""
|
|
73
|
+
...
|