ruml-parser 1.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.
- ruml_parser-1.0.0/.github/workflows/release.yml +39 -0
- ruml_parser-1.0.0/CONTRIBUTING.md +24 -0
- ruml_parser-1.0.0/DEVELOPMENT.md +151 -0
- ruml_parser-1.0.0/LICENSE +73 -0
- ruml_parser-1.0.0/LICENSES/Apache-2.0.txt +73 -0
- ruml_parser-1.0.0/PKG-INFO +119 -0
- ruml_parser-1.0.0/README.md +102 -0
- ruml_parser-1.0.0/REUSE.toml +6 -0
- ruml_parser-1.0.0/pyproject.toml +44 -0
- ruml_parser-1.0.0/ruml_parser/__init__.py +183 -0
- ruml_parser-1.0.0/ruml_parser/internal/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/extension.py +91 -0
- ruml_parser-1.0.0/ruml_parser/internal/mapping.py +731 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/__init__.py +237 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/actions/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/actions/actions_capability_declaration.py +23 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/actions/actions_node_capability.py +40 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/ai_query/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/ai_query/ai_query_capability_declaration.py +25 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/ai_query/ai_query_node_capability.py +66 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/aliases.py +93 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/abstract_capability_declaration.py +23 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/abstract_node_capability.py +14 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/capability_declaration.py +52 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/capability_declarations.py +199 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/extension_node_capability.py +17 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/node_capabilities.py +113 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/capability/other_node_capability.py +21 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/context/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/context/context.py +40 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/context/context_capability_declaration.py +25 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/context/context_refs_node_capability.py +17 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/datapoints/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/datapoints/datapoint.py +101 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/datapoints/datapoint_set.py +20 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/datapoints/datapoints_capability_declaration.py +29 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/datapoints/option.py +11 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/expression/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/expression/expression_capability_declaration.py +23 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/expression/expression_node_capability.py +20 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/metadata.py +83 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/nodes/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/nodes/abstract_node.py +29 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/nodes/branch_node.py +15 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/nodes/leaf_node.py +10 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/nodes/node.py +6 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/protocol/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/protocol/protocol_capability_declaration.py +29 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/query/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/query/query_capability_declaration.py +23 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/query/query_node_capability.py +17 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/ruml_document.py +45 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/text_reference/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/text_reference/text.py +69 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/text_reference/text_reference_capability_declaration.py +25 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/text_reference/text_refs_node_capability.py +32 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/tree/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/internal/ruml/tree/tree_capability_declarations.py +30 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/__init__.py +14 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/capabilities.py +227 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/contexts.py +51 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/datapoint_sets.py +125 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/modular.py +42 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/recursion.py +197 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/root.py +36 -0
- ruml_parser-1.0.0/ruml_parser/internal/validation/texts.py +50 -0
- ruml_parser-1.0.0/ruml_parser/model/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/model/ruml.py +1156 -0
- ruml_parser-1.0.0/ruml_parser/model/ruml_result.py +430 -0
- ruml_parser-1.0.0/ruml_parser/node_result_status.py +19 -0
- ruml_parser-1.0.0/ruml_parser/pydantic.py +96 -0
- ruml_parser-1.0.0/ruml_parser/ruml_parser.py +75 -0
- ruml_parser-1.0.0/ruml_parser/schema_files.py +23 -0
- ruml_parser-1.0.0/ruml_parser/schema_validation.py +354 -0
- ruml_parser-1.0.0/ruml_parser/structural_error.py +36 -0
- ruml_parser-1.0.0/ruml_parser/tests/__init__.py +2 -0
- ruml_parser-1.0.0/ruml_parser/tests/greeting_extension.py +75 -0
- ruml_parser-1.0.0/ruml_parser/tests/ruml_builders.py +184 -0
- ruml_parser-1.0.0/ruml_parser/tests/ruml_dict.py +483 -0
- ruml_parser-1.0.0/ruml_parser/tests/ruml_result_dict.py +200 -0
- ruml_parser-1.0.0/ruml_parser/tests/ruml_result_schema.py +36 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_capability_extensions.py +170 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_context_input_validation.py +88 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_datapoint_sets.py +179 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_identifier_patterns.py +62 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_internal_mapping.py +943 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_metadata_length_limits.py +25 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_metadata_status_rules.py +63 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_protocol.py +43 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_pydantic.py +145 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_recursion_flags.py +302 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_result_schema_reason.py +97 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_ruml_parser.py +129 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_ruml_parser_extensions.py +91 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_schema_error_locations.py +133 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_schema_formats.py +268 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_text.py +147 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_text_input_validation.py +93 -0
- ruml_parser-1.0.0/ruml_parser/tests/test_text_references.py +101 -0
- ruml_parser-1.0.0/ruml_parser/tests/validation/test_capabilities.py +313 -0
- ruml_parser-1.0.0/ruml_parser/tests/validation/test_modular.py +94 -0
- ruml_parser-1.0.0/ruml_parser/tests/validation/test_root.py +67 -0
- ruml_parser-1.0.0/ruml_parser/text.py +220 -0
- ruml_parser-1.0.0/scripts/ruml_schema_pre_process.py +100 -0
- ruml_parser-1.0.0/uv.lock +563 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
release:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: astral-sh/setup-uv@v6
|
|
20
|
+
|
|
21
|
+
- run: uv sync
|
|
22
|
+
- run: uv run --with pytest pytest
|
|
23
|
+
|
|
24
|
+
- run: uv build --out-dir dist
|
|
25
|
+
|
|
26
|
+
- name: Tag and release
|
|
27
|
+
env:
|
|
28
|
+
GH_TOKEN: ${{ github.token }}
|
|
29
|
+
run: |
|
|
30
|
+
tag="v$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml | head -1)"
|
|
31
|
+
case "$tag" in *-*) prerelease=--prerelease ;; *) prerelease= ;; esac
|
|
32
|
+
if ! gh release view "$tag" >/dev/null 2>&1; then
|
|
33
|
+
gh release create "$tag" --target "$GITHUB_SHA" --title "$tag" $prerelease
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
- name: Publish to PyPI
|
|
37
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
38
|
+
with:
|
|
39
|
+
skip-existing: true
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
This repository holds the Python parser for RUML. It is published by the
|
|
4
|
+
Law as Code Institut GmbH; Rulemapping Group GmbH holds the rights.
|
|
5
|
+
|
|
6
|
+
## What we take at the moment
|
|
7
|
+
|
|
8
|
+
Feedback is welcome. Please open an issue for
|
|
9
|
+
|
|
10
|
+
- errors, gaps and unclear passages,
|
|
11
|
+
- questions about how something is meant,
|
|
12
|
+
- proposals for changes or additions.
|
|
13
|
+
|
|
14
|
+
We do not accept pull requests yet. In this first phase the repository is an export of
|
|
15
|
+
our internal sources: each commit here is one export, and a change made here would be
|
|
16
|
+
overwritten by the next one. If an issue leads to a change, we make it in the sources and it
|
|
17
|
+
arrives here with the next export.
|
|
18
|
+
|
|
19
|
+
We will open the repository for code contributions later and describe the process here.
|
|
20
|
+
|
|
21
|
+
## Security
|
|
22
|
+
|
|
23
|
+
Please do not report security problems in a public issue. Use "Report a vulnerability" in the
|
|
24
|
+
Security tab of this repository.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Developing ruml-parser
|
|
2
|
+
|
|
3
|
+
This file contains information relevant to development of ruml-parser itself.
|
|
4
|
+
|
|
5
|
+
## Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
ruml-parser/
|
|
9
|
+
├── scripts/
|
|
10
|
+
│ └── ruml_schema_pre_process.py # Schema rewrite applied before code generation
|
|
11
|
+
└── ruml_parser/
|
|
12
|
+
├── ruml_parser.py # RumlParser: JSON text / dict / model → RumlDocument, with extensions
|
|
13
|
+
├── pydantic.py # ParsedRumlDocument: for rulemaps in Pydantic models, FastAPI params, ...
|
|
14
|
+
├── schema_files.py # Paths & metadata of shipped schema files
|
|
15
|
+
├── schema_validation.py # Full schema validation (incl. extensions' payload schemas)
|
|
16
|
+
├── text.py # RUML Text: readable text, element index, GUIDs, digest, writer
|
|
17
|
+
├── model/
|
|
18
|
+
│ ├── ruml.py # Generated models: RumlRulemappingLogicFormat, Node, ...
|
|
19
|
+
│ └── ruml_result.py # Generated models: RumlResultRumlEvaluationResultFormat, ...
|
|
20
|
+
├── internal/
|
|
21
|
+
│ ├── ruml/ # Hand-written internal dataclasses, one folder per capability: RumlDocument, ...
|
|
22
|
+
│ ├── mapping.py # to_internal(): generated model instance → internal dataclasses
|
|
23
|
+
│ ├── extension.py # CapabilityExtension: typed models of draft/third-party capabilities
|
|
24
|
+
│ └── validation/ # Checks of the spec's cross-object rules on a RumlDocument
|
|
25
|
+
└── tests/
|
|
26
|
+
├── ruml_dict.py # Generated TypedDicts of RUML: RumlRulemappingLogicFormatDict, ...
|
|
27
|
+
└── ruml_result_dict.py # Generated TypedDicts of RUML-Result: RumlResultRumlEvaluationResultFormatDict, ...
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`ruml_parser/model/ruml.py`, `ruml_result.py`, `tests/ruml_dict.py` and
|
|
31
|
+
`tests/ruml_result_dict.py` are **generated code**, so do not hand-edit them. See
|
|
32
|
+
[Regenerating the models](#regenerating-the-models).
|
|
33
|
+
|
|
34
|
+
## Model layers
|
|
35
|
+
|
|
36
|
+
Parsing of a RUML document is a two-step process: Pydantic models generated from the
|
|
37
|
+
RUML JSON Schema are utilized for the initial parsing; `to_internal` then converts these
|
|
38
|
+
into hand-written "internal" dataclasses (root model: `RumlDocument`), which are what
|
|
39
|
+
library users will work with. `RumlParser` can perform both steps at once:
|
|
40
|
+
|
|
41
|
+
<!-- Color code, uniform across the RUML READMEs (deliberately not explained to viewers — the colors only need to
|
|
42
|
+
match up subconsciously): blue = ruml-parser (one color per workspace package; hand-written files in the lighter
|
|
43
|
+
shade, generated ones in the slightly darker one), slate = repo-level tooling, green = runtime data. -->
|
|
44
|
+
|
|
45
|
+
```mermaid
|
|
46
|
+
graph TB
|
|
47
|
+
doc(["RUML document<br/>(JSON / dict)"])
|
|
48
|
+
schema["<b>ruml.schema.json</b><br/>(ruml-schema package)"]
|
|
49
|
+
generated["<b>ruml_parser/model/ruml.py</b><br/>RumlRulemappingLogicFormat<br/>(generated Pydantic model)"]
|
|
50
|
+
parser[["<b>RumlParser</b><br/>(also behind ParsedRumlDocument)"]]
|
|
51
|
+
toInternal[["<b>to_internal()</b><br/>ruml_parser/internal/mapping.py"]]
|
|
52
|
+
internal["<b>ruml_parser/internal/ruml/</b><br/>RumlDocument<br/>(hand-written dataclasses)"]
|
|
53
|
+
doc --> parser --> internal
|
|
54
|
+
doc -->|" plain Pydantic validation<br/>(the model alone) "| generated
|
|
55
|
+
generated --> toInternal --> internal
|
|
56
|
+
parser -.->|" 1. validates against<br/>(the full schema) "| schema
|
|
57
|
+
parser -.->|" 2. model_validate() "| generated
|
|
58
|
+
parser -.->|" 3. maps with "| toInternal
|
|
59
|
+
classDef parserIn fill: #eff6ff, stroke: #2563eb, color: #1e3a8a
|
|
60
|
+
classDef parserOut fill: #bfdbfe, stroke: #2563eb, color: #1e3a8a
|
|
61
|
+
classDef data fill: #dcfce7, stroke: #16a34a, color: #14532d
|
|
62
|
+
classDef spec fill: #cffafe, stroke: #0891b2, color: #164e63
|
|
63
|
+
class parser,toInternal,internal parserIn
|
|
64
|
+
class generated parserOut
|
|
65
|
+
class doc data
|
|
66
|
+
class schema spec
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
<sup>**Legend:** ─ transforms into ⋯ uses</sup>
|
|
70
|
+
|
|
71
|
+
Two things about this pipeline are easy to trip over:
|
|
72
|
+
|
|
73
|
+
- **The generated model is a loosened approximation of the schema.** Code generation
|
|
74
|
+
cannot express the schema's top-level `allOf` cross-field rules, which are dropped
|
|
75
|
+
before generation (see [Regenerating the models](#regenerating-the-models)), nor the
|
|
76
|
+
`if`/`then` rules that pick a capability payload's schema by the entry's id, which it
|
|
77
|
+
ignores: every payload comes out as a free-form object. `RumlParser` therefore
|
|
78
|
+
validates against the real schema *first* and only then parses into the model, as does
|
|
79
|
+
`ParsedRumlDocument`, which uses it; validating with the model alone accepts slightly
|
|
80
|
+
more than the schema allows. `RumlParser` collects every independent violation and
|
|
81
|
+
reports the offending locations as JSON Pointers (`RumlValidationError.paths`).
|
|
82
|
+
- **The internal dataclasses are the working representation.** The generated models
|
|
83
|
+
inherit every limitation of the schema, the code generator, and Pydantic — placeholder
|
|
84
|
+
names like `Type1`, unions like `Actions1 | Actions2 | Actions3`, capability entries
|
|
85
|
+
whose payload type is not selected by their id. The hand-written twin in
|
|
86
|
+
`internal/ruml/` fixes those where it matters; `to_internal()` translates a validated
|
|
87
|
+
model instance into it, rejecting what it cannot represent (a capability payload of
|
|
88
|
+
the wrong shape for its id), and then runs the checks in `internal/validation/` on the
|
|
89
|
+
result: the spec's cross-object rules that neither the schema nor the types can
|
|
90
|
+
express, such as "no implicit capabilities" (a node may only use capabilities the root
|
|
91
|
+
declares).
|
|
92
|
+
|
|
93
|
+
During development, the different layers and schemas from which they are generated are
|
|
94
|
+
kept in sync partly mechanically and partly by hand:
|
|
95
|
+
|
|
96
|
+
<!-- Color code, uniform across the RUML READMEs (deliberately not explained to viewers — the colors only need to
|
|
97
|
+
match up subconsciously): blue = ruml-parser (one color per workspace package; hand-written files in the lighter
|
|
98
|
+
shade, generated ones in the slightly darker one), slate = repo-level tooling, green = runtime data. -->
|
|
99
|
+
|
|
100
|
+
```mermaid
|
|
101
|
+
graph TB
|
|
102
|
+
schema["<b>ruml.schema.json</b><br/>(ruml-schema package,<br/>source of truth)"]
|
|
103
|
+
codegen[["<b>make update-models</b><br/>pre-process + codegen:<br/>top-level allOf dropped,<br/>payload rules not followed"]]
|
|
104
|
+
generated["<b>ruml_parser/model/ruml.py</b><br/>RumlRulemappingLogicFormat<br/>(generated Pydantic model)"]
|
|
105
|
+
generatedDicts["<b>ruml_parser/tests/ruml_dict.py</b><br/>RumlRulemappingLogicFormatDict<br/>(generated TypedDicts, for tests)"]
|
|
106
|
+
internal["<b>ruml_parser/internal/ruml/</b><br/>RumlDocument<br/>(hand-written dataclasses)"]
|
|
107
|
+
mapping["<b>ruml_parser/internal/mapping.py</b><br/>to_internal()<br/>(hand-written)"]
|
|
108
|
+
typecheck[["<b>make typecheck</b><br/>doubles as sync check:<br/>the mapping touches<br/>every field of both sides"]]
|
|
109
|
+
schema --> codegen
|
|
110
|
+
codegen -->|" payload: union of<br/>the rules' shapes "| generatedDicts
|
|
111
|
+
codegen -->|" payload: free-form object "| generated
|
|
112
|
+
generated ==>|" changes carried<br/>over by hand "| internal
|
|
113
|
+
generated & internal ==> mapping
|
|
114
|
+
typecheck -.->|" checks "| mapping
|
|
115
|
+
classDef parserIn fill: #eff6ff, stroke: #2563eb, color: #1e3a8a
|
|
116
|
+
classDef parserOut fill: #bfdbfe, stroke: #2563eb, color: #1e3a8a
|
|
117
|
+
classDef tooling fill: #e2e8f0, stroke: #64748b, color: #1e293b
|
|
118
|
+
classDef spec fill: #cffafe, stroke: #0891b2, color: #164e63
|
|
119
|
+
class schema spec
|
|
120
|
+
class codegen,internal,mapping parserIn
|
|
121
|
+
class generated,generatedDicts parserOut
|
|
122
|
+
class typecheck tooling
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
<sup>**Legend:** ━ carried over by hand ─ generates ⋯ checks</sup>
|
|
126
|
+
|
|
127
|
+
Because the mappers touch every field of both sides, type-checking doubles as a sync
|
|
128
|
+
check after a regeneration — see the module docstring of `internal/ruml/__init__.py` for
|
|
129
|
+
the conventions.
|
|
130
|
+
|
|
131
|
+
## Regenerating the models
|
|
132
|
+
|
|
133
|
+
To update Pydantic models generated from JSON Schemas, run:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
make update-models # from the repo root
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
This runs the repo-level `scripts/update_models.py`, which drives
|
|
140
|
+
[`datamodel-code-generator`](https://github.com/koxudaxi/datamodel-code-generator)
|
|
141
|
+
against every schema-generated model in the workspace: the four models here
|
|
142
|
+
(`model/ruml.py`, `model/ruml_result.py` and the test-facing TypedDicts in
|
|
143
|
+
`tests/ruml_dict.py` and `tests/ruml_result_dict.py`), plus those of other workspace
|
|
144
|
+
members, such as the spec-test descriptor model in
|
|
145
|
+
[ruml-spec-tests](../ruml-spec-tests). The RUML and RUML-Result schemas come from the
|
|
146
|
+
`ruml-schema` package, pinned exactly in `pyproject.toml`; run it whenever that pin
|
|
147
|
+
changes.
|
|
148
|
+
|
|
149
|
+
The script pre-processes `ruml.schema.json` before generation (via
|
|
150
|
+
`scripts/ruml_schema_pre_process.py`) to fix schema problems that the generator cannot
|
|
151
|
+
handle.
|
|
@@ -0,0 +1,73 @@
|
|
|
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, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright [yyyy] [name of copyright owner]
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
|
@@ -0,0 +1,73 @@
|
|
|
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, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright [yyyy] [name of copyright owner]
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ruml-parser
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Providing Pydantic models for RUML and RUML Result
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.14
|
|
8
|
+
Requires-Dist: email-validator<3,>=2.3.0
|
|
9
|
+
Requires-Dist: jsonschema[format-nongpl]<5,>=4.23.0
|
|
10
|
+
Requires-Dist: more-itertools<12,>=11.1.0
|
|
11
|
+
Requires-Dist: pydantic-core<3,>=2.41.1
|
|
12
|
+
Requires-Dist: pydantic<3,>=2.12.0
|
|
13
|
+
Requires-Dist: referencing<0.38,>=0.37.0
|
|
14
|
+
Requires-Dist: regress<2027,>=2026.9.1
|
|
15
|
+
Requires-Dist: ruml-schema==1.0.0
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# ruml-python
|
|
19
|
+
|
|
20
|
+
The Python parser for RUML, the Rulemapping Logic Format: Pydantic models, parsing and
|
|
21
|
+
validation. RUML is an open, JSON-based file format for the machine-executable
|
|
22
|
+
representation of legal decision logic; the specification, the schemas and the
|
|
23
|
+
conformance tests are in [ruml](https://github.com/Law-as-Code-Institute/ruml).
|
|
24
|
+
|
|
25
|
+
RUML-Result is the companion format for the outcome of evaluating a rulemap. This
|
|
26
|
+
library is the parsing/validation layer only — it has no evaluation logic.
|
|
27
|
+
|
|
28
|
+
## Installing
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pip install ruml-parser
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
It needs Python 3.14 or later.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Using RumlParser directly
|
|
39
|
+
|
|
40
|
+
As its name implies, `RumlParser` can be used to parse a rulemap from JSON text or a
|
|
41
|
+
decoded dict:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from ruml_parser import RumlParser
|
|
45
|
+
|
|
46
|
+
parser = RumlParser()
|
|
47
|
+
document = parser.parse_json(json_text) # or parse_dict(raw_dict)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`document.nodes` is a `dict[LexId, Node]`; lexId `"1"` is the rulemap root by convention
|
|
51
|
+
(RUML has no explicit root marker).
|
|
52
|
+
|
|
53
|
+
### Using Pydantic
|
|
54
|
+
|
|
55
|
+
For easy interoperability with Pydantic and related frameworks (e.g. FastAPI), we also
|
|
56
|
+
provide a way to annotate a Pydantic field (or FastAPI parameter) such that it takes
|
|
57
|
+
rulemap-structured data (e.g. from JSON) as input and contains a `RumlDocument` once
|
|
58
|
+
parsed:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from pydantic import BaseModel
|
|
62
|
+
from ruml_parser import ParsedRumlDocument
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class OuterModel(BaseModel):
|
|
66
|
+
document: ParsedRumlDocument # = Annotated[RumlDocument, ...]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Note that OpenAPI/JSON Schemas generated from `ParsedRumlDocument` will deviate from the
|
|
70
|
+
true RUML JSON Schema a bit due to being internally generated from a set of Pydantic
|
|
71
|
+
models that were themselves auto-generated from the original JSON Schema. Refer to
|
|
72
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
73
|
+
|
|
74
|
+
`ParsedRumlDocument` can also be used if the RUML document is at the root of the JSON to
|
|
75
|
+
be parsed (even though, in this case, one might as well use `RumlParser` directly):
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from pydantic import TypeAdapter
|
|
79
|
+
from ruml_parser import ParsedRumlDocument
|
|
80
|
+
|
|
81
|
+
document = TypeAdapter(ParsedRumlDocument).validate_python(raw_dict) # RumlDocument
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Capability extensions
|
|
85
|
+
|
|
86
|
+
The schema leaves the payloads of draft and third-party capabilities free-form, and so
|
|
87
|
+
does the internal model. To work with typed models of such a capability, implement a
|
|
88
|
+
`CapabilityExtension` for it and pass it to `RumlParser`. The parser then validates the
|
|
89
|
+
capability's payloads against the extension's JSON Schemas (combined with the RUML
|
|
90
|
+
schema), parses its root-level declaration and node-level entries into types of the
|
|
91
|
+
extension's, and lets it check the capability's cross-object rules on the result:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
parser = RumlParser(extensions=[MyCapabilityExtension()])
|
|
95
|
+
document = parser.parse_dict(raw_dict)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Naturally, `document` can't have any fields that are statically annotated as the types
|
|
99
|
+
associated with the extension, so helpers must be used for correctly-typed access:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
declaration = document.capabilities.extension(MyCapability) # MyCapability | None
|
|
103
|
+
entries = document.all_node_capabilities_of_type(MyNodeCapability) # (lexId, entry)s
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
Feedback is welcome as issues; pull requests are not accepted yet. See
|
|
109
|
+
[CONTRIBUTING.md](CONTRIBUTING.md).
|
|
110
|
+
|
|
111
|
+
For information relevant to development of ruml-parser itself, see
|
|
112
|
+
[DEVELOPMENT.md](DEVELOPMENT.md).
|
|
113
|
+
|
|
114
|
+
## Licence
|
|
115
|
+
|
|
116
|
+
Apache-2.0, see [LICENSE](LICENSE). Copyright 2026 Rulemapping Group GmbH.
|
|
117
|
+
|
|
118
|
+
Published by Law as Code Institut GmbH. RUML is a trademark of Rulemapping Group GmbH; an
|
|
119
|
+
application for registration as an EU trade mark has been filed.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# ruml-python
|
|
2
|
+
|
|
3
|
+
The Python parser for RUML, the Rulemapping Logic Format: Pydantic models, parsing and
|
|
4
|
+
validation. RUML is an open, JSON-based file format for the machine-executable
|
|
5
|
+
representation of legal decision logic; the specification, the schemas and the
|
|
6
|
+
conformance tests are in [ruml](https://github.com/Law-as-Code-Institute/ruml).
|
|
7
|
+
|
|
8
|
+
RUML-Result is the companion format for the outcome of evaluating a rulemap. This
|
|
9
|
+
library is the parsing/validation layer only — it has no evaluation logic.
|
|
10
|
+
|
|
11
|
+
## Installing
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pip install ruml-parser
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
It needs Python 3.14 or later.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Using RumlParser directly
|
|
22
|
+
|
|
23
|
+
As its name implies, `RumlParser` can be used to parse a rulemap from JSON text or a
|
|
24
|
+
decoded dict:
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from ruml_parser import RumlParser
|
|
28
|
+
|
|
29
|
+
parser = RumlParser()
|
|
30
|
+
document = parser.parse_json(json_text) # or parse_dict(raw_dict)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`document.nodes` is a `dict[LexId, Node]`; lexId `"1"` is the rulemap root by convention
|
|
34
|
+
(RUML has no explicit root marker).
|
|
35
|
+
|
|
36
|
+
### Using Pydantic
|
|
37
|
+
|
|
38
|
+
For easy interoperability with Pydantic and related frameworks (e.g. FastAPI), we also
|
|
39
|
+
provide a way to annotate a Pydantic field (or FastAPI parameter) such that it takes
|
|
40
|
+
rulemap-structured data (e.g. from JSON) as input and contains a `RumlDocument` once
|
|
41
|
+
parsed:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from pydantic import BaseModel
|
|
45
|
+
from ruml_parser import ParsedRumlDocument
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class OuterModel(BaseModel):
|
|
49
|
+
document: ParsedRumlDocument # = Annotated[RumlDocument, ...]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Note that OpenAPI/JSON Schemas generated from `ParsedRumlDocument` will deviate from the
|
|
53
|
+
true RUML JSON Schema a bit due to being internally generated from a set of Pydantic
|
|
54
|
+
models that were themselves auto-generated from the original JSON Schema. Refer to
|
|
55
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
56
|
+
|
|
57
|
+
`ParsedRumlDocument` can also be used if the RUML document is at the root of the JSON to
|
|
58
|
+
be parsed (even though, in this case, one might as well use `RumlParser` directly):
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from pydantic import TypeAdapter
|
|
62
|
+
from ruml_parser import ParsedRumlDocument
|
|
63
|
+
|
|
64
|
+
document = TypeAdapter(ParsedRumlDocument).validate_python(raw_dict) # RumlDocument
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Capability extensions
|
|
68
|
+
|
|
69
|
+
The schema leaves the payloads of draft and third-party capabilities free-form, and so
|
|
70
|
+
does the internal model. To work with typed models of such a capability, implement a
|
|
71
|
+
`CapabilityExtension` for it and pass it to `RumlParser`. The parser then validates the
|
|
72
|
+
capability's payloads against the extension's JSON Schemas (combined with the RUML
|
|
73
|
+
schema), parses its root-level declaration and node-level entries into types of the
|
|
74
|
+
extension's, and lets it check the capability's cross-object rules on the result:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
parser = RumlParser(extensions=[MyCapabilityExtension()])
|
|
78
|
+
document = parser.parse_dict(raw_dict)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Naturally, `document` can't have any fields that are statically annotated as the types
|
|
82
|
+
associated with the extension, so helpers must be used for correctly-typed access:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
declaration = document.capabilities.extension(MyCapability) # MyCapability | None
|
|
86
|
+
entries = document.all_node_capabilities_of_type(MyNodeCapability) # (lexId, entry)s
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Contributing
|
|
90
|
+
|
|
91
|
+
Feedback is welcome as issues; pull requests are not accepted yet. See
|
|
92
|
+
[CONTRIBUTING.md](CONTRIBUTING.md).
|
|
93
|
+
|
|
94
|
+
For information relevant to development of ruml-parser itself, see
|
|
95
|
+
[DEVELOPMENT.md](DEVELOPMENT.md).
|
|
96
|
+
|
|
97
|
+
## Licence
|
|
98
|
+
|
|
99
|
+
Apache-2.0, see [LICENSE](LICENSE). Copyright 2026 Rulemapping Group GmbH.
|
|
100
|
+
|
|
101
|
+
Published by Law as Code Institut GmbH. RUML is a trademark of Rulemapping Group GmbH; an
|
|
102
|
+
application for registration as an EU trade mark has been filed.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "ruml-parser"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Providing Pydantic models for RUML and RUML Result"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
requires-python = ">=3.14"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"pydantic>=2.12.0,<3",
|
|
10
|
+
# Comes with pydantic; declared for `core_schema`, which custom field types need.
|
|
11
|
+
"pydantic-core>=2.41.1,<3",
|
|
12
|
+
# EmailStr is only a usable annotation with this installed: pydantic raises
|
|
13
|
+
# at class definition time, so an import of the models fails without it.
|
|
14
|
+
"email-validator>=2.3.0,<3",
|
|
15
|
+
"jsonschema[format-nongpl]>=4.23.0,<5",
|
|
16
|
+
"referencing>=0.37.0,<0.38",
|
|
17
|
+
"more-itertools>=11.1.0,<12",
|
|
18
|
+
# ECMA-262 regular expressions, for `format: regex`.
|
|
19
|
+
"regress>=2026.9.1,<2027",
|
|
20
|
+
# The RUML and RUML-Result schemas. Pinned exactly: the models in
|
|
21
|
+
# ruml_parser/model/ are generated from this very version.
|
|
22
|
+
"ruml-schema==1.0.0",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["hatchling"]
|
|
27
|
+
build-backend = "hatchling.build"
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.wheel]
|
|
30
|
+
packages = ["ruml_parser"]
|
|
31
|
+
# The workspace's editable install still serves them to other packages' tests.
|
|
32
|
+
exclude = ["ruml_parser/tests"]
|
|
33
|
+
|
|
34
|
+
[tool.uv]
|
|
35
|
+
exclude-newer = "7 days"
|
|
36
|
+
# Our own package, pinned exactly above: the schemas of a RUML release have to be
|
|
37
|
+
# usable on the day of that release.
|
|
38
|
+
exclude-newer-package = { ruml-schema = false }
|
|
39
|
+
default-groups = ["dev"]
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"ruff>=0.16.0,<0.17",
|
|
44
|
+
]
|