orca-runtime-python 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.
@@ -0,0 +1,246 @@
1
+ Metadata-Version: 2.4
2
+ Name: orca-runtime-python
3
+ Version: 0.1.0
4
+ Summary: Python async runtime for Orca state machines
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/orca-lang/orca-lang
7
+ Project-URL: Repository, https://github.com/orca-lang/orca-lang-python
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest>=7.0; extra == "dev"
20
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
21
+ Requires-Dist: black>=23.0; extra == "dev"
22
+ Requires-Dist: mypy>=1.0; extra == "dev"
23
+ Requires-Dist: ruff>=0.1; extra == "dev"
24
+
25
+ # Orca Runtime Python
26
+
27
+ A first-class Python async runtime for [Orca](https://github.com/orca-lang/orca-lang) state machines.
28
+
29
+ ## Overview
30
+
31
+ Orca is a state machine language designed for LLM code generation. This package provides a Python runtime that executes Orca machine definitions with:
32
+
33
+ - **Async-first** - Native `async/await` throughout
34
+ - **Event bus integration** - Decoupled pub/sub for agentic systems
35
+ - **Effect system** - Typed async operations with handler registration
36
+ - **Hierarchical states** - Nested/compound state support
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install orca-runtime-python
42
+ ```
43
+
44
+ ## Quick Start
45
+
46
+ ```python
47
+ import asyncio
48
+ from orca_runtime_python import (
49
+ parse_orca,
50
+ OrcaMachine,
51
+ get_event_bus,
52
+ )
53
+
54
+ # Define an Orca machine
55
+ orca_source = """
56
+ machine OrderProcessor
57
+
58
+ context {
59
+ order_id: ""
60
+ status: "pending"
61
+ }
62
+
63
+ state pending [initial] "Order received"
64
+ state fulfilled [final] "Order complete"
65
+
66
+ transitions {
67
+ pending + ORDER_PLACED -> pending
68
+ pending + ORDER_FULFILLED -> fulfilled
69
+ }
70
+ """
71
+
72
+ async def main():
73
+ # Parse and create machine
74
+ machine_def = parse_orca(orca_source)
75
+ machine = OrcaMachine(machine_def)
76
+
77
+ # Register effect handlers
78
+ bus = get_event_bus()
79
+ bus.register_effect_handler("Effect", lambda e: EffectResult(
80
+ status="success", data=e.payload
81
+ ))
82
+
83
+ # Start and run
84
+ await machine.start()
85
+ print(f"Initial state: {machine.state}")
86
+
87
+ await machine.send("ORDER_FULFILLED")
88
+ print(f"After event: {machine.state}")
89
+
90
+ await machine.stop()
91
+
92
+ asyncio.run(main())
93
+ ```
94
+
95
+ ## Architecture
96
+
97
+ ```
98
+ ┌─────────────────────────────────────────────────────────────────┐
99
+ │ OrcaMachine │
100
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
101
+ │ │ State Store │ │ Transition │ │ Effect Executor │ │
102
+ │ │ (current) │ │ Evaluator │ │ (async handlers) │ │
103
+ │ └──────────────┘ └──────────────┘ └──────────────────────┘ │
104
+ │ │ │ │ │
105
+ │ └────────────────┼──────────────────────┘ │
106
+ │ ▼ │
107
+ │ ┌──────────────────┐ │
108
+ │ │ EventBus │ (pub/sub) │
109
+ │ └──────────────────┘ │
110
+ └─────────────────────────────────────────────────────────────────┘
111
+ ```
112
+
113
+ ## Core Components
114
+
115
+ ### OrcaMachine
116
+
117
+ The main runtime class that executes state machines:
118
+
119
+ ```python
120
+ machine = OrcaMachine(
121
+ definition=machine_def,
122
+ event_bus=get_event_bus(),
123
+ context={"order_id": "123"},
124
+ on_transition=lambda old, new: print(f"{old} -> {new}"),
125
+ )
126
+ ```
127
+
128
+ ### EventBus
129
+
130
+ Async event bus with pub/sub and request/response:
131
+
132
+ ```python
133
+ bus = get_event_bus()
134
+
135
+ # Subscribe to events
136
+ bus.subscribe(EventType.STATE_CHANGED, handler)
137
+
138
+ # Publish events
139
+ await bus.publish(Event(
140
+ type=EventType.STATE_CHANGED,
141
+ source="OrderProcessor",
142
+ payload={"from": "pending", "to": "fulfilled"},
143
+ ))
144
+
145
+ # Request/response pattern
146
+ response = await bus.request_response(
147
+ request_type=EventType.SCHEDULING_QUERY,
148
+ request_payload={"type": "availability"},
149
+ response_type=EventType.SCHEDULING_QUERY_RESPONSE,
150
+ )
151
+ ```
152
+
153
+ ### Effect Handlers
154
+
155
+ Register async handlers for effect types:
156
+
157
+ ```python
158
+ async def handle_narrative(effect: Effect) -> EffectResult:
159
+ narrative = await generate_narrative(effect.payload)
160
+ return EffectResult(status="success", data={"narrative": narrative})
161
+
162
+ bus.register_effect_handler("NarrativeRequest", handle_narrative)
163
+ ```
164
+
165
+ ## Orca DSL Syntax
166
+
167
+ ```orca
168
+ machine GameEngine
169
+
170
+ context {
171
+ health: int = 100
172
+ inventory: string[]
173
+ }
174
+
175
+ events {
176
+ start_game
177
+ attack
178
+ heal
179
+ }
180
+
181
+ state idle [initial] {
182
+ description: "Waiting for player input"
183
+ }
184
+
185
+ state combat {
186
+ description: "In combat"
187
+
188
+ state fighting [initial] {
189
+ description: "Actively fighting"
190
+ }
191
+
192
+ state defending {
193
+ description: "Blocking attacks"
194
+ }
195
+ }
196
+
197
+ state game_over [final] {
198
+ description: "Game ended"
199
+ }
200
+
201
+ guards {
202
+ can_heal: ctx.health < 100
203
+ }
204
+
205
+ transitions {
206
+ idle + start_game -> combat : start_combat
207
+ combat + attack -> combat : resolve_attack
208
+ combat + heal [can_heal] -> combat : apply_heal
209
+ combat + attack [health <= 0] -> game_over : end_game
210
+ }
211
+
212
+ actions {
213
+ start_combat: (ctx: Context) -> Context
214
+ resolve_attack: (ctx: Context) -> Context + Effect<DamageRequest>
215
+ apply_heal: (ctx: Context) -> Context
216
+ end_game: (ctx: Context) -> Context
217
+ }
218
+ ```
219
+
220
+ ## Hierarchy
221
+
222
+ ```
223
+ orca-runtime-python/
224
+ ├── orca_runtime_python/ # Main package
225
+ │ ├── __init__.py
226
+ │ ├── types.py # Core types
227
+ │ ├── parser.py # DSL parser
228
+ │ ├── machine.py # OrcaMachine runtime
229
+ │ ├── bus.py # EventBus
230
+ │ └── effects.py # Effect system
231
+ ├── pyproject.toml
232
+ └── README.md
233
+ ```
234
+
235
+ ## Relationship to Other Implementations
236
+
237
+ | Package | Language | Purpose |
238
+ |---------|----------|---------|
239
+ | `orca` (npm) | TypeScript/JS | Core implementation (parser, verifier, compiler) |
240
+ | `orca-runtime-python` | Python | Python async runtime |
241
+
242
+ The Orca language is defined once and implemented across platforms. The Python runtime executes machines compiled from Orca DSL.
243
+
244
+ ## License
245
+
246
+ Apache 2.0
@@ -0,0 +1,222 @@
1
+ # Orca Runtime Python
2
+
3
+ A first-class Python async runtime for [Orca](https://github.com/orca-lang/orca-lang) state machines.
4
+
5
+ ## Overview
6
+
7
+ Orca is a state machine language designed for LLM code generation. This package provides a Python runtime that executes Orca machine definitions with:
8
+
9
+ - **Async-first** - Native `async/await` throughout
10
+ - **Event bus integration** - Decoupled pub/sub for agentic systems
11
+ - **Effect system** - Typed async operations with handler registration
12
+ - **Hierarchical states** - Nested/compound state support
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install orca-runtime-python
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ```python
23
+ import asyncio
24
+ from orca_runtime_python import (
25
+ parse_orca,
26
+ OrcaMachine,
27
+ get_event_bus,
28
+ )
29
+
30
+ # Define an Orca machine
31
+ orca_source = """
32
+ machine OrderProcessor
33
+
34
+ context {
35
+ order_id: ""
36
+ status: "pending"
37
+ }
38
+
39
+ state pending [initial] "Order received"
40
+ state fulfilled [final] "Order complete"
41
+
42
+ transitions {
43
+ pending + ORDER_PLACED -> pending
44
+ pending + ORDER_FULFILLED -> fulfilled
45
+ }
46
+ """
47
+
48
+ async def main():
49
+ # Parse and create machine
50
+ machine_def = parse_orca(orca_source)
51
+ machine = OrcaMachine(machine_def)
52
+
53
+ # Register effect handlers
54
+ bus = get_event_bus()
55
+ bus.register_effect_handler("Effect", lambda e: EffectResult(
56
+ status="success", data=e.payload
57
+ ))
58
+
59
+ # Start and run
60
+ await machine.start()
61
+ print(f"Initial state: {machine.state}")
62
+
63
+ await machine.send("ORDER_FULFILLED")
64
+ print(f"After event: {machine.state}")
65
+
66
+ await machine.stop()
67
+
68
+ asyncio.run(main())
69
+ ```
70
+
71
+ ## Architecture
72
+
73
+ ```
74
+ ┌─────────────────────────────────────────────────────────────────┐
75
+ │ OrcaMachine │
76
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
77
+ │ │ State Store │ │ Transition │ │ Effect Executor │ │
78
+ │ │ (current) │ │ Evaluator │ │ (async handlers) │ │
79
+ │ └──────────────┘ └──────────────┘ └──────────────────────┘ │
80
+ │ │ │ │ │
81
+ │ └────────────────┼──────────────────────┘ │
82
+ │ ▼ │
83
+ │ ┌──────────────────┐ │
84
+ │ │ EventBus │ (pub/sub) │
85
+ │ └──────────────────┘ │
86
+ └─────────────────────────────────────────────────────────────────┘
87
+ ```
88
+
89
+ ## Core Components
90
+
91
+ ### OrcaMachine
92
+
93
+ The main runtime class that executes state machines:
94
+
95
+ ```python
96
+ machine = OrcaMachine(
97
+ definition=machine_def,
98
+ event_bus=get_event_bus(),
99
+ context={"order_id": "123"},
100
+ on_transition=lambda old, new: print(f"{old} -> {new}"),
101
+ )
102
+ ```
103
+
104
+ ### EventBus
105
+
106
+ Async event bus with pub/sub and request/response:
107
+
108
+ ```python
109
+ bus = get_event_bus()
110
+
111
+ # Subscribe to events
112
+ bus.subscribe(EventType.STATE_CHANGED, handler)
113
+
114
+ # Publish events
115
+ await bus.publish(Event(
116
+ type=EventType.STATE_CHANGED,
117
+ source="OrderProcessor",
118
+ payload={"from": "pending", "to": "fulfilled"},
119
+ ))
120
+
121
+ # Request/response pattern
122
+ response = await bus.request_response(
123
+ request_type=EventType.SCHEDULING_QUERY,
124
+ request_payload={"type": "availability"},
125
+ response_type=EventType.SCHEDULING_QUERY_RESPONSE,
126
+ )
127
+ ```
128
+
129
+ ### Effect Handlers
130
+
131
+ Register async handlers for effect types:
132
+
133
+ ```python
134
+ async def handle_narrative(effect: Effect) -> EffectResult:
135
+ narrative = await generate_narrative(effect.payload)
136
+ return EffectResult(status="success", data={"narrative": narrative})
137
+
138
+ bus.register_effect_handler("NarrativeRequest", handle_narrative)
139
+ ```
140
+
141
+ ## Orca DSL Syntax
142
+
143
+ ```orca
144
+ machine GameEngine
145
+
146
+ context {
147
+ health: int = 100
148
+ inventory: string[]
149
+ }
150
+
151
+ events {
152
+ start_game
153
+ attack
154
+ heal
155
+ }
156
+
157
+ state idle [initial] {
158
+ description: "Waiting for player input"
159
+ }
160
+
161
+ state combat {
162
+ description: "In combat"
163
+
164
+ state fighting [initial] {
165
+ description: "Actively fighting"
166
+ }
167
+
168
+ state defending {
169
+ description: "Blocking attacks"
170
+ }
171
+ }
172
+
173
+ state game_over [final] {
174
+ description: "Game ended"
175
+ }
176
+
177
+ guards {
178
+ can_heal: ctx.health < 100
179
+ }
180
+
181
+ transitions {
182
+ idle + start_game -> combat : start_combat
183
+ combat + attack -> combat : resolve_attack
184
+ combat + heal [can_heal] -> combat : apply_heal
185
+ combat + attack [health <= 0] -> game_over : end_game
186
+ }
187
+
188
+ actions {
189
+ start_combat: (ctx: Context) -> Context
190
+ resolve_attack: (ctx: Context) -> Context + Effect<DamageRequest>
191
+ apply_heal: (ctx: Context) -> Context
192
+ end_game: (ctx: Context) -> Context
193
+ }
194
+ ```
195
+
196
+ ## Hierarchy
197
+
198
+ ```
199
+ orca-runtime-python/
200
+ ├── orca_runtime_python/ # Main package
201
+ │ ├── __init__.py
202
+ │ ├── types.py # Core types
203
+ │ ├── parser.py # DSL parser
204
+ │ ├── machine.py # OrcaMachine runtime
205
+ │ ├── bus.py # EventBus
206
+ │ └── effects.py # Effect system
207
+ ├── pyproject.toml
208
+ └── README.md
209
+ ```
210
+
211
+ ## Relationship to Other Implementations
212
+
213
+ | Package | Language | Purpose |
214
+ |---------|----------|---------|
215
+ | `orca` (npm) | TypeScript/JS | Core implementation (parser, verifier, compiler) |
216
+ | `orca-runtime-python` | Python | Python async runtime |
217
+
218
+ The Orca language is defined once and implemented across platforms. The Python runtime executes machines compiled from Orca DSL.
219
+
220
+ ## License
221
+
222
+ Apache 2.0
@@ -0,0 +1,69 @@
1
+ """
2
+ Orca Runtime Python
3
+
4
+ A first-class Python async runtime for Orca state machines.
5
+ """
6
+
7
+ from .types import (
8
+ StateDef,
9
+ Transition,
10
+ GuardDef,
11
+ ActionSignature,
12
+ EffectDef,
13
+ MachineDef,
14
+ StateValue,
15
+ Context,
16
+ Effect,
17
+ EffectResult,
18
+ EffectStatus,
19
+ )
20
+
21
+ from .bus import (
22
+ EventBus,
23
+ Event,
24
+ EventType,
25
+ get_event_bus,
26
+ )
27
+
28
+ from .machine import OrcaMachine
29
+
30
+ from .parser import parse_orca_md, parse_orca_auto
31
+
32
+ from .persistence import PersistenceAdapter, FilePersistence
33
+
34
+ from .logging import LogSink, FileSink, ConsoleSink, MultiSink
35
+
36
+ __version__ = "0.1.0"
37
+
38
+ __all__ = [
39
+ # Types
40
+ "StateDef",
41
+ "Transition",
42
+ "GuardDef",
43
+ "ActionSignature",
44
+ "EffectDef",
45
+ "MachineDef",
46
+ "StateValue",
47
+ "Context",
48
+ "Effect",
49
+ "EffectResult",
50
+ "EffectStatus",
51
+ # Bus
52
+ "EventBus",
53
+ "Event",
54
+ "EventType",
55
+ "get_event_bus",
56
+ # Machine
57
+ "OrcaMachine",
58
+ # Parser
59
+ "parse_orca_md",
60
+ "parse_orca_auto",
61
+ # Persistence
62
+ "PersistenceAdapter",
63
+ "FilePersistence",
64
+ # Logging
65
+ "LogSink",
66
+ "FileSink",
67
+ "ConsoleSink",
68
+ "MultiSink",
69
+ ]