cjm-workflow-state 0.0.2__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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2022, fastai
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ include settings.ini
2
+ include LICENSE
3
+ include CONTRIBUTING.md
4
+ include README.md
5
+ recursive-exclude * __pycache__
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: cjm-workflow-state
3
+ Version: 0.0.2
4
+ Summary: SQLite-backed workflow state persistence and undo history for multi-step human-in-the-loop workflows.
5
+ Home-page: https://github.com/cj-mills/cjm-workflow-state
6
+ Author: Christian J. Mills
7
+ Author-email: 9126128+cj-mills@users.noreply.github.com
8
+ License: Apache-2.0
9
+ Keywords: nbdev jupyter notebook python
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Python: >=3.12
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: dev
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: keywords
26
+ Dynamic: license
27
+ Dynamic: license-file
28
+ Dynamic: provides-extra
29
+ Dynamic: requires-python
30
+ Dynamic: summary
31
+
32
+ # cjm-workflow-state
33
+
34
+
35
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
36
+
37
+ ## Install
38
+
39
+ ``` bash
40
+ pip install cjm_workflow_state
41
+ ```
42
+
43
+ ## Project Structure
44
+
45
+ nbs/
46
+ ├── history.ipynb # Generic undo history stack for workflow operations.
47
+ └── state_store.ipynb # SQLite-backed workflow state storage for persistence across restarts.
48
+
49
+ Total: 2 notebooks
50
+
51
+ ## Module Dependencies
52
+
53
+ ``` mermaid
54
+ graph LR
55
+ history[history<br/>History]
56
+ state_store[state_store<br/>State Store]
57
+ ```
58
+
59
+ No cross-module dependencies detected.
60
+
61
+ ## CLI Reference
62
+
63
+ No CLI commands found in this project.
64
+
65
+ ## Module Overview
66
+
67
+ Detailed documentation for each module in the project:
68
+
69
+ ### History (`history.ipynb`)
70
+
71
+ > Generic undo history stack for workflow operations.
72
+
73
+ #### Import
74
+
75
+ ``` python
76
+ from cjm_workflow_state.history import (
77
+ DEFAULT_MAX_HISTORY_DEPTH,
78
+ push_history,
79
+ pop_history
80
+ )
81
+ ```
82
+
83
+ #### Functions
84
+
85
+ ``` python
86
+ def push_history(
87
+ history: List[Dict[str, Any]], # Current history stack
88
+ snapshot: Dict[str, Any], # State snapshot to save
89
+ max_depth: int = DEFAULT_MAX_HISTORY_DEPTH, # Maximum history depth
90
+ ) -> List[Dict[str, Any]]: # Updated history stack
91
+ "Push a state snapshot onto the history stack, enforcing max depth."
92
+ ```
93
+
94
+ ``` python
95
+ def pop_history(
96
+ history: List[Dict[str, Any]], # Current history stack
97
+ ) -> Optional[Tuple[Dict[str, Any], List[Dict[str, Any]]]]: # (snapshot, updated_history) or None
98
+ "Pop the most recent snapshot from the history stack."
99
+ ```
100
+
101
+ #### Variables
102
+
103
+ ``` python
104
+ DEFAULT_MAX_HISTORY_DEPTH = 50
105
+ ```
106
+
107
+ ### State Store (`state_store.ipynb`)
108
+
109
+ > SQLite-backed workflow state storage for persistence across restarts.
110
+
111
+ #### Import
112
+
113
+ ``` python
114
+ from cjm_workflow_state.state_store import (
115
+ SQLiteWorkflowStateStore
116
+ )
117
+ ```
118
+
119
+ #### Classes
120
+
121
+ ``` python
122
+ class SQLiteWorkflowStateStore:
123
+ def __init__(
124
+ self,
125
+ db_path: Path # Path to SQLite database file
126
+ )
127
+ "SQLite-backed workflow state storage for persistence across restarts."
128
+
129
+ def __init__(
130
+ self,
131
+ db_path: Path # Path to SQLite database file
132
+ )
133
+ "Initialize the state store and create tables if needed."
134
+
135
+ def get_current_step(
136
+ self,
137
+ flow_id: str, # Workflow identifier
138
+ session_id: str # Session identifier string
139
+ ) -> Optional[str]: # Current step ID or None
140
+ "Get current step ID for a workflow."
141
+
142
+ def set_current_step(
143
+ self,
144
+ flow_id: str, # Workflow identifier
145
+ session_id: str, # Session identifier string
146
+ step_id: str # Step ID to set as current
147
+ ) -> None
148
+ "Set current step ID for a workflow."
149
+
150
+ def get_state(
151
+ self,
152
+ flow_id: str, # Workflow identifier
153
+ session_id: str # Session identifier string
154
+ ) -> Dict[str, Any]: # Workflow state dictionary
155
+ "Get all workflow state."
156
+
157
+ def update_state(
158
+ self,
159
+ flow_id: str, # Workflow identifier
160
+ session_id: str, # Session identifier string
161
+ updates: Dict[str, Any] # State updates to merge
162
+ ) -> None
163
+ "Update workflow state by merging new values."
164
+
165
+ def clear_state(
166
+ self,
167
+ flow_id: str, # Workflow identifier
168
+ session_id: str # Session identifier string
169
+ ) -> None
170
+ "Clear all workflow state."
171
+
172
+ def get_step_state(
173
+ self,
174
+ flow_id: str, # Workflow identifier
175
+ session_id: str, # Session identifier string
176
+ step_id: str # Step identifier
177
+ ) -> Dict[str, Any]: # Step-specific state dictionary
178
+ "Get state for a specific step."
179
+
180
+ def update_step_state(
181
+ self,
182
+ flow_id: str, # Workflow identifier
183
+ session_id: str, # Session identifier string
184
+ step_id: str, # Step identifier
185
+ updates: Dict[str, Any] # Step-specific state updates
186
+ ) -> None
187
+ "Update state for a specific step."
188
+
189
+ def clear_step_state(
190
+ self,
191
+ flow_id: str, # Workflow identifier
192
+ session_id: str, # Session identifier string
193
+ step_id: str # Step identifier
194
+ ) -> None
195
+ "Clear state for a specific step."
196
+ ```
@@ -0,0 +1,165 @@
1
+ # cjm-workflow-state
2
+
3
+
4
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
5
+
6
+ ## Install
7
+
8
+ ``` bash
9
+ pip install cjm_workflow_state
10
+ ```
11
+
12
+ ## Project Structure
13
+
14
+ nbs/
15
+ ├── history.ipynb # Generic undo history stack for workflow operations.
16
+ └── state_store.ipynb # SQLite-backed workflow state storage for persistence across restarts.
17
+
18
+ Total: 2 notebooks
19
+
20
+ ## Module Dependencies
21
+
22
+ ``` mermaid
23
+ graph LR
24
+ history[history<br/>History]
25
+ state_store[state_store<br/>State Store]
26
+ ```
27
+
28
+ No cross-module dependencies detected.
29
+
30
+ ## CLI Reference
31
+
32
+ No CLI commands found in this project.
33
+
34
+ ## Module Overview
35
+
36
+ Detailed documentation for each module in the project:
37
+
38
+ ### History (`history.ipynb`)
39
+
40
+ > Generic undo history stack for workflow operations.
41
+
42
+ #### Import
43
+
44
+ ``` python
45
+ from cjm_workflow_state.history import (
46
+ DEFAULT_MAX_HISTORY_DEPTH,
47
+ push_history,
48
+ pop_history
49
+ )
50
+ ```
51
+
52
+ #### Functions
53
+
54
+ ``` python
55
+ def push_history(
56
+ history: List[Dict[str, Any]], # Current history stack
57
+ snapshot: Dict[str, Any], # State snapshot to save
58
+ max_depth: int = DEFAULT_MAX_HISTORY_DEPTH, # Maximum history depth
59
+ ) -> List[Dict[str, Any]]: # Updated history stack
60
+ "Push a state snapshot onto the history stack, enforcing max depth."
61
+ ```
62
+
63
+ ``` python
64
+ def pop_history(
65
+ history: List[Dict[str, Any]], # Current history stack
66
+ ) -> Optional[Tuple[Dict[str, Any], List[Dict[str, Any]]]]: # (snapshot, updated_history) or None
67
+ "Pop the most recent snapshot from the history stack."
68
+ ```
69
+
70
+ #### Variables
71
+
72
+ ``` python
73
+ DEFAULT_MAX_HISTORY_DEPTH = 50
74
+ ```
75
+
76
+ ### State Store (`state_store.ipynb`)
77
+
78
+ > SQLite-backed workflow state storage for persistence across restarts.
79
+
80
+ #### Import
81
+
82
+ ``` python
83
+ from cjm_workflow_state.state_store import (
84
+ SQLiteWorkflowStateStore
85
+ )
86
+ ```
87
+
88
+ #### Classes
89
+
90
+ ``` python
91
+ class SQLiteWorkflowStateStore:
92
+ def __init__(
93
+ self,
94
+ db_path: Path # Path to SQLite database file
95
+ )
96
+ "SQLite-backed workflow state storage for persistence across restarts."
97
+
98
+ def __init__(
99
+ self,
100
+ db_path: Path # Path to SQLite database file
101
+ )
102
+ "Initialize the state store and create tables if needed."
103
+
104
+ def get_current_step(
105
+ self,
106
+ flow_id: str, # Workflow identifier
107
+ session_id: str # Session identifier string
108
+ ) -> Optional[str]: # Current step ID or None
109
+ "Get current step ID for a workflow."
110
+
111
+ def set_current_step(
112
+ self,
113
+ flow_id: str, # Workflow identifier
114
+ session_id: str, # Session identifier string
115
+ step_id: str # Step ID to set as current
116
+ ) -> None
117
+ "Set current step ID for a workflow."
118
+
119
+ def get_state(
120
+ self,
121
+ flow_id: str, # Workflow identifier
122
+ session_id: str # Session identifier string
123
+ ) -> Dict[str, Any]: # Workflow state dictionary
124
+ "Get all workflow state."
125
+
126
+ def update_state(
127
+ self,
128
+ flow_id: str, # Workflow identifier
129
+ session_id: str, # Session identifier string
130
+ updates: Dict[str, Any] # State updates to merge
131
+ ) -> None
132
+ "Update workflow state by merging new values."
133
+
134
+ def clear_state(
135
+ self,
136
+ flow_id: str, # Workflow identifier
137
+ session_id: str # Session identifier string
138
+ ) -> None
139
+ "Clear all workflow state."
140
+
141
+ def get_step_state(
142
+ self,
143
+ flow_id: str, # Workflow identifier
144
+ session_id: str, # Session identifier string
145
+ step_id: str # Step identifier
146
+ ) -> Dict[str, Any]: # Step-specific state dictionary
147
+ "Get state for a specific step."
148
+
149
+ def update_step_state(
150
+ self,
151
+ flow_id: str, # Workflow identifier
152
+ session_id: str, # Session identifier string
153
+ step_id: str, # Step identifier
154
+ updates: Dict[str, Any] # Step-specific state updates
155
+ ) -> None
156
+ "Update state for a specific step."
157
+
158
+ def clear_step_state(
159
+ self,
160
+ flow_id: str, # Workflow identifier
161
+ session_id: str, # Session identifier string
162
+ step_id: str # Step identifier
163
+ ) -> None
164
+ "Clear state for a specific step."
165
+ ```
@@ -0,0 +1 @@
1
+ __version__ = "0.0.2"
@@ -0,0 +1,37 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'settings': { 'branch': 'main',
4
+ 'doc_baseurl': '/cjm-workflow-state',
5
+ 'doc_host': 'https://cj-mills.github.io',
6
+ 'git_url': 'https://github.com/cj-mills/cjm-workflow-state',
7
+ 'lib_path': 'cjm_workflow_state'},
8
+ 'syms': { 'cjm_workflow_state.history': { 'cjm_workflow_state.history.pop_history': ( 'history.html#pop_history',
9
+ 'cjm_workflow_state/history.py'),
10
+ 'cjm_workflow_state.history.push_history': ( 'history.html#push_history',
11
+ 'cjm_workflow_state/history.py')},
12
+ 'cjm_workflow_state.state_store': { 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore': ( 'state_store.html#sqliteworkflowstatestore',
13
+ 'cjm_workflow_state/state_store.py'),
14
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.__init__': ( 'state_store.html#sqliteworkflowstatestore.__init__',
15
+ 'cjm_workflow_state/state_store.py'),
16
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore._get_connection': ( 'state_store.html#sqliteworkflowstatestore._get_connection',
17
+ 'cjm_workflow_state/state_store.py'),
18
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore._init_db': ( 'state_store.html#sqliteworkflowstatestore._init_db',
19
+ 'cjm_workflow_state/state_store.py'),
20
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore._make_key': ( 'state_store.html#sqliteworkflowstatestore._make_key',
21
+ 'cjm_workflow_state/state_store.py'),
22
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.clear_state': ( 'state_store.html#sqliteworkflowstatestore.clear_state',
23
+ 'cjm_workflow_state/state_store.py'),
24
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.clear_step_state': ( 'state_store.html#sqliteworkflowstatestore.clear_step_state',
25
+ 'cjm_workflow_state/state_store.py'),
26
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.get_current_step': ( 'state_store.html#sqliteworkflowstatestore.get_current_step',
27
+ 'cjm_workflow_state/state_store.py'),
28
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.get_state': ( 'state_store.html#sqliteworkflowstatestore.get_state',
29
+ 'cjm_workflow_state/state_store.py'),
30
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.get_step_state': ( 'state_store.html#sqliteworkflowstatestore.get_step_state',
31
+ 'cjm_workflow_state/state_store.py'),
32
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.set_current_step': ( 'state_store.html#sqliteworkflowstatestore.set_current_step',
33
+ 'cjm_workflow_state/state_store.py'),
34
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.update_state': ( 'state_store.html#sqliteworkflowstatestore.update_state',
35
+ 'cjm_workflow_state/state_store.py'),
36
+ 'cjm_workflow_state.state_store.SQLiteWorkflowStateStore.update_step_state': ( 'state_store.html#sqliteworkflowstatestore.update_step_state',
37
+ 'cjm_workflow_state/state_store.py')}}}
@@ -0,0 +1,36 @@
1
+ """Generic undo history stack for workflow operations."""
2
+
3
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/history.ipynb.
4
+
5
+ # %% auto #0
6
+ __all__ = ['DEFAULT_MAX_HISTORY_DEPTH', 'push_history', 'pop_history']
7
+
8
+ # %% ../nbs/history.ipynb #hist-imports
9
+ from typing import Optional, Tuple, List, Dict, Any
10
+
11
+ # %% ../nbs/history.ipynb #hist-const
12
+ DEFAULT_MAX_HISTORY_DEPTH = 50
13
+
14
+ # %% ../nbs/history.ipynb #hist-push
15
+ def push_history(
16
+ history: List[Dict[str, Any]], # Current history stack
17
+ snapshot: Dict[str, Any], # State snapshot to save
18
+ max_depth: int = DEFAULT_MAX_HISTORY_DEPTH, # Maximum history depth
19
+ ) -> List[Dict[str, Any]]: # Updated history stack
20
+ """Push a state snapshot onto the history stack, enforcing max depth."""
21
+ new_history = list(history)
22
+ new_history.append(snapshot)
23
+ if len(new_history) > max_depth:
24
+ new_history = new_history[-max_depth:]
25
+ return new_history
26
+
27
+ # %% ../nbs/history.ipynb #hist-pop
28
+ def pop_history(
29
+ history: List[Dict[str, Any]], # Current history stack
30
+ ) -> Optional[Tuple[Dict[str, Any], List[Dict[str, Any]]]]: # (snapshot, updated_history) or None
31
+ """Pop the most recent snapshot from the history stack."""
32
+ if not history:
33
+ return None
34
+ new_history = list(history)
35
+ snapshot = new_history.pop()
36
+ return snapshot, new_history
@@ -0,0 +1,185 @@
1
+ """SQLite-backed workflow state storage for persistence across restarts."""
2
+
3
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/state_store.ipynb.
4
+
5
+ # %% auto #0
6
+ __all__ = ['SQLiteWorkflowStateStore']
7
+
8
+ # %% ../nbs/state_store.ipynb #ss-imports
9
+ import json
10
+ import sqlite3
11
+ from pathlib import Path
12
+ from typing import Dict, Any, Optional
13
+ from contextlib import contextmanager
14
+
15
+ # %% ../nbs/state_store.ipynb #ss-class
16
+ class SQLiteWorkflowStateStore:
17
+ """SQLite-backed workflow state storage for persistence across restarts."""
18
+
19
+ def __init__(
20
+ self,
21
+ db_path: Path # Path to SQLite database file
22
+ ):
23
+ """Initialize the state store and create tables if needed."""
24
+ self.db_path = Path(db_path)
25
+ self.db_path.parent.mkdir(parents=True, exist_ok=True)
26
+ self._init_db()
27
+
28
+ @contextmanager
29
+ def _get_connection(self): # Context manager yielding SQLite connection
30
+ """Get a database connection with proper cleanup."""
31
+ conn = sqlite3.connect(self.db_path)
32
+ conn.row_factory = sqlite3.Row
33
+ try:
34
+ yield conn
35
+ conn.commit()
36
+ finally:
37
+ conn.close()
38
+
39
+ def _init_db(self) -> None:
40
+ """Initialize database schema."""
41
+ with self._get_connection() as conn:
42
+ conn.execute("""
43
+ CREATE TABLE IF NOT EXISTS workflow_state (
44
+ flow_session_key TEXT PRIMARY KEY,
45
+ current_step TEXT,
46
+ state_json TEXT DEFAULT '{}',
47
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
48
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
49
+ )
50
+ """)
51
+ conn.execute("""
52
+ CREATE INDEX IF NOT EXISTS idx_workflow_state_updated
53
+ ON workflow_state(updated_at)
54
+ """)
55
+
56
+ def _make_key(
57
+ self,
58
+ flow_id: str, # Workflow identifier
59
+ session_id: str # Session identifier string
60
+ ) -> str: # Composite key for storage
61
+ """Create composite key from flow_id and session_id."""
62
+ return f"{flow_id}:{session_id}"
63
+
64
+ def get_current_step(
65
+ self,
66
+ flow_id: str, # Workflow identifier
67
+ session_id: str # Session identifier string
68
+ ) -> Optional[str]: # Current step ID or None
69
+ """Get current step ID for a workflow."""
70
+ key = self._make_key(flow_id, session_id)
71
+ with self._get_connection() as conn:
72
+ row = conn.execute(
73
+ "SELECT current_step FROM workflow_state WHERE flow_session_key = ?",
74
+ (key,)
75
+ ).fetchone()
76
+ return row["current_step"] if row else None
77
+
78
+ def set_current_step(
79
+ self,
80
+ flow_id: str, # Workflow identifier
81
+ session_id: str, # Session identifier string
82
+ step_id: str # Step ID to set as current
83
+ ) -> None:
84
+ """Set current step ID for a workflow."""
85
+ key = self._make_key(flow_id, session_id)
86
+ with self._get_connection() as conn:
87
+ conn.execute("""
88
+ INSERT INTO workflow_state (flow_session_key, current_step)
89
+ VALUES (?, ?)
90
+ ON CONFLICT(flow_session_key) DO UPDATE SET
91
+ current_step = excluded.current_step,
92
+ updated_at = CURRENT_TIMESTAMP
93
+ """, (key, step_id))
94
+
95
+ def get_state(
96
+ self,
97
+ flow_id: str, # Workflow identifier
98
+ session_id: str # Session identifier string
99
+ ) -> Dict[str, Any]: # Workflow state dictionary
100
+ """Get all workflow state."""
101
+ key = self._make_key(flow_id, session_id)
102
+ with self._get_connection() as conn:
103
+ row = conn.execute(
104
+ "SELECT state_json FROM workflow_state WHERE flow_session_key = ?",
105
+ (key,)
106
+ ).fetchone()
107
+ if row and row["state_json"]:
108
+ return json.loads(row["state_json"])
109
+ return {}
110
+
111
+ def update_state(
112
+ self,
113
+ flow_id: str, # Workflow identifier
114
+ session_id: str, # Session identifier string
115
+ updates: Dict[str, Any] # State updates to merge
116
+ ) -> None:
117
+ """Update workflow state by merging new values."""
118
+ key = self._make_key(flow_id, session_id)
119
+ current_state = self.get_state(flow_id, session_id)
120
+ current_state.update(updates)
121
+ state_json = json.dumps(current_state)
122
+ with self._get_connection() as conn:
123
+ conn.execute("""
124
+ INSERT INTO workflow_state (flow_session_key, state_json)
125
+ VALUES (?, ?)
126
+ ON CONFLICT(flow_session_key) DO UPDATE SET
127
+ state_json = excluded.state_json,
128
+ updated_at = CURRENT_TIMESTAMP
129
+ """, (key, state_json))
130
+
131
+ def clear_state(
132
+ self,
133
+ flow_id: str, # Workflow identifier
134
+ session_id: str # Session identifier string
135
+ ) -> None:
136
+ """Clear all workflow state."""
137
+ key = self._make_key(flow_id, session_id)
138
+ with self._get_connection() as conn:
139
+ conn.execute(
140
+ "DELETE FROM workflow_state WHERE flow_session_key = ?",
141
+ (key,)
142
+ )
143
+
144
+ def get_step_state(
145
+ self,
146
+ flow_id: str, # Workflow identifier
147
+ session_id: str, # Session identifier string
148
+ step_id: str # Step identifier
149
+ ) -> Dict[str, Any]: # Step-specific state dictionary
150
+ """Get state for a specific step."""
151
+ state = self.get_state(flow_id, session_id)
152
+ step_key = f"_step_{step_id}"
153
+ return state.get(step_key, {})
154
+
155
+ def update_step_state(
156
+ self,
157
+ flow_id: str, # Workflow identifier
158
+ session_id: str, # Session identifier string
159
+ step_id: str, # Step identifier
160
+ updates: Dict[str, Any] # Step-specific state updates
161
+ ) -> None:
162
+ """Update state for a specific step."""
163
+ step_key = f"_step_{step_id}"
164
+ current_step_state = self.get_step_state(flow_id, session_id, step_id)
165
+ current_step_state.update(updates)
166
+ self.update_state(flow_id, session_id, {step_key: current_step_state})
167
+
168
+ def clear_step_state(
169
+ self,
170
+ flow_id: str, # Workflow identifier
171
+ session_id: str, # Session identifier string
172
+ step_id: str # Step identifier
173
+ ) -> None:
174
+ """Clear state for a specific step."""
175
+ step_key = f"_step_{step_id}"
176
+ state = self.get_state(flow_id, session_id)
177
+ if step_key in state:
178
+ del state[step_key]
179
+ key = self._make_key(flow_id, session_id)
180
+ state_json = json.dumps(state)
181
+ with self._get_connection() as conn:
182
+ conn.execute("""
183
+ UPDATE workflow_state SET state_json = ?, updated_at = CURRENT_TIMESTAMP
184
+ WHERE flow_session_key = ?
185
+ """, (state_json, key))
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: cjm-workflow-state
3
+ Version: 0.0.2
4
+ Summary: SQLite-backed workflow state persistence and undo history for multi-step human-in-the-loop workflows.
5
+ Home-page: https://github.com/cj-mills/cjm-workflow-state
6
+ Author: Christian J. Mills
7
+ Author-email: 9126128+cj-mills@users.noreply.github.com
8
+ License: Apache-2.0
9
+ Keywords: nbdev jupyter notebook python
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Python: >=3.12
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: dev
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: keywords
26
+ Dynamic: license
27
+ Dynamic: license-file
28
+ Dynamic: provides-extra
29
+ Dynamic: requires-python
30
+ Dynamic: summary
31
+
32
+ # cjm-workflow-state
33
+
34
+
35
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
36
+
37
+ ## Install
38
+
39
+ ``` bash
40
+ pip install cjm_workflow_state
41
+ ```
42
+
43
+ ## Project Structure
44
+
45
+ nbs/
46
+ ├── history.ipynb # Generic undo history stack for workflow operations.
47
+ └── state_store.ipynb # SQLite-backed workflow state storage for persistence across restarts.
48
+
49
+ Total: 2 notebooks
50
+
51
+ ## Module Dependencies
52
+
53
+ ``` mermaid
54
+ graph LR
55
+ history[history<br/>History]
56
+ state_store[state_store<br/>State Store]
57
+ ```
58
+
59
+ No cross-module dependencies detected.
60
+
61
+ ## CLI Reference
62
+
63
+ No CLI commands found in this project.
64
+
65
+ ## Module Overview
66
+
67
+ Detailed documentation for each module in the project:
68
+
69
+ ### History (`history.ipynb`)
70
+
71
+ > Generic undo history stack for workflow operations.
72
+
73
+ #### Import
74
+
75
+ ``` python
76
+ from cjm_workflow_state.history import (
77
+ DEFAULT_MAX_HISTORY_DEPTH,
78
+ push_history,
79
+ pop_history
80
+ )
81
+ ```
82
+
83
+ #### Functions
84
+
85
+ ``` python
86
+ def push_history(
87
+ history: List[Dict[str, Any]], # Current history stack
88
+ snapshot: Dict[str, Any], # State snapshot to save
89
+ max_depth: int = DEFAULT_MAX_HISTORY_DEPTH, # Maximum history depth
90
+ ) -> List[Dict[str, Any]]: # Updated history stack
91
+ "Push a state snapshot onto the history stack, enforcing max depth."
92
+ ```
93
+
94
+ ``` python
95
+ def pop_history(
96
+ history: List[Dict[str, Any]], # Current history stack
97
+ ) -> Optional[Tuple[Dict[str, Any], List[Dict[str, Any]]]]: # (snapshot, updated_history) or None
98
+ "Pop the most recent snapshot from the history stack."
99
+ ```
100
+
101
+ #### Variables
102
+
103
+ ``` python
104
+ DEFAULT_MAX_HISTORY_DEPTH = 50
105
+ ```
106
+
107
+ ### State Store (`state_store.ipynb`)
108
+
109
+ > SQLite-backed workflow state storage for persistence across restarts.
110
+
111
+ #### Import
112
+
113
+ ``` python
114
+ from cjm_workflow_state.state_store import (
115
+ SQLiteWorkflowStateStore
116
+ )
117
+ ```
118
+
119
+ #### Classes
120
+
121
+ ``` python
122
+ class SQLiteWorkflowStateStore:
123
+ def __init__(
124
+ self,
125
+ db_path: Path # Path to SQLite database file
126
+ )
127
+ "SQLite-backed workflow state storage for persistence across restarts."
128
+
129
+ def __init__(
130
+ self,
131
+ db_path: Path # Path to SQLite database file
132
+ )
133
+ "Initialize the state store and create tables if needed."
134
+
135
+ def get_current_step(
136
+ self,
137
+ flow_id: str, # Workflow identifier
138
+ session_id: str # Session identifier string
139
+ ) -> Optional[str]: # Current step ID or None
140
+ "Get current step ID for a workflow."
141
+
142
+ def set_current_step(
143
+ self,
144
+ flow_id: str, # Workflow identifier
145
+ session_id: str, # Session identifier string
146
+ step_id: str # Step ID to set as current
147
+ ) -> None
148
+ "Set current step ID for a workflow."
149
+
150
+ def get_state(
151
+ self,
152
+ flow_id: str, # Workflow identifier
153
+ session_id: str # Session identifier string
154
+ ) -> Dict[str, Any]: # Workflow state dictionary
155
+ "Get all workflow state."
156
+
157
+ def update_state(
158
+ self,
159
+ flow_id: str, # Workflow identifier
160
+ session_id: str, # Session identifier string
161
+ updates: Dict[str, Any] # State updates to merge
162
+ ) -> None
163
+ "Update workflow state by merging new values."
164
+
165
+ def clear_state(
166
+ self,
167
+ flow_id: str, # Workflow identifier
168
+ session_id: str # Session identifier string
169
+ ) -> None
170
+ "Clear all workflow state."
171
+
172
+ def get_step_state(
173
+ self,
174
+ flow_id: str, # Workflow identifier
175
+ session_id: str, # Session identifier string
176
+ step_id: str # Step identifier
177
+ ) -> Dict[str, Any]: # Step-specific state dictionary
178
+ "Get state for a specific step."
179
+
180
+ def update_step_state(
181
+ self,
182
+ flow_id: str, # Workflow identifier
183
+ session_id: str, # Session identifier string
184
+ step_id: str, # Step identifier
185
+ updates: Dict[str, Any] # Step-specific state updates
186
+ ) -> None
187
+ "Update state for a specific step."
188
+
189
+ def clear_step_state(
190
+ self,
191
+ flow_id: str, # Workflow identifier
192
+ session_id: str, # Session identifier string
193
+ step_id: str # Step identifier
194
+ ) -> None
195
+ "Clear state for a specific step."
196
+ ```
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ settings.ini
6
+ setup.py
7
+ cjm_workflow_state/__init__.py
8
+ cjm_workflow_state/_modidx.py
9
+ cjm_workflow_state/history.py
10
+ cjm_workflow_state/state_store.py
11
+ cjm_workflow_state.egg-info/PKG-INFO
12
+ cjm_workflow_state.egg-info/SOURCES.txt
13
+ cjm_workflow_state.egg-info/dependency_links.txt
14
+ cjm_workflow_state.egg-info/entry_points.txt
15
+ cjm_workflow_state.egg-info/not-zip-safe
16
+ cjm_workflow_state.egg-info/requires.txt
17
+ cjm_workflow_state.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [nbdev]
2
+ cjm_workflow_state = cjm_workflow_state._modidx:d
@@ -0,0 +1 @@
1
+ cjm_workflow_state
@@ -0,0 +1,11 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name="cjm-workflow-state"
7
+ requires-python=">=3.12"
8
+ dynamic = [ "keywords", "description", "version", "dependencies", "optional-dependencies", "readme", "license", "authors", "classifiers", "entry-points", "scripts", "urls"]
9
+
10
+ [tool.uv]
11
+ cache-keys = [{ file = "pyproject.toml" }, { file = "settings.ini" }, { file = "setup.py" }]
@@ -0,0 +1,37 @@
1
+ [DEFAULT]
2
+ repo = cjm-workflow-state
3
+ lib_name = cjm-workflow-state
4
+ version = 0.0.2
5
+ min_python = 3.12
6
+ license = apache2
7
+ black_formatting = False
8
+ doc_path = _docs
9
+ lib_path = cjm_workflow_state
10
+ nbs_path = nbs
11
+ recursive = True
12
+ tst_flags = notest
13
+ put_version_in_init = True
14
+ update_pyproject = True
15
+ branch = main
16
+ custom_sidebar = False
17
+ doc_host = https://cj-mills.github.io
18
+ doc_baseurl = /cjm-workflow-state
19
+ git_url = https://github.com/cj-mills/cjm-workflow-state
20
+ title = cjm-workflow-state
21
+ audience = Developers
22
+ author = Christian J. Mills
23
+ author_email = 9126128+cj-mills@users.noreply.github.com
24
+ copyright = 2026 onwards, Christian J. Mills
25
+ description = SQLite-backed workflow state persistence and undo history for multi-step human-in-the-loop workflows.
26
+ keywords = nbdev jupyter notebook python
27
+ language = English
28
+ status = 3
29
+ user = cj-mills
30
+ readme_nb = index.ipynb
31
+ allowed_metadata_keys =
32
+ allowed_cell_metadata_keys =
33
+ jupyter_hooks = False
34
+ clean_ids = True
35
+ clear_all = False
36
+ skip_procs =
37
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,63 @@
1
+ from pkg_resources import parse_version
2
+ from configparser import ConfigParser
3
+ import setuptools, shlex
4
+ assert parse_version(setuptools.__version__)>=parse_version('36.2')
5
+
6
+ # note: all settings are in settings.ini; edit there, not here
7
+ config = ConfigParser(delimiters=['='])
8
+ config.read('settings.ini', encoding='utf-8')
9
+ cfg = config['DEFAULT']
10
+
11
+ cfg_keys = 'version description keywords author author_email'.split()
12
+ expected = cfg_keys + "lib_name user branch license status min_python audience language".split()
13
+ for o in expected: assert o in cfg, "missing expected setting: {}".format(o)
14
+ setup_cfg = {o:cfg[o] for o in cfg_keys}
15
+
16
+ licenses = {
17
+ 'apache2': 'Apache-2.0',
18
+ 'mit': 'MIT',
19
+ 'gpl2': 'GPL-2.0-only',
20
+ 'gpl3': 'GPL-3.0-or-later',
21
+ 'bsd3': 'BSD-3-Clause',
22
+ }
23
+ statuses = [ '1 - Planning', '2 - Pre-Alpha', '3 - Alpha',
24
+ '4 - Beta', '5 - Production/Stable', '6 - Mature', '7 - Inactive' ]
25
+ py_versions = '3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13'.split()
26
+
27
+ requirements = shlex.split(cfg.get('requirements', ''))
28
+ if cfg.get('pip_requirements'): requirements += shlex.split(cfg.get('pip_requirements', ''))
29
+ min_python = cfg['min_python']
30
+ dev_requirements = (cfg.get('dev_requirements') or '').split()
31
+
32
+ package_data = dict()
33
+ pkg_data = cfg.get('package_data', None)
34
+ if pkg_data:
35
+ package_data[cfg['lib_name']] = pkg_data.split() # split as multiple files might be listed
36
+ # Add package data to setup_cfg for setuptools.setup(..., **setup_cfg)
37
+ setup_cfg['package_data'] = package_data
38
+
39
+ setuptools.setup(
40
+ name = cfg['lib_name'],
41
+ license = licenses.get(cfg['license'].lower(), cfg['license']),
42
+ classifiers = [
43
+ 'Development Status :: ' + statuses[int(cfg['status'])],
44
+ 'Intended Audience :: ' + cfg['audience'].title(),
45
+ 'Natural Language :: ' + cfg['language'].title(),
46
+ ] + ['Programming Language :: Python :: '+o for o in py_versions[py_versions.index(min_python):]],
47
+ url = cfg['git_url'],
48
+ packages = setuptools.find_packages(),
49
+ include_package_data = True,
50
+ install_requires = requirements,
51
+ extras_require={ 'dev': dev_requirements },
52
+ dependency_links = cfg.get('dep_links','').split(),
53
+ python_requires = '>=' + cfg['min_python'],
54
+ long_description = open('README.md', encoding='utf-8').read(),
55
+ long_description_content_type = 'text/markdown',
56
+ zip_safe = False,
57
+ entry_points = {
58
+ 'console_scripts': cfg.get('console_scripts','').split(),
59
+ 'nbdev': [f'{cfg.get("lib_path")}={cfg.get("lib_path")}._modidx:d']
60
+ },
61
+ **setup_cfg)
62
+
63
+