necoherence 0.2.0__py3-none-any.whl

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,66 @@
1
+ # Python 向けの Necoherence
2
+
3
+ [プロジェクトの概要](https://github.com/barineco/necoherence/blob/publish/README-ja.md) | [English](README.md)
4
+
5
+ このパッケージは、Necoherence の Python による実装で、Python 3.12 以降で使えます。
6
+ 実行時に使うのは、標準ライブラリだけです。
7
+
8
+ ## 意味プロファイルの受け入れ
9
+
10
+ 呼び出し側は、宣言を復号するときと、生成したライブラリを受け入れるときに、版の付いた意味プロファイルを渡します。
11
+ 検証、符号化と復号、実行で使う転送形式は、受け入れたプロファイルが定めます。
12
+
13
+ 期待するプロファイルの参照、出典、信頼するバイト列は、入力のバイト列とは別の引数として渡します。
14
+
15
+ ```python
16
+ from necoherence.signature_values import ValueContext
17
+ from necoherence.type_signatures import checkLibrary, decode_profile_artifact
18
+
19
+ def decide(expected, sources, trusted, input_bytes, library, type_id, value):
20
+ profile = decode_profile_artifact(expected, sources, trusted, input_bytes)
21
+ checked = checkLibrary({**library, "profile": profile})
22
+ context = ValueContext({
23
+ "profile": checked.value["profile"], "nodes": checked.value["nodes"],
24
+ })
25
+ return context.validate(type_id, value)
26
+ ```
27
+
28
+ 失敗の型は、原因ごとに次のとおりです。
29
+
30
+ - `WireFailure`: プロファイルの転送値の形式が誤っている
31
+ - `DeclarationFailure`: プロファイルかライブラリが、宣言の条件に違反している
32
+ - `AdmissionFailure`: プロファイルが、期待した参照や出典と食い違っている
33
+ - `MeaningFailure`: 型に意味の定義が欠けている
34
+ - `ValueFailure`: 値が検証で拒否された
35
+
36
+ ## その他の機能
37
+
38
+ [プロジェクトの概要](https://github.com/barineco/necoherence/blob/publish/README-ja.md) に挙げた機能のほかに、次の機能があります。
39
+
40
+ - 宣言の検査: 識別子の重複や、宣言にない型や定義への参照など、型と操作の宣言の誤りを検出する
41
+ - 生成したコードのランタイム: 生成した Python のコードが実行時に呼び出す、値の検証とコーデックの共通の処理
42
+
43
+ 任意の [HTTP アダプター](../python-http-adapter/) は、`necoherence-http-adapter` として独立に配布します。ネットワーク副作用のコマンドを実行し、観測を核の台帳へ返します。
44
+
45
+ ## 付属のツール
46
+
47
+ 型と操作の宣言から Python の型とコーデックを生成する生成器は、[tools/](https://github.com/barineco/necoherence/tree/publish/tools) にあります。
48
+ ライセンスは AGPL-3.0-only です。
49
+
50
+ ## 使用例
51
+
52
+ 使用例は [examples/](https://github.com/barineco/necoherence/tree/publish/python/examples) にあります。
53
+
54
+ ## テストと型検査
55
+
56
+ 次のコマンドで、テストと型検査を実行します。
57
+
58
+ ```bash
59
+ python3 -m pip install ".[dev]"
60
+ python3 -m pytest -q
61
+ python3 -m mypy src tests
62
+ ```
63
+
64
+ ## ライセンス
65
+
66
+ [MIT](LICENSE)
necoherence/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Necoherence for Python
2
+
3
+ [Project overview](https://github.com/barineco/necoherence/blob/publish/README.md) | [日本語](README-ja.md)
4
+
5
+ This package is the Python implementation of Necoherence, for Python 3.12 or later.
6
+ It uses only the standard library at run time.
7
+
8
+ ## Accepting a semantic profile
9
+
10
+ The caller passes a versioned semantic profile when decoding declarations and when accepting a generated library.
11
+ The accepted profile defines the wire format used by validation, encoding and decoding, and execution.
12
+
13
+ The expected profile reference, the sources, and the trusted bytes are passed as arguments separate from the input bytes.
14
+
15
+ ```python
16
+ from necoherence.signature_values import ValueContext
17
+ from necoherence.type_signatures import checkLibrary, decode_profile_artifact
18
+
19
+ def decide(expected, sources, trusted, input_bytes, library, type_id, value):
20
+ profile = decode_profile_artifact(expected, sources, trusted, input_bytes)
21
+ checked = checkLibrary({**library, "profile": profile})
22
+ context = ValueContext({
23
+ "profile": checked.value["profile"], "nodes": checked.value["nodes"],
24
+ })
25
+ return context.validate(type_id, value)
26
+ ```
27
+
28
+ Failures are returned as the following types, one for each cause:
29
+
30
+ - `WireFailure`: the profile's wire value is malformed
31
+ - `DeclarationFailure`: the profile or the library violates a declaration condition
32
+ - `AdmissionFailure`: the profile differs from the expected reference or sources
33
+ - `MeaningFailure`: a type lacks a definition of its meaning
34
+ - `ValueFailure`: validation rejected the value
35
+
36
+ ## Other features
37
+
38
+ Besides the features listed in the [project overview](https://github.com/barineco/necoherence/blob/publish/README.md), the package provides the following:
39
+
40
+ - Declaration checking: detects errors in declarations of types and operations, such as duplicate identifiers and references to undeclared types or definitions
41
+ - Runtime for generated code: the shared value validation and codec routines that generated Python code calls at run time
42
+
43
+ The optional [HTTP adapter](../python-http-adapter/) is distributed separately as `necoherence-http-adapter`. It executes network-effect commands and returns observations to the core ledger.
44
+
45
+ ## Tools
46
+
47
+ The generator, which produces Python types and codecs from declarations of types and operations, is in [tools/](https://github.com/barineco/necoherence/tree/publish/tools).
48
+ Its license is AGPL-3.0-only.
49
+
50
+ ## Examples
51
+
52
+ Examples are in [examples/](https://github.com/barineco/necoherence/tree/publish/python/examples).
53
+
54
+ ## Testing and type checking
55
+
56
+ The following commands run the tests and the type checks:
57
+
58
+ ```bash
59
+ python3 -m pip install ".[dev]"
60
+ python3 -m pytest -q
61
+ python3 -m mypy src tests
62
+ ```
63
+
64
+ ## License
65
+
66
+ [MIT](LICENSE)
@@ -0,0 +1,479 @@
1
+ # SPDX-FileCopyrightText: 2026 barineco
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """Revision-aware state transition utilities for Python.
5
+
6
+ Ten shared feature families: core, call, iteration, store, record,
7
+ reconcile, request progression, dynamic admission, step transition, file
8
+ effect.
9
+ """
10
+
11
+ from necoherence.call import (
12
+ BoundaryDiagnosis,
13
+ CallFailed,
14
+ CallOk,
15
+ CallResult,
16
+ Deferred,
17
+ Immediate,
18
+ ProjectionFailed,
19
+ Request,
20
+ deferred_of,
21
+ immediate_of,
22
+ io,
23
+ issue,
24
+ )
25
+ from necoherence.core import (
26
+ Applied,
27
+ Basis,
28
+ BoundaryFailed,
29
+ Command,
30
+ Conflicted,
31
+ Observation,
32
+ Outcome,
33
+ Rejected,
34
+ ResourceId,
35
+ Revision,
36
+ StaleBasis,
37
+ UnknownResource,
38
+ World,
39
+ apply,
40
+ bump,
41
+ command_of,
42
+ lookup,
43
+ )
44
+ from necoherence.dynamic_admission import (
45
+ AdapterBindingUnavailable,
46
+ AdmissionDecision,
47
+ AdmissionProvenance,
48
+ AdmissionSignal,
49
+ BindingSelectionMismatch,
50
+ CapacityObservation,
51
+ CapacityObservationUnavailable,
52
+ Coalesced,
53
+ CoalescedWitness,
54
+ CoalescingWitness,
55
+ ConfiguredSafetyLimitExceeded,
56
+ DynamicAdmissionFailure,
57
+ DynamicAdmissionInput,
58
+ DynamicAdmissionOutcome,
59
+ DynamicAdmissionResult,
60
+ DynamicAdmissionState,
61
+ DynamicPermissionIdentityMismatch,
62
+ DynamicUnknownRequest,
63
+ EffectiveBudget,
64
+ ElisionOutcome,
65
+ Erased,
66
+ EnvironmentSpecification,
67
+ FutureUseSet,
68
+ MeaningDenied,
69
+ NotCoalesced,
70
+ OutstandingSignalSet,
71
+ ProgressionStartFailure,
72
+ ProgressionSubmitFailure,
73
+ ProvenanceErasureWitness,
74
+ ProvenanceRetentionRequired,
75
+ RequestNotTerminal,
76
+ ResourceCoordinateMismatch,
77
+ Retained,
78
+ SignalKind,
79
+ Started as DynamicStarted,
80
+ Submitted,
81
+ admit_dynamic_request,
82
+ elide_admission_provenance,
83
+ )
84
+ from necoherence.files import (
85
+ ContentDigest,
86
+ Digests,
87
+ ExternalFileState,
88
+ ExternalMutation,
89
+ FileRecord,
90
+ FileSnapshot,
91
+ NormalizedPath,
92
+ Read,
93
+ ReadFailure,
94
+ ReadReq,
95
+ ReadResult,
96
+ ReplaceContents,
97
+ ReplaceReq,
98
+ ReplaceResult,
99
+ Replaced,
100
+ ResourcePathMismatch,
101
+ Tracked,
102
+ TrackReq,
103
+ TrackResult,
104
+ UnobservedContents,
105
+ lookup_digest,
106
+ normalize_path,
107
+ read,
108
+ replace,
109
+ set_digest,
110
+ track,
111
+ )
112
+ from necoherence.iteration import (
113
+ ClosureFixpoint,
114
+ ClosureOutcome,
115
+ ClosureProjectionFailed,
116
+ ClosureReq,
117
+ ClosureState,
118
+ ClosureViolation,
119
+ Continue,
120
+ FoldCountNegative,
121
+ FoldOutcome,
122
+ FoldReq,
123
+ FoldStopped,
124
+ FoldTrace,
125
+ MeasureNegative,
126
+ RecurseDidNotDecrease,
127
+ RecurseOutcome,
128
+ RecurseProjectionFailed,
129
+ RecurseReq,
130
+ RecurseSettled,
131
+ Settled,
132
+ StageProjectionFailed,
133
+ StepOutcome,
134
+ closure,
135
+ fold,
136
+ recurse,
137
+ )
138
+ from necoherence.reconcile import (
139
+ Divergence,
140
+ Reconciliation,
141
+ UnknownToWorld,
142
+ WorldAhead,
143
+ WorldBehind,
144
+ coherent,
145
+ reconcile,
146
+ )
147
+ from necoherence.record import (
148
+ CallRecord,
149
+ NoBasis,
150
+ has_edge,
151
+ record_of,
152
+ record_on_basis,
153
+ )
154
+ from necoherence.request_progression import (
155
+ Accepted, AdapterCommand, AdapterFailed, AdapterFailure, AdapterResult,
156
+ AdapterSignal, AppliedResult, AppliedSignal, CancelCommand, CancelDecisionResult,
157
+ CancelFailure, CancelIssued, CancelRejected, CancelUnknownRequest,
158
+ CancelledAtAdapter, CancelledResult, CancelledWithoutAdapter,
159
+ CancellationAdapterFailure, CancellationAdapterFailureObserved,
160
+ CompletionAdapterFailure, CompletionAdapterFailureObserved,
161
+ CompletionIdentityMismatch, CompletionNotRunning, CompletionObservationFailed,
162
+ CompletionObservationFailure, CompletionObservationResult, CompletionSignalMismatch,
163
+ ConcurrentLimitExceeded, ConfiguredSafetyLimit, CostSelection,
164
+ CostSelectionIdentityMismatch, Deferred as StartDeferred, Denied, DuplicateIdentity,
165
+ EvidenceVersion, Execute, ExecuteNow, ExecutionHandle, HandleMismatch,
166
+ InFlightLimitExceeded, MeaningPermission, MissingExecutionHandle, Ordered,
167
+ PendingLimitExceeded, PermissionDenial, PermissionDenied,
168
+ PermissionIdentityMismatch, PermissionNotOrdered, Permitted, PolicyOrderBlocked,
169
+ Publishing, RemainPending, RequestAlreadyTerminal, RequestEffectClass,
170
+ RequestEntry, RequestFootprint, RequestIdentity, RequestInput, RequestNotPending,
171
+ RequestNotStarting, RequestPhase, RequestPolicy, RequestProgressionSnapshot,
172
+ ResourceBudget, ResourceDemand, Running, Started, Starting, StartAdapterFailure,
173
+ StartAdapterFailureObserved, StartCommand, StartDecisionFailure,
174
+ StartDecisionRejected, StartDecisionResult, StartIdentityMismatch,
175
+ StartObservationFailed, StartObservationFailure, StartObservationResult,
176
+ StartSignalMismatch, SubmitAccepted, SubmitFailure, SubmitRejected, SubmitResult,
177
+ SupersededResult, UnknownCompletion, UnknownRequest, apply_completion_observation,
178
+ apply_start_observation, decide_cancel, decide_start, derive_concurrent,
179
+ derive_in_flight, derive_pending, empty, submit,
180
+ )
181
+ from necoherence.store import (
182
+ Found,
183
+ Observed,
184
+ Store,
185
+ Unknown,
186
+ observe,
187
+ store_entries,
188
+ store_of,
189
+ world_of_store,
190
+ )
191
+ from necoherence.transition import (
192
+ Capacity,
193
+ CapacityExceeded,
194
+ CapacityNegative,
195
+ Consumed,
196
+ Consumption,
197
+ LimitNotPositive,
198
+ PositiveLimit,
199
+ Reprocess,
200
+ ReprocessLimitExhausted,
201
+ StepFailed,
202
+ StepFailure,
203
+ StepSettled,
204
+ StepTransition,
205
+ step,
206
+ )
207
+ from necoherence.signature_support import GenerationFailure
208
+
209
+ __all__ = [
210
+ "GenerationFailure",
211
+ "Accepted",
212
+ "AdapterBindingUnavailable",
213
+ "AdapterCommand",
214
+ "AdapterFailed",
215
+ "AdapterFailure",
216
+ "AdapterResult",
217
+ "AdapterSignal",
218
+ "AdmissionDecision",
219
+ "AdmissionProvenance",
220
+ "AdmissionSignal",
221
+ "Applied",
222
+ "AppliedResult",
223
+ "AppliedSignal",
224
+ "Basis",
225
+ "BindingSelectionMismatch",
226
+ "BoundaryDiagnosis",
227
+ "BoundaryFailed",
228
+ "CallRecord",
229
+ "CancelCommand",
230
+ "CancelDecisionResult",
231
+ "CancelFailure",
232
+ "CancelIssued",
233
+ "CancelRejected",
234
+ "CancelUnknownRequest",
235
+ "CancelledAtAdapter",
236
+ "CancelledResult",
237
+ "CancelledWithoutAdapter",
238
+ "CancellationAdapterFailure",
239
+ "CancellationAdapterFailureObserved",
240
+ "CallFailed",
241
+ "CallOk",
242
+ "CallResult",
243
+ "Capacity",
244
+ "CapacityExceeded",
245
+ "CapacityNegative",
246
+ "CapacityObservation",
247
+ "CapacityObservationUnavailable",
248
+ "ClosureFixpoint",
249
+ "ClosureOutcome",
250
+ "ClosureProjectionFailed",
251
+ "ClosureReq",
252
+ "ClosureState",
253
+ "ClosureViolation",
254
+ "Coalesced",
255
+ "CoalescedWitness",
256
+ "CoalescingWitness",
257
+ "Command",
258
+ "CompletionAdapterFailure",
259
+ "CompletionAdapterFailureObserved",
260
+ "CompletionIdentityMismatch",
261
+ "CompletionNotRunning",
262
+ "CompletionObservationFailed",
263
+ "CompletionObservationFailure",
264
+ "CompletionObservationResult",
265
+ "CompletionSignalMismatch",
266
+ "ConfiguredSafetyLimit",
267
+ "ConfiguredSafetyLimitExceeded",
268
+ "ConcurrentLimitExceeded",
269
+ "Conflicted",
270
+ "Consumed",
271
+ "Consumption",
272
+ "ContentDigest",
273
+ "Continue",
274
+ "CostSelection",
275
+ "CostSelectionIdentityMismatch",
276
+ "StartDeferred",
277
+ "Denied",
278
+ "Digests",
279
+ "Divergence",
280
+ "DuplicateIdentity",
281
+ "DynamicAdmissionFailure",
282
+ "DynamicAdmissionInput",
283
+ "DynamicAdmissionOutcome",
284
+ "DynamicAdmissionResult",
285
+ "DynamicAdmissionState",
286
+ "DynamicPermissionIdentityMismatch",
287
+ "DynamicStarted",
288
+ "DynamicUnknownRequest",
289
+ "EffectiveBudget",
290
+ "ElisionOutcome",
291
+ "EnvironmentSpecification",
292
+ "Erased",
293
+ "EvidenceVersion",
294
+ "Execute",
295
+ "ExecuteNow",
296
+ "ExecutionHandle",
297
+ "ExternalFileState",
298
+ "ExternalMutation",
299
+ "FileRecord",
300
+ "FileSnapshot",
301
+ "Found",
302
+ "FoldCountNegative",
303
+ "FoldOutcome",
304
+ "FoldReq",
305
+ "FoldStopped",
306
+ "FoldTrace",
307
+ "FutureUseSet",
308
+ "HandleMismatch",
309
+ "Immediate",
310
+ "InFlightLimitExceeded",
311
+ "LimitNotPositive",
312
+ "MeasureNegative",
313
+ "MeaningDenied",
314
+ "MeaningPermission",
315
+ "MissingExecutionHandle",
316
+ "NoBasis",
317
+ "NormalizedPath",
318
+ "NotCoalesced",
319
+ "Observation",
320
+ "Observed",
321
+ "Ordered",
322
+ "Outcome",
323
+ "OutstandingSignalSet",
324
+ "PendingLimitExceeded",
325
+ "PermissionDenial",
326
+ "PermissionDenied",
327
+ "PermissionIdentityMismatch",
328
+ "PermissionNotOrdered",
329
+ "Permitted",
330
+ "PolicyOrderBlocked",
331
+ "PositiveLimit",
332
+ "ProgressionStartFailure",
333
+ "ProgressionSubmitFailure",
334
+ "ProjectionFailed",
335
+ "ProvenanceErasureWitness",
336
+ "ProvenanceRetentionRequired",
337
+ "Publishing",
338
+ "Read",
339
+ "ReadFailure",
340
+ "ReadReq",
341
+ "ReadResult",
342
+ "Reconciliation",
343
+ "Request",
344
+ "RecurseDidNotDecrease",
345
+ "RecurseOutcome",
346
+ "RecurseProjectionFailed",
347
+ "RecurseReq",
348
+ "RecurseSettled",
349
+ "Rejected",
350
+ "RemainPending",
351
+ "ReplaceContents",
352
+ "ReplaceReq",
353
+ "ReplaceResult",
354
+ "Replaced",
355
+ "Reprocess",
356
+ "ReprocessLimitExhausted",
357
+ "RequestAlreadyTerminal",
358
+ "RequestEffectClass",
359
+ "RequestEntry",
360
+ "RequestFootprint",
361
+ "RequestIdentity",
362
+ "RequestInput",
363
+ "RequestNotPending",
364
+ "RequestNotStarting",
365
+ "RequestNotTerminal",
366
+ "RequestPhase",
367
+ "RequestPolicy",
368
+ "RequestProgressionSnapshot",
369
+ "ResourceBudget",
370
+ "ResourceCoordinateMismatch",
371
+ "ResourceDemand",
372
+ "ResourceId",
373
+ "ResourcePathMismatch",
374
+ "Retained",
375
+ "Revision",
376
+ "Running",
377
+ "Settled",
378
+ "SignalKind",
379
+ "StageProjectionFailed",
380
+ "StaleBasis",
381
+ "StartAdapterFailure",
382
+ "StartAdapterFailureObserved",
383
+ "StartCommand",
384
+ "StartDecisionFailure",
385
+ "StartDecisionRejected",
386
+ "StartDecisionResult",
387
+ "StartIdentityMismatch",
388
+ "StartObservationFailed",
389
+ "StartObservationFailure",
390
+ "StartObservationResult",
391
+ "StartSignalMismatch",
392
+ "Started",
393
+ "Starting",
394
+ "StepFailed",
395
+ "StepFailure",
396
+ "StepOutcome",
397
+ "StepSettled",
398
+ "StepTransition",
399
+ "Store",
400
+ "SubmitAccepted",
401
+ "SubmitFailure",
402
+ "SubmitRejected",
403
+ "SubmitResult",
404
+ "Submitted",
405
+ "SupersededResult",
406
+ "TrackReq",
407
+ "TrackResult",
408
+ "Tracked",
409
+ "UnknownCompletion",
410
+ "UnknownRequest",
411
+ "UnknownResource",
412
+ "UnknownToWorld",
413
+ "Unknown",
414
+ "UnobservedContents",
415
+ "World",
416
+ "WorldAhead",
417
+ "WorldBehind",
418
+ "admit_dynamic_request",
419
+ "apply",
420
+ "apply_completion_observation",
421
+ "apply_start_observation",
422
+ "bump",
423
+ "closure",
424
+ "coherent",
425
+ "command_of",
426
+ "decide_cancel",
427
+ "decide_start",
428
+ "deferred_of",
429
+ "derive_concurrent",
430
+ "derive_in_flight",
431
+ "derive_pending",
432
+ "elide_admission_provenance",
433
+ "empty",
434
+ "fold",
435
+ "has_edge",
436
+ "immediate_of",
437
+ "io",
438
+ "issue",
439
+ "lookup",
440
+ "lookup_digest",
441
+ "normalize_path",
442
+ "observe",
443
+ "read",
444
+ "reconcile",
445
+ "record_of",
446
+ "record_on_basis",
447
+ "recurse",
448
+ "replace",
449
+ "set_digest",
450
+ "step",
451
+ "store_entries",
452
+ "store_of",
453
+ "submit",
454
+ "track",
455
+ ]
456
+
457
+ from .type_signatures import (
458
+ TypeSignatureLibrary, ExpectedSignatureBasis, CheckedSignatureGeneration,
459
+ admit_signature_generation, checkLibrary, checkProfile, decode_diagnostic,
460
+ decode_generation, decode_library, decode_profile, decode_profile_artifact,
461
+ decode_signature_basis, decode_value_condition, encode_diagnostic,
462
+ encode_generation, encode_library, encode_profile, encode_signature_basis,
463
+ encode_value_condition, signature_basis, value_semantic_profile,
464
+ )
465
+ from .signature_values import (
466
+ Completed, Ready, SealedForm, TagModel, Wrapper,
467
+ selectBranch, withMember, wrapDecode, wrapEncode,
468
+ )
469
+
470
+ __all__ += [
471
+ "TypeSignatureLibrary", "ExpectedSignatureBasis", "CheckedSignatureGeneration",
472
+ "admit_signature_generation", "checkLibrary", "checkProfile", "decode_diagnostic",
473
+ "decode_generation", "decode_library", "decode_profile", "decode_profile_artifact",
474
+ "decode_signature_basis", "decode_value_condition", "encode_diagnostic",
475
+ "encode_generation", "encode_library", "encode_profile", "encode_signature_basis",
476
+ "encode_value_condition", "signature_basis", "value_semantic_profile",
477
+ "Completed", "Ready", "SealedForm", "TagModel", "Wrapper",
478
+ "selectBranch", "withMember", "wrapDecode", "wrapEncode",
479
+ ]