plynx-sdk 2.0.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.
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: plynx-sdk
3
+ Version: 2.0.0
4
+ Summary: PLynx SDK: op authoring API and process wire types. Standard library only.
5
+ Keywords: plynx,sdk,workflow,dag,pipeline
6
+ Author: Ivan Khomyakov
7
+ License-Expression: Apache-2.0
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.11
18
+ Project-URL: Homepage, https://github.com/plynx-team/plynx
19
+ Project-URL: Repository, https://github.com/plynx-team/plynx
20
+ Project-URL: Issues, https://github.com/plynx-team/plynx/issues
21
+ Project-URL: Changelog, https://github.com/plynx-team/plynx/blob/master/CHANGELOG.md
22
+ Project-URL: Documentation, https://github.com/plynx-team/plynx/blob/master/docs/guides/author_pack.md
23
+ Description-Content-Type: text/markdown
24
+
25
+ # plynx-sdk
26
+
27
+ Zero-dependency Python SDK for authoring [PLynx](https://pypi.org/project/plynx/) operations and Node Packs. Standard library only.
28
+
29
+ ## Installation
30
+
31
+ Add `plynx-sdk` as a dependency of your Node Pack:
32
+
33
+ ```bash
34
+ uv add plynx-sdk
35
+ ```
36
+
37
+ Or install with pip:
38
+
39
+ ```bash
40
+ pip install plynx-sdk
41
+ ```
42
+
43
+ ## Quick Example
44
+
45
+ ```python
46
+ from typing import TypedDict
47
+ from plynx_sdk import Op, checkpoint, op
48
+
49
+
50
+ @op(title="Greet")
51
+ def greet(name: str) -> str:
52
+ return f"Hello, {name}!"
53
+
54
+
55
+ class PickOption(Op):
56
+ TITLE = "Pick Option"
57
+
58
+ class Outputs(TypedDict):
59
+ choice: str
60
+
61
+ def run(self, question: str) -> Outputs:
62
+ answer = checkpoint(question, options=["yes", "no"])
63
+ return {"choice": answer}
64
+ ```
65
+
66
+ ## Documentation
67
+
68
+ - [Guide: Authoring a Node Pack](https://github.com/plynx-team/plynx/blob/master/docs/guides/author_pack.md)
69
+ - [PLynx Repository](https://github.com/plynx-team/plynx)
70
+ - [Changelog](https://github.com/plynx-team/plynx/blob/master/CHANGELOG.md)
71
+
72
+ ## License
73
+
74
+ Apache-2.0
@@ -0,0 +1,50 @@
1
+ # plynx-sdk
2
+
3
+ Zero-dependency Python SDK for authoring [PLynx](https://pypi.org/project/plynx/) operations and Node Packs. Standard library only.
4
+
5
+ ## Installation
6
+
7
+ Add `plynx-sdk` as a dependency of your Node Pack:
8
+
9
+ ```bash
10
+ uv add plynx-sdk
11
+ ```
12
+
13
+ Or install with pip:
14
+
15
+ ```bash
16
+ pip install plynx-sdk
17
+ ```
18
+
19
+ ## Quick Example
20
+
21
+ ```python
22
+ from typing import TypedDict
23
+ from plynx_sdk import Op, checkpoint, op
24
+
25
+
26
+ @op(title="Greet")
27
+ def greet(name: str) -> str:
28
+ return f"Hello, {name}!"
29
+
30
+
31
+ class PickOption(Op):
32
+ TITLE = "Pick Option"
33
+
34
+ class Outputs(TypedDict):
35
+ choice: str
36
+
37
+ def run(self, question: str) -> Outputs:
38
+ answer = checkpoint(question, options=["yes", "no"])
39
+ return {"choice": answer}
40
+ ```
41
+
42
+ ## Documentation
43
+
44
+ - [Guide: Authoring a Node Pack](https://github.com/plynx-team/plynx/blob/master/docs/guides/author_pack.md)
45
+ - [PLynx Repository](https://github.com/plynx-team/plynx)
46
+ - [Changelog](https://github.com/plynx-team/plynx/blob/master/CHANGELOG.md)
47
+
48
+ ## License
49
+
50
+ Apache-2.0
@@ -0,0 +1,40 @@
1
+ [project]
2
+ name = "plynx-sdk"
3
+ version = "2.0.0"
4
+ description = "PLynx SDK: op authoring API and process wire types. Standard library only."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.11"
8
+ keywords = [
9
+ "plynx",
10
+ "sdk",
11
+ "workflow",
12
+ "dag",
13
+ "pipeline",
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Science/Research",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ ]
26
+ dependencies = []
27
+
28
+ [[project.authors]]
29
+ name = "Ivan Khomyakov"
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/plynx-team/plynx"
33
+ Repository = "https://github.com/plynx-team/plynx"
34
+ Issues = "https://github.com/plynx-team/plynx/issues"
35
+ Changelog = "https://github.com/plynx-team/plynx/blob/master/CHANGELOG.md"
36
+ Documentation = "https://github.com/plynx-team/plynx/blob/master/docs/guides/author_pack.md"
37
+
38
+ [build-system]
39
+ requires = ["uv_build>=0.9.0,<0.10"]
40
+ build-backend = "uv_build"
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "plynx-sdk"
3
+ version = "2.0.0"
4
+ description = "PLynx SDK: op authoring API and process wire types. Standard library only."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.11"
8
+ authors = [{ name = "Ivan Khomyakov" }]
9
+ keywords = ["plynx", "sdk", "workflow", "dag", "pipeline"]
10
+ classifiers = [
11
+ "Development Status :: 5 - Production/Stable",
12
+ "Intended Audience :: Developers",
13
+ "Intended Audience :: Science/Research",
14
+ "Operating System :: OS Independent",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Topic :: Software Development :: Libraries :: Python Modules",
20
+ ]
21
+ dependencies = []
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/plynx-team/plynx"
25
+ Repository = "https://github.com/plynx-team/plynx"
26
+ Issues = "https://github.com/plynx-team/plynx/issues"
27
+ Changelog = "https://github.com/plynx-team/plynx/blob/master/CHANGELOG.md"
28
+ Documentation = "https://github.com/plynx-team/plynx/blob/master/docs/guides/author_pack.md"
29
+
30
+ [build-system]
31
+ requires = ["uv_build>=0.9.0,<0.10"]
32
+ build-backend = "uv_build"
@@ -0,0 +1,41 @@
1
+ """PLynx SDK: op authoring API and process wire types. Standard library only."""
2
+
3
+ from plynx_sdk.checkpoint import CheckpointInterrupt, checkpoint, checkpoint_context
4
+ from plynx_sdk.op import Op, OpMetadata, op
5
+ from plynx_sdk.types import (
6
+ SEMANTIC_MEDIA_ALIASES,
7
+ AudioWav,
8
+ CsvFile,
9
+ Directory,
10
+ DirectoryMarker,
11
+ ImageFile,
12
+ JsonFile,
13
+ MarkdownFile,
14
+ Media,
15
+ MidiFile,
16
+ PdfFile,
17
+ Range,
18
+ TextFile,
19
+ )
20
+
21
+ __all__ = [
22
+ "SEMANTIC_MEDIA_ALIASES",
23
+ "AudioWav",
24
+ "CheckpointInterrupt",
25
+ "CsvFile",
26
+ "Directory",
27
+ "DirectoryMarker",
28
+ "ImageFile",
29
+ "JsonFile",
30
+ "MarkdownFile",
31
+ "Media",
32
+ "MidiFile",
33
+ "Op",
34
+ "OpMetadata",
35
+ "PdfFile",
36
+ "Range",
37
+ "TextFile",
38
+ "checkpoint",
39
+ "checkpoint_context",
40
+ "op",
41
+ ]
@@ -0,0 +1,125 @@
1
+ """Checkpoint interrupt and replay state (PROTOCOL.md section 5).
2
+
3
+ Standard library only.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import os
9
+ import tempfile
10
+ from collections.abc import Iterator, Mapping, Sequence
11
+ from contextlib import contextmanager
12
+ from contextvars import ContextVar
13
+ from dataclasses import dataclass, field
14
+ from pathlib import Path
15
+
16
+ from plynx_sdk.protocol import CheckpointManifest
17
+
18
+
19
+ class CheckpointInterrupt(BaseException):
20
+ """Raised when ``checkpoint()`` pauses a node attempt for user input.
21
+
22
+ Inherits from ``BaseException`` so ``except Exception:`` inside op code
23
+ does not swallow a checkpoint interrupt.
24
+ """
25
+
26
+ def __init__(self, manifest: CheckpointManifest) -> None:
27
+ super().__init__(f"Checkpoint {manifest.checkpoint_id}: {manifest.question}")
28
+ self.manifest = manifest
29
+
30
+
31
+ @dataclass
32
+ class _CheckpointState:
33
+ """Per-attempt checkpoint counter, pre-supplied answers, and target node directory."""
34
+
35
+ answers: dict[str, str] = field(default_factory=dict)
36
+ node_dir: Path | None = None
37
+ call_index: int = 0
38
+
39
+
40
+ _CURRENT_STATE: ContextVar[_CheckpointState | None] = ContextVar(
41
+ "_plynx_checkpoint_state", default=None
42
+ )
43
+
44
+
45
+ def _atomic_write_checkpoint(path: Path, content: str) -> None:
46
+ path.parent.mkdir(parents=True, exist_ok=True)
47
+ fd, tmp_name = tempfile.mkstemp(
48
+ dir=str(path.parent),
49
+ prefix=f".{path.name}.",
50
+ suffix=".tmp",
51
+ )
52
+ try:
53
+ with os.fdopen(fd, "w", encoding="utf-8", newline="\n") as handle:
54
+ handle.write(content)
55
+ os.replace(tmp_name, path)
56
+ except BaseException:
57
+ if os.path.exists(tmp_name):
58
+ os.unlink(tmp_name)
59
+ raise
60
+
61
+
62
+ @contextmanager
63
+ def checkpoint_context(
64
+ answers: Mapping[str, str] | None = None,
65
+ node_dir: Path | None = None,
66
+ ) -> Iterator[None]:
67
+ """Bind checkpoint replay answers and ``node_dir`` for a single op execution attempt."""
68
+ state = _CheckpointState(
69
+ answers=dict(answers) if answers is not None else {},
70
+ node_dir=node_dir,
71
+ call_index=0,
72
+ )
73
+ token = _CURRENT_STATE.set(state)
74
+ try:
75
+ yield
76
+ finally:
77
+ _CURRENT_STATE.reset(token)
78
+
79
+
80
+ def checkpoint(
81
+ question: str,
82
+ options: Sequence[str] | None = None,
83
+ allow_freeform: bool = False,
84
+ ) -> str:
85
+ """Ask a checkpoint question or replay its stored answer.
86
+
87
+ Each call within an attempt gets id ``cp_<n>`` where ``n`` starts at 0.
88
+ If ``checkpoint_answers`` contains ``cp_<n>``, returns that string answer.
89
+ Otherwise writes ``checkpoint.json`` (when running in a node directory) and
90
+ raises ``CheckpointInterrupt``.
91
+ """
92
+ state = _CURRENT_STATE.get()
93
+ if state is None:
94
+ idx = 0
95
+ answers: dict[str, str] = {}
96
+ node_dir: Path | None = None
97
+ else:
98
+ idx = state.call_index
99
+ state.call_index += 1
100
+ answers = state.answers
101
+ node_dir = state.node_dir
102
+
103
+ cp_id = f"cp_{idx}"
104
+ opt_list = list(options) if options is not None else None
105
+ manifest = CheckpointManifest(
106
+ checkpoint_id=cp_id,
107
+ question=question,
108
+ options=opt_list,
109
+ allow_freeform=allow_freeform,
110
+ )
111
+
112
+ if cp_id in answers:
113
+ return answers[cp_id]
114
+
115
+ if node_dir is not None:
116
+ _atomic_write_checkpoint(node_dir / "checkpoint.json", manifest.to_json())
117
+
118
+ raise CheckpointInterrupt(manifest)
119
+
120
+
121
+ __all__ = [
122
+ "CheckpointInterrupt",
123
+ "checkpoint",
124
+ "checkpoint_context",
125
+ ]