flametrench-ids 0.3.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.
- flametrench_ids-0.3.0/LICENSE +201 -0
- flametrench_ids-0.3.0/NOTICE +9 -0
- flametrench_ids-0.3.0/PKG-INFO +89 -0
- flametrench_ids-0.3.0/README.md +61 -0
- flametrench_ids-0.3.0/pyproject.toml +50 -0
- flametrench_ids-0.3.0/setup.cfg +4 -0
- flametrench_ids-0.3.0/src/flametrench_ids/__init__.py +43 -0
- flametrench_ids-0.3.0/src/flametrench_ids/ids.py +259 -0
- flametrench_ids-0.3.0/src/flametrench_ids.egg-info/PKG-INFO +89 -0
- flametrench_ids-0.3.0/src/flametrench_ids.egg-info/SOURCES.txt +13 -0
- flametrench_ids-0.3.0/src/flametrench_ids.egg-info/dependency_links.txt +1 -0
- flametrench_ids-0.3.0/src/flametrench_ids.egg-info/requires.txt +6 -0
- flametrench_ids-0.3.0/src/flametrench_ids.egg-info/top_level.txt +1 -0
- flametrench_ids-0.3.0/tests/test_conformance.py +121 -0
- flametrench_ids-0.3.0/tests/test_ids.py +173 -0
|
@@ -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 describing the origin of the Work and
|
|
141
|
+
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 accept and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
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 2026 NDC Digital, LLC
|
|
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,9 @@
|
|
|
1
|
+
Flametrench
|
|
2
|
+
Copyright 2026 NDC Digital, LLC
|
|
3
|
+
|
|
4
|
+
This product includes software developed by NDC Digital, LLC and its
|
|
5
|
+
contributors. See individual source files for contribution attribution.
|
|
6
|
+
|
|
7
|
+
The Flametrench name and associated logos are pending trademarks of
|
|
8
|
+
NDC Digital, LLC and are used in accordance with the trademark policy
|
|
9
|
+
published at https://flametrench.dev.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flametrench-ids
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Flametrench v0.1 wire-format identifiers for Python: encode, decode, and generate prefixed UUIDv7 IDs.
|
|
5
|
+
Author: NDC Digital, LLC
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://flametrench.dev
|
|
8
|
+
Project-URL: Repository, https://github.com/flametrench/ids-python
|
|
9
|
+
Project-URL: Specification, https://github.com/flametrench/spec
|
|
10
|
+
Keywords: flametrench,ids,uuid,uuidv7,wire-format
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Requires-Dist: uuid7>=0.1.0; python_version < "3.14"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# flametrench-ids
|
|
30
|
+
|
|
31
|
+
[](https://github.com/flametrench/ids-python/actions/workflows/ci.yml)
|
|
32
|
+
|
|
33
|
+
Python SDK for the [Flametrench](https://github.com/flametrench/spec) wire-format identifier specification.
|
|
34
|
+
|
|
35
|
+
Flametrench identifiers are stable, opaque strings of the form `{type}_{32-hex}`, where the hex payload is a UUIDv7 (so generated IDs sort by creation time). The same identifiers travel unchanged across Node, PHP, Python, and Java SDKs.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from flametrench_ids import generate, decode, is_valid, type_of
|
|
39
|
+
|
|
40
|
+
generate("usr")
|
|
41
|
+
# → 'usr_0190f2a81b3c7abc8123456789abcdef'
|
|
42
|
+
|
|
43
|
+
decode("usr_0190f2a81b3c7abc8123456789abcdef")
|
|
44
|
+
# → DecodedId(type='usr', uuid='0190f2a8-1b3c-7abc-8123-456789abcdef')
|
|
45
|
+
|
|
46
|
+
is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "usr") # → True
|
|
47
|
+
is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "org") # → False
|
|
48
|
+
|
|
49
|
+
type_of("usr_0190f2a81b3c7abc8123456789abcdef") # → 'usr'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install flametrench-ids
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Requires Python 3.11+. UUIDv7 generation uses `uuid.uuid7()` from the stdlib on Python 3.14+, falling back to the [`uuid7`](https://pypi.org/project/uuid7/) package on 3.11–3.13. Both produce identical RFC 9562 v7 layouts; the conformance suite verifies this.
|
|
59
|
+
|
|
60
|
+
## Registered type prefixes
|
|
61
|
+
|
|
62
|
+
| Prefix | Meaning | Spec version |
|
|
63
|
+
| ------- | ---------------------- | ------------ |
|
|
64
|
+
| `usr` | user | v0.1 |
|
|
65
|
+
| `org` | organization | v0.1 |
|
|
66
|
+
| `mem` | membership | v0.1 |
|
|
67
|
+
| `inv` | invitation | v0.1 |
|
|
68
|
+
| `ses` | session | v0.1 |
|
|
69
|
+
| `cred` | credential | v0.1 |
|
|
70
|
+
| `tup` | authorization tuple | v0.1 |
|
|
71
|
+
| `mfa` | MFA factor | v0.2 |
|
|
72
|
+
| `shr` | share token | v0.2 |
|
|
73
|
+
|
|
74
|
+
The registry is normative; see [docs/ids.md](https://github.com/flametrench/spec/blob/main/docs/ids.md) for the full rules.
|
|
75
|
+
|
|
76
|
+
## Conformance
|
|
77
|
+
|
|
78
|
+
`flametrench-ids` runs the same fixture corpus that gates `@flametrench/ids` (Node) and `flametrench/ids` (PHP). All 48 MUST-level fixtures from `spec/conformance/fixtures/ids/` pass on every release; the test suite vendors the fixtures and compares them to the upstream spec repo via CI.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# In a checked-out copy:
|
|
82
|
+
pytest
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Apache-2.0. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
|
88
|
+
|
|
89
|
+
Copyright 2026 NDC Digital, LLC.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# flametrench-ids
|
|
2
|
+
|
|
3
|
+
[](https://github.com/flametrench/ids-python/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
Python SDK for the [Flametrench](https://github.com/flametrench/spec) wire-format identifier specification.
|
|
6
|
+
|
|
7
|
+
Flametrench identifiers are stable, opaque strings of the form `{type}_{32-hex}`, where the hex payload is a UUIDv7 (so generated IDs sort by creation time). The same identifiers travel unchanged across Node, PHP, Python, and Java SDKs.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from flametrench_ids import generate, decode, is_valid, type_of
|
|
11
|
+
|
|
12
|
+
generate("usr")
|
|
13
|
+
# → 'usr_0190f2a81b3c7abc8123456789abcdef'
|
|
14
|
+
|
|
15
|
+
decode("usr_0190f2a81b3c7abc8123456789abcdef")
|
|
16
|
+
# → DecodedId(type='usr', uuid='0190f2a8-1b3c-7abc-8123-456789abcdef')
|
|
17
|
+
|
|
18
|
+
is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "usr") # → True
|
|
19
|
+
is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "org") # → False
|
|
20
|
+
|
|
21
|
+
type_of("usr_0190f2a81b3c7abc8123456789abcdef") # → 'usr'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install flametrench-ids
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Requires Python 3.11+. UUIDv7 generation uses `uuid.uuid7()` from the stdlib on Python 3.14+, falling back to the [`uuid7`](https://pypi.org/project/uuid7/) package on 3.11–3.13. Both produce identical RFC 9562 v7 layouts; the conformance suite verifies this.
|
|
31
|
+
|
|
32
|
+
## Registered type prefixes
|
|
33
|
+
|
|
34
|
+
| Prefix | Meaning | Spec version |
|
|
35
|
+
| ------- | ---------------------- | ------------ |
|
|
36
|
+
| `usr` | user | v0.1 |
|
|
37
|
+
| `org` | organization | v0.1 |
|
|
38
|
+
| `mem` | membership | v0.1 |
|
|
39
|
+
| `inv` | invitation | v0.1 |
|
|
40
|
+
| `ses` | session | v0.1 |
|
|
41
|
+
| `cred` | credential | v0.1 |
|
|
42
|
+
| `tup` | authorization tuple | v0.1 |
|
|
43
|
+
| `mfa` | MFA factor | v0.2 |
|
|
44
|
+
| `shr` | share token | v0.2 |
|
|
45
|
+
|
|
46
|
+
The registry is normative; see [docs/ids.md](https://github.com/flametrench/spec/blob/main/docs/ids.md) for the full rules.
|
|
47
|
+
|
|
48
|
+
## Conformance
|
|
49
|
+
|
|
50
|
+
`flametrench-ids` runs the same fixture corpus that gates `@flametrench/ids` (Node) and `flametrench/ids` (PHP). All 48 MUST-level fixtures from `spec/conformance/fixtures/ids/` pass on every release; the test suite vendors the fixtures and compares them to the upstream spec repo via CI.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# In a checked-out copy:
|
|
54
|
+
pytest
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
Apache-2.0. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
|
60
|
+
|
|
61
|
+
Copyright 2026 NDC Digital, LLC.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "flametrench-ids"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Flametrench v0.1 wire-format identifiers for Python: encode, decode, and generate prefixed UUIDv7 IDs."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "NDC Digital, LLC" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["flametrench", "ids", "uuid", "uuidv7", "wire-format"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: Apache Software License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
# uuid7 is available in stdlib as `uuid.uuid7()` from Python 3.14+. For
|
|
29
|
+
# 3.11–3.13 we fall back to the `uuid7` package, which produces the same
|
|
30
|
+
# RFC 9562 v7 layout. Either path produces identical wire-format output;
|
|
31
|
+
# the conformance fixtures verify this.
|
|
32
|
+
"uuid7>=0.1.0;python_version<'3.14'",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = [
|
|
37
|
+
"pytest>=8.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://flametrench.dev"
|
|
42
|
+
Repository = "https://github.com/flametrench/ids-python"
|
|
43
|
+
Specification = "https://github.com/flametrench/spec"
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.packages.find]
|
|
46
|
+
where = ["src"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
testpaths = ["tests"]
|
|
50
|
+
python_files = ["test_*.py", "*_test.py"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright 2026 NDC Digital, LLC
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""flametrench-ids — wire-format identifiers for Python.
|
|
5
|
+
|
|
6
|
+
The spec-normative identifier layer for Flametrench v0.1. See the upstream
|
|
7
|
+
specification at https://github.com/flametrench/spec/blob/main/docs/ids.md.
|
|
8
|
+
|
|
9
|
+
The wire format is ``{type}_{32-hex}``. Generated IDs use UUIDv7 so they
|
|
10
|
+
sort by creation time. The same fixtures that exercise the Node and PHP
|
|
11
|
+
SDKs run against this package; cross-language interop is enforced by the
|
|
12
|
+
test suite, not aspiration.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from .ids import (
|
|
16
|
+
TYPES,
|
|
17
|
+
DecodedId,
|
|
18
|
+
InvalidIdError,
|
|
19
|
+
InvalidTypeError,
|
|
20
|
+
decode,
|
|
21
|
+
decode_any,
|
|
22
|
+
encode,
|
|
23
|
+
generate,
|
|
24
|
+
is_valid,
|
|
25
|
+
is_valid_shape,
|
|
26
|
+
type_of,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"TYPES",
|
|
31
|
+
"DecodedId",
|
|
32
|
+
"InvalidIdError",
|
|
33
|
+
"InvalidTypeError",
|
|
34
|
+
"decode",
|
|
35
|
+
"decode_any",
|
|
36
|
+
"encode",
|
|
37
|
+
"generate",
|
|
38
|
+
"is_valid",
|
|
39
|
+
"is_valid_shape",
|
|
40
|
+
"type_of",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
__version__ = "0.3.0"
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# Copyright 2026 NDC Digital, LLC
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""Core identifier encode/decode + generation logic.
|
|
5
|
+
|
|
6
|
+
Mirrors @flametrench/ids (Node) and flametrench/ids (PHP) exactly. The same
|
|
7
|
+
spec fixtures verify all three implementations.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
import uuid
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
|
|
17
|
+
# UUIDv7 source. Python 3.14 added uuid.uuid7 to the stdlib; older versions
|
|
18
|
+
# use the `uuid7` package, which produces an identical RFC 9562 v7 layout.
|
|
19
|
+
# (PyPI's `uuid7` distribution publishes its module as `uuid_extensions` —
|
|
20
|
+
# the dist name and module name don't match.)
|
|
21
|
+
if sys.version_info >= (3, 14):
|
|
22
|
+
def _uuid7() -> uuid.UUID:
|
|
23
|
+
return uuid.uuid7()
|
|
24
|
+
else:
|
|
25
|
+
from uuid_extensions import uuid7 as _uuid7_str
|
|
26
|
+
|
|
27
|
+
def _uuid7() -> uuid.UUID:
|
|
28
|
+
return uuid.UUID(str(_uuid7_str()))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class InvalidIdError(ValueError):
|
|
32
|
+
"""Raised when a string is not a syntactically valid wire-format ID."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class InvalidTypeError(ValueError):
|
|
36
|
+
"""Raised when a type prefix is not in the registered set."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Registered type prefixes for Flametrench v0.1.
|
|
40
|
+
#
|
|
41
|
+
# Keep this map synchronized with the Flametrench specification's reserved
|
|
42
|
+
# prefix registry at https://github.com/flametrench/spec/blob/main/docs/ids.md.
|
|
43
|
+
# Parallel implementations (Node, PHP, Java) use the same prefixes.
|
|
44
|
+
TYPES: dict[str, str] = {
|
|
45
|
+
"usr": "user",
|
|
46
|
+
"org": "organization",
|
|
47
|
+
"mem": "membership",
|
|
48
|
+
"inv": "invitation",
|
|
49
|
+
"ses": "session",
|
|
50
|
+
"cred": "credential",
|
|
51
|
+
"tup": "authorization_tuple",
|
|
52
|
+
# v0.2 — Proposed (ADR 0008)
|
|
53
|
+
"mfa": "mfa_factor",
|
|
54
|
+
# v0.2 — Proposed (ADR 0012)
|
|
55
|
+
"shr": "share_token",
|
|
56
|
+
# v0.3 — Active (ADR 0016)
|
|
57
|
+
"pat": "personal_access_token",
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True)
|
|
62
|
+
class DecodedId:
|
|
63
|
+
"""The shape returned by :func:`decode`.
|
|
64
|
+
|
|
65
|
+
``uuid`` is the canonical 8-4-4-4-12 dashed form (RFC 4122 / 9562).
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
type: str
|
|
69
|
+
uuid: str
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
_HEX_PAYLOAD_LENGTH = 32
|
|
73
|
+
_HEX_PATTERN = re.compile(r"^[0-9a-f]{32}$")
|
|
74
|
+
_VERSION_NIBBLE_PATTERN = re.compile(r"^[1-8]$")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _assert_type(type_: str) -> None:
|
|
78
|
+
if type_ not in TYPES:
|
|
79
|
+
registered = ", ".join(TYPES.keys())
|
|
80
|
+
raise InvalidTypeError(
|
|
81
|
+
f"Unregistered type prefix: '{type_}'. Registered prefixes: {registered}.",
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _is_valid_uuid_string(value: str) -> bool:
|
|
86
|
+
"""Match the JavaScript ``uuid.validate`` semantics for wire input.
|
|
87
|
+
|
|
88
|
+
Accepts canonical 8-4-4-4-12 hex with hyphens, case-insensitive.
|
|
89
|
+
Returns False for anything else (including non-RFC-4122 layouts).
|
|
90
|
+
"""
|
|
91
|
+
try:
|
|
92
|
+
uuid.UUID(value)
|
|
93
|
+
except (ValueError, AttributeError, TypeError):
|
|
94
|
+
return False
|
|
95
|
+
# ``uuid.UUID`` accepts URN, braces, and 32-char hex without dashes; we
|
|
96
|
+
# require the canonical dashed form to match the Node/PHP behavior.
|
|
97
|
+
if len(value) != 36:
|
|
98
|
+
return False
|
|
99
|
+
if value[8] != "-" or value[13] != "-" or value[18] != "-" or value[23] != "-":
|
|
100
|
+
return False
|
|
101
|
+
return True
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def encode(type_: str, uuid_str: str) -> str:
|
|
105
|
+
"""Encode a type and UUID into Flametrench wire format.
|
|
106
|
+
|
|
107
|
+
>>> encode("usr", "0190f2a8-1b3c-7abc-8123-456789abcdef")
|
|
108
|
+
'usr_0190f2a81b3c7abc8123456789abcdef'
|
|
109
|
+
|
|
110
|
+
:raises InvalidTypeError: If the type prefix is not registered.
|
|
111
|
+
:raises InvalidIdError: If the UUID is not a valid UUID string.
|
|
112
|
+
"""
|
|
113
|
+
_assert_type(type_)
|
|
114
|
+
if not _is_valid_uuid_string(uuid_str):
|
|
115
|
+
raise InvalidIdError(f"Value is not a valid UUID: {uuid_str}")
|
|
116
|
+
hex_payload = uuid_str.replace("-", "").lower()
|
|
117
|
+
return f"{type_}_{hex_payload}"
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def decode(id_: str) -> DecodedId:
|
|
121
|
+
"""Decode a Flametrench wire-format ID into its type and canonical UUID.
|
|
122
|
+
|
|
123
|
+
>>> decode("usr_0190f2a81b3c7abc8123456789abcdef")
|
|
124
|
+
DecodedId(type='usr', uuid='0190f2a8-1b3c-7abc-8123-456789abcdef')
|
|
125
|
+
|
|
126
|
+
:raises InvalidIdError: If the ID is malformed.
|
|
127
|
+
:raises InvalidTypeError: If the type prefix is not registered.
|
|
128
|
+
"""
|
|
129
|
+
if not isinstance(id_, str):
|
|
130
|
+
raise InvalidIdError(f"ID must be a string: {id_!r}")
|
|
131
|
+
separator = id_.find("_")
|
|
132
|
+
if separator == -1:
|
|
133
|
+
raise InvalidIdError(f"ID missing type separator: {id_}")
|
|
134
|
+
|
|
135
|
+
type_ = id_[:separator]
|
|
136
|
+
hex_payload = id_[separator + 1 :]
|
|
137
|
+
|
|
138
|
+
_assert_type(type_)
|
|
139
|
+
|
|
140
|
+
if len(hex_payload) != _HEX_PAYLOAD_LENGTH or not _HEX_PATTERN.match(hex_payload):
|
|
141
|
+
raise InvalidIdError(f"ID payload is not 32 lowercase hex characters: {id_}")
|
|
142
|
+
|
|
143
|
+
# Version nibble (13th hex char, 0-indexed position 12) must be 1-8.
|
|
144
|
+
# This rejects the Nil UUID (v0) and Max UUID (v15/f), which are not
|
|
145
|
+
# meaningful identifiers in the Flametrench wire format.
|
|
146
|
+
if not _VERSION_NIBBLE_PATTERN.match(hex_payload[12]):
|
|
147
|
+
raise InvalidIdError(f"ID payload is not a valid UUID: {id_}")
|
|
148
|
+
|
|
149
|
+
canonical = "-".join(
|
|
150
|
+
[
|
|
151
|
+
hex_payload[0:8],
|
|
152
|
+
hex_payload[8:12],
|
|
153
|
+
hex_payload[12:16],
|
|
154
|
+
hex_payload[16:20],
|
|
155
|
+
hex_payload[20:32],
|
|
156
|
+
]
|
|
157
|
+
)
|
|
158
|
+
return DecodedId(type=type_, uuid=canonical)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def decode_any(id_: str) -> DecodedId:
|
|
162
|
+
"""Decode a Flametrench wire-format ID without checking the registered-type set.
|
|
163
|
+
|
|
164
|
+
Use this for backend storage adapters that need to convert wire-format
|
|
165
|
+
object IDs to canonical UUIDs without knowing the application's
|
|
166
|
+
domain types in advance — e.g., when an authz tuple has
|
|
167
|
+
``object_type='proj'`` and ``object_id='proj_0190f2a8...'``.
|
|
168
|
+
|
|
169
|
+
Validates wire-format shape (separator, 32-char lowercase hex, version
|
|
170
|
+
nibble 1–8). Does NOT consult :data:`TYPES`. See ``spec/docs/ids.md``.
|
|
171
|
+
|
|
172
|
+
:raises InvalidIdError: If the ID's structure is malformed. Never
|
|
173
|
+
raises :class:`InvalidTypeError`.
|
|
174
|
+
"""
|
|
175
|
+
if not isinstance(id_, str):
|
|
176
|
+
raise InvalidIdError(f"ID must be a string: {id_!r}")
|
|
177
|
+
separator = id_.find("_")
|
|
178
|
+
if separator == -1:
|
|
179
|
+
raise InvalidIdError(f"ID missing type separator: {id_}")
|
|
180
|
+
|
|
181
|
+
type_ = id_[:separator]
|
|
182
|
+
hex_payload = id_[separator + 1 :]
|
|
183
|
+
|
|
184
|
+
if len(type_) == 0:
|
|
185
|
+
raise InvalidIdError(f"ID has empty type prefix: {id_}")
|
|
186
|
+
|
|
187
|
+
if len(hex_payload) != _HEX_PAYLOAD_LENGTH or not _HEX_PATTERN.match(hex_payload):
|
|
188
|
+
raise InvalidIdError(f"ID payload is not 32 lowercase hex characters: {id_}")
|
|
189
|
+
|
|
190
|
+
if not _VERSION_NIBBLE_PATTERN.match(hex_payload[12]):
|
|
191
|
+
raise InvalidIdError(f"ID payload is not a valid UUID: {id_}")
|
|
192
|
+
|
|
193
|
+
canonical = "-".join(
|
|
194
|
+
[
|
|
195
|
+
hex_payload[0:8],
|
|
196
|
+
hex_payload[8:12],
|
|
197
|
+
hex_payload[12:16],
|
|
198
|
+
hex_payload[16:20],
|
|
199
|
+
hex_payload[20:32],
|
|
200
|
+
]
|
|
201
|
+
)
|
|
202
|
+
return DecodedId(type=type_, uuid=canonical)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def is_valid_shape(id_: str) -> bool:
|
|
206
|
+
"""Predicate counterpart to :func:`decode_any`.
|
|
207
|
+
|
|
208
|
+
Returns true for any well-formed wire-format ID regardless of
|
|
209
|
+
registry membership. Use this when validating input from external
|
|
210
|
+
systems that may legitimately reference application-defined object
|
|
211
|
+
types.
|
|
212
|
+
"""
|
|
213
|
+
try:
|
|
214
|
+
decode_any(id_)
|
|
215
|
+
except InvalidIdError:
|
|
216
|
+
return False
|
|
217
|
+
return True
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def is_valid(id_: str, expected_type: str | None = None) -> bool:
|
|
221
|
+
"""Check whether a string is a valid Flametrench wire-format ID.
|
|
222
|
+
|
|
223
|
+
Optionally asserts the ID is of a specific type.
|
|
224
|
+
|
|
225
|
+
>>> is_valid("usr_0190f2a81b3c7abc8123456789abcdef")
|
|
226
|
+
True
|
|
227
|
+
>>> is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "org")
|
|
228
|
+
False
|
|
229
|
+
"""
|
|
230
|
+
try:
|
|
231
|
+
decoded = decode(id_)
|
|
232
|
+
except (InvalidIdError, InvalidTypeError):
|
|
233
|
+
return False
|
|
234
|
+
if expected_type is not None and decoded.type != expected_type:
|
|
235
|
+
return False
|
|
236
|
+
return True
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def type_of(id_: str) -> str:
|
|
240
|
+
"""Extract the type prefix from a wire-format ID.
|
|
241
|
+
|
|
242
|
+
:raises InvalidIdError: If the ID is malformed.
|
|
243
|
+
:raises InvalidTypeError: If the type prefix is not registered.
|
|
244
|
+
"""
|
|
245
|
+
return decode(id_).type
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def generate(type_: str) -> str:
|
|
249
|
+
"""Generate a fresh wire-format ID of the given type.
|
|
250
|
+
|
|
251
|
+
Uses UUIDv7 so generated IDs are sortable by creation time.
|
|
252
|
+
|
|
253
|
+
>>> generate("usr") # doctest: +SKIP
|
|
254
|
+
'usr_0190f2a81b3c7abc8123456789abcdef'
|
|
255
|
+
|
|
256
|
+
:raises InvalidTypeError: If the type prefix is not registered.
|
|
257
|
+
"""
|
|
258
|
+
_assert_type(type_)
|
|
259
|
+
return encode(type_, str(_uuid7()))
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flametrench-ids
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Flametrench v0.1 wire-format identifiers for Python: encode, decode, and generate prefixed UUIDv7 IDs.
|
|
5
|
+
Author: NDC Digital, LLC
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://flametrench.dev
|
|
8
|
+
Project-URL: Repository, https://github.com/flametrench/ids-python
|
|
9
|
+
Project-URL: Specification, https://github.com/flametrench/spec
|
|
10
|
+
Keywords: flametrench,ids,uuid,uuidv7,wire-format
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Requires-Dist: uuid7>=0.1.0; python_version < "3.14"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# flametrench-ids
|
|
30
|
+
|
|
31
|
+
[](https://github.com/flametrench/ids-python/actions/workflows/ci.yml)
|
|
32
|
+
|
|
33
|
+
Python SDK for the [Flametrench](https://github.com/flametrench/spec) wire-format identifier specification.
|
|
34
|
+
|
|
35
|
+
Flametrench identifiers are stable, opaque strings of the form `{type}_{32-hex}`, where the hex payload is a UUIDv7 (so generated IDs sort by creation time). The same identifiers travel unchanged across Node, PHP, Python, and Java SDKs.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from flametrench_ids import generate, decode, is_valid, type_of
|
|
39
|
+
|
|
40
|
+
generate("usr")
|
|
41
|
+
# → 'usr_0190f2a81b3c7abc8123456789abcdef'
|
|
42
|
+
|
|
43
|
+
decode("usr_0190f2a81b3c7abc8123456789abcdef")
|
|
44
|
+
# → DecodedId(type='usr', uuid='0190f2a8-1b3c-7abc-8123-456789abcdef')
|
|
45
|
+
|
|
46
|
+
is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "usr") # → True
|
|
47
|
+
is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "org") # → False
|
|
48
|
+
|
|
49
|
+
type_of("usr_0190f2a81b3c7abc8123456789abcdef") # → 'usr'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install flametrench-ids
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Requires Python 3.11+. UUIDv7 generation uses `uuid.uuid7()` from the stdlib on Python 3.14+, falling back to the [`uuid7`](https://pypi.org/project/uuid7/) package on 3.11–3.13. Both produce identical RFC 9562 v7 layouts; the conformance suite verifies this.
|
|
59
|
+
|
|
60
|
+
## Registered type prefixes
|
|
61
|
+
|
|
62
|
+
| Prefix | Meaning | Spec version |
|
|
63
|
+
| ------- | ---------------------- | ------------ |
|
|
64
|
+
| `usr` | user | v0.1 |
|
|
65
|
+
| `org` | organization | v0.1 |
|
|
66
|
+
| `mem` | membership | v0.1 |
|
|
67
|
+
| `inv` | invitation | v0.1 |
|
|
68
|
+
| `ses` | session | v0.1 |
|
|
69
|
+
| `cred` | credential | v0.1 |
|
|
70
|
+
| `tup` | authorization tuple | v0.1 |
|
|
71
|
+
| `mfa` | MFA factor | v0.2 |
|
|
72
|
+
| `shr` | share token | v0.2 |
|
|
73
|
+
|
|
74
|
+
The registry is normative; see [docs/ids.md](https://github.com/flametrench/spec/blob/main/docs/ids.md) for the full rules.
|
|
75
|
+
|
|
76
|
+
## Conformance
|
|
77
|
+
|
|
78
|
+
`flametrench-ids` runs the same fixture corpus that gates `@flametrench/ids` (Node) and `flametrench/ids` (PHP). All 48 MUST-level fixtures from `spec/conformance/fixtures/ids/` pass on every release; the test suite vendors the fixtures and compares them to the upstream spec repo via CI.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# In a checked-out copy:
|
|
82
|
+
pytest
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Apache-2.0. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
|
88
|
+
|
|
89
|
+
Copyright 2026 NDC Digital, LLC.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
NOTICE
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/flametrench_ids/__init__.py
|
|
6
|
+
src/flametrench_ids/ids.py
|
|
7
|
+
src/flametrench_ids.egg-info/PKG-INFO
|
|
8
|
+
src/flametrench_ids.egg-info/SOURCES.txt
|
|
9
|
+
src/flametrench_ids.egg-info/dependency_links.txt
|
|
10
|
+
src/flametrench_ids.egg-info/requires.txt
|
|
11
|
+
src/flametrench_ids.egg-info/top_level.txt
|
|
12
|
+
tests/test_conformance.py
|
|
13
|
+
tests/test_ids.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flametrench_ids
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Copyright 2026 NDC Digital, LLC
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""Flametrench v0.1 conformance suite — Python harness.
|
|
5
|
+
|
|
6
|
+
Exercises the IDs capability against the fixture corpus vendored from
|
|
7
|
+
github.com/flametrench/spec/conformance/fixtures/ids/. The fixtures
|
|
8
|
+
under tests/conformance/fixtures/ are a snapshot; the drift-check CI
|
|
9
|
+
job verifies they match the upstream spec repo.
|
|
10
|
+
|
|
11
|
+
Every test name is "[{fixture_id}] {description}" so failures point
|
|
12
|
+
directly at a spec-linked fixture. Do not modify test behavior here;
|
|
13
|
+
if a fixture needs to change, change it in the spec repo and re-vendor.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
import pytest
|
|
23
|
+
|
|
24
|
+
from flametrench_ids import (
|
|
25
|
+
InvalidIdError,
|
|
26
|
+
InvalidTypeError,
|
|
27
|
+
decode,
|
|
28
|
+
encode,
|
|
29
|
+
is_valid,
|
|
30
|
+
type_of,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
_FIXTURES_DIR = Path(__file__).parent / "conformance" / "fixtures"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _load_fixture(relative_path: str) -> dict[str, Any]:
|
|
37
|
+
raw = (_FIXTURES_DIR / relative_path).read_text(encoding="utf-8")
|
|
38
|
+
return json.loads(raw)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _error_class_for_spec_name(name: str) -> type[Exception]:
|
|
42
|
+
if name == "InvalidIdError":
|
|
43
|
+
return InvalidIdError
|
|
44
|
+
if name == "InvalidTypeError":
|
|
45
|
+
return InvalidTypeError
|
|
46
|
+
raise RuntimeError(f"Unknown spec error name: {name}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _ids_param(relative_path: str) -> list[Any]:
|
|
50
|
+
fixture = _load_fixture(relative_path)
|
|
51
|
+
return [
|
|
52
|
+
pytest.param(t, id=t["id"])
|
|
53
|
+
for t in fixture["tests"]
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# ─── ids.encode ───
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.mark.parametrize("test_case", _ids_param("ids/encode.json"))
|
|
61
|
+
def test_encode_conformance(test_case: dict[str, Any]) -> None:
|
|
62
|
+
inp = test_case["input"]
|
|
63
|
+
expected = test_case["expected"]
|
|
64
|
+
if "error" in expected:
|
|
65
|
+
ctor = _error_class_for_spec_name(expected["error"])
|
|
66
|
+
with pytest.raises(ctor):
|
|
67
|
+
encode(inp["type"], inp["uuid"])
|
|
68
|
+
else:
|
|
69
|
+
assert encode(inp["type"], inp["uuid"]) == expected["result"]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# ─── ids.decode (positive + round-trip) ───
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.parametrize("test_case", _ids_param("ids/decode.json"))
|
|
76
|
+
def test_decode_positive_conformance(test_case: dict[str, Any]) -> None:
|
|
77
|
+
inp = test_case["input"]
|
|
78
|
+
expected = test_case["expected"]["result"]
|
|
79
|
+
decoded = decode(inp["id"])
|
|
80
|
+
assert decoded.type == expected["type"]
|
|
81
|
+
assert decoded.uuid == expected["uuid"]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# ─── ids.decode (rejection) ───
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.parametrize("test_case", _ids_param("ids/decode-reject.json"))
|
|
88
|
+
def test_decode_rejection_conformance(test_case: dict[str, Any]) -> None:
|
|
89
|
+
inp = test_case["input"]
|
|
90
|
+
ctor = _error_class_for_spec_name(test_case["expected"]["error"])
|
|
91
|
+
with pytest.raises(ctor):
|
|
92
|
+
decode(inp["id"])
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# ─── ids.is_valid ───
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@pytest.mark.parametrize("test_case", _ids_param("ids/is-valid.json"))
|
|
99
|
+
def test_is_valid_conformance(test_case: dict[str, Any]) -> None:
|
|
100
|
+
inp = test_case["input"]
|
|
101
|
+
expected = test_case["expected"]["result"]
|
|
102
|
+
if "expected_type" in inp:
|
|
103
|
+
result = is_valid(inp["id"], inp["expected_type"])
|
|
104
|
+
else:
|
|
105
|
+
result = is_valid(inp["id"])
|
|
106
|
+
assert result is expected
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ─── ids.type_of ───
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@pytest.mark.parametrize("test_case", _ids_param("ids/type-of.json"))
|
|
113
|
+
def test_type_of_conformance(test_case: dict[str, Any]) -> None:
|
|
114
|
+
inp = test_case["input"]
|
|
115
|
+
expected = test_case["expected"]
|
|
116
|
+
if "error" in expected:
|
|
117
|
+
ctor = _error_class_for_spec_name(expected["error"])
|
|
118
|
+
with pytest.raises(ctor):
|
|
119
|
+
type_of(inp["id"])
|
|
120
|
+
else:
|
|
121
|
+
assert type_of(inp["id"]) == expected["result"]
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Copyright 2026 NDC Digital, LLC
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""Unit tests for the Python ids API.
|
|
5
|
+
|
|
6
|
+
Mirrors the Node + PHP unit tests so behavior is consistent across SDKs.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
from flametrench_ids import (
|
|
16
|
+
InvalidIdError,
|
|
17
|
+
InvalidTypeError,
|
|
18
|
+
TYPES,
|
|
19
|
+
decode,
|
|
20
|
+
decode_any,
|
|
21
|
+
encode,
|
|
22
|
+
generate,
|
|
23
|
+
is_valid,
|
|
24
|
+
is_valid_shape,
|
|
25
|
+
type_of,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
SAMPLE_HEX = "0190f2a81b3c7abc8123456789abcdef"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TestEncode:
|
|
32
|
+
def test_encodes_a_canonical_uuid(self) -> None:
|
|
33
|
+
result = encode("usr", "0190f2a8-1b3c-7abc-8123-456789abcdef")
|
|
34
|
+
assert result == "usr_0190f2a81b3c7abc8123456789abcdef"
|
|
35
|
+
|
|
36
|
+
def test_uppercase_uuid_input_is_lowercased(self) -> None:
|
|
37
|
+
result = encode("org", "0190F2A8-1B3C-7ABC-8123-456789ABCDEF")
|
|
38
|
+
assert result == "org_0190f2a81b3c7abc8123456789abcdef"
|
|
39
|
+
|
|
40
|
+
def test_unknown_type_prefix_raises(self) -> None:
|
|
41
|
+
with pytest.raises(InvalidTypeError):
|
|
42
|
+
encode("foo", "0190f2a8-1b3c-7abc-8123-456789abcdef")
|
|
43
|
+
|
|
44
|
+
def test_malformed_uuid_raises(self) -> None:
|
|
45
|
+
with pytest.raises(InvalidIdError):
|
|
46
|
+
encode("usr", "not-a-uuid")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TestDecode:
|
|
50
|
+
def test_round_trip(self) -> None:
|
|
51
|
+
original = "0190f2a8-1b3c-7abc-8123-456789abcdef"
|
|
52
|
+
encoded = encode("usr", original)
|
|
53
|
+
decoded = decode(encoded)
|
|
54
|
+
assert decoded.type == "usr"
|
|
55
|
+
assert decoded.uuid == original
|
|
56
|
+
|
|
57
|
+
def test_rejects_missing_separator(self) -> None:
|
|
58
|
+
with pytest.raises(InvalidIdError):
|
|
59
|
+
decode("usr0190f2a81b3c7abc8123456789abcdef")
|
|
60
|
+
|
|
61
|
+
def test_rejects_uppercase_hex(self) -> None:
|
|
62
|
+
with pytest.raises(InvalidIdError):
|
|
63
|
+
decode("usr_0190F2A81B3C7ABC8123456789ABCDEF")
|
|
64
|
+
|
|
65
|
+
def test_rejects_unregistered_prefix(self) -> None:
|
|
66
|
+
with pytest.raises(InvalidTypeError):
|
|
67
|
+
decode("foo_0190f2a81b3c7abc8123456789abcdef")
|
|
68
|
+
|
|
69
|
+
def test_rejects_nil_uuid(self) -> None:
|
|
70
|
+
# All-zeros: version nibble is 0
|
|
71
|
+
with pytest.raises(InvalidIdError):
|
|
72
|
+
decode("usr_00000000000000000000000000000000")
|
|
73
|
+
|
|
74
|
+
def test_rejects_max_uuid(self) -> None:
|
|
75
|
+
# All f's: version nibble is f (15)
|
|
76
|
+
with pytest.raises(InvalidIdError):
|
|
77
|
+
decode("usr_ffffffffffffffffffffffffffffffff")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class TestIsValid:
|
|
81
|
+
def test_returns_true_for_valid_id(self) -> None:
|
|
82
|
+
assert is_valid("usr_0190f2a81b3c7abc8123456789abcdef")
|
|
83
|
+
|
|
84
|
+
def test_returns_false_for_unregistered_prefix(self) -> None:
|
|
85
|
+
assert not is_valid("foo_0190f2a81b3c7abc8123456789abcdef")
|
|
86
|
+
|
|
87
|
+
def test_type_check_returns_true_when_matches(self) -> None:
|
|
88
|
+
assert is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "usr")
|
|
89
|
+
|
|
90
|
+
def test_type_check_returns_false_when_mismatched(self) -> None:
|
|
91
|
+
assert not is_valid("usr_0190f2a81b3c7abc8123456789abcdef", "org")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class TestTypeOf:
|
|
95
|
+
def test_returns_the_type_prefix(self) -> None:
|
|
96
|
+
assert type_of("usr_0190f2a81b3c7abc8123456789abcdef") == "usr"
|
|
97
|
+
|
|
98
|
+
def test_raises_for_malformed(self) -> None:
|
|
99
|
+
with pytest.raises(InvalidIdError):
|
|
100
|
+
type_of("not an id")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TestGenerate:
|
|
104
|
+
def test_produces_a_well_formed_id_for_each_registered_type(self) -> None:
|
|
105
|
+
pattern = re.compile(r"^[a-z]+_[0-9a-f]{32}$")
|
|
106
|
+
for type_ in TYPES:
|
|
107
|
+
id_ = generate(type_)
|
|
108
|
+
assert pattern.match(id_)
|
|
109
|
+
assert is_valid(id_, type_)
|
|
110
|
+
|
|
111
|
+
def test_unregistered_type_raises(self) -> None:
|
|
112
|
+
with pytest.raises(InvalidTypeError):
|
|
113
|
+
generate("foo")
|
|
114
|
+
|
|
115
|
+
def test_generated_ids_are_unique(self) -> None:
|
|
116
|
+
ids = {generate("usr") for _ in range(50)}
|
|
117
|
+
assert len(ids) == 50
|
|
118
|
+
|
|
119
|
+
def test_generated_ids_round_trip(self) -> None:
|
|
120
|
+
id_ = generate("org")
|
|
121
|
+
decoded = decode(id_)
|
|
122
|
+
assert decoded.type == "org"
|
|
123
|
+
# Re-encode and compare back to the wire form.
|
|
124
|
+
assert encode("org", decoded.uuid) == id_
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class TestDecodeAny:
|
|
128
|
+
"""Adapter helper for application-defined object types."""
|
|
129
|
+
|
|
130
|
+
def test_decodes_a_registered_prefix_the_same_as_decode(self) -> None:
|
|
131
|
+
result = decode_any(f"usr_{SAMPLE_HEX}")
|
|
132
|
+
assert result.type == "usr"
|
|
133
|
+
assert result.uuid == "0190f2a8-1b3c-7abc-8123-456789abcdef"
|
|
134
|
+
|
|
135
|
+
def test_decodes_an_application_defined_prefix_that_decode_rejects(
|
|
136
|
+
self,
|
|
137
|
+
) -> None:
|
|
138
|
+
# 'proj' is not in TYPES — strict decode raises InvalidTypeError;
|
|
139
|
+
# decode_any accepts it.
|
|
140
|
+
result = decode_any(f"proj_{SAMPLE_HEX}")
|
|
141
|
+
assert result.type == "proj"
|
|
142
|
+
|
|
143
|
+
def test_rejects_malformed_shape_with_invalid_id_error(self) -> None:
|
|
144
|
+
with pytest.raises(InvalidIdError):
|
|
145
|
+
decode_any("no-separator")
|
|
146
|
+
|
|
147
|
+
def test_rejects_uppercase_hex(self) -> None:
|
|
148
|
+
with pytest.raises(InvalidIdError):
|
|
149
|
+
decode_any(f"usr_{SAMPLE_HEX.upper()}")
|
|
150
|
+
|
|
151
|
+
def test_rejects_empty_type_prefix(self) -> None:
|
|
152
|
+
with pytest.raises(InvalidIdError):
|
|
153
|
+
decode_any(f"_{SAMPLE_HEX}")
|
|
154
|
+
|
|
155
|
+
def test_rejects_nil_uuid(self) -> None:
|
|
156
|
+
with pytest.raises(InvalidIdError):
|
|
157
|
+
decode_any("usr_00000000000000000000000000000000")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class TestIsValidShape:
|
|
161
|
+
"""Predicate counterpart to decode_any."""
|
|
162
|
+
|
|
163
|
+
def test_returns_true_for_application_defined_prefixes(self) -> None:
|
|
164
|
+
assert is_valid_shape(f"proj_{SAMPLE_HEX}")
|
|
165
|
+
assert is_valid_shape(f"doc_{SAMPLE_HEX}")
|
|
166
|
+
|
|
167
|
+
def test_returns_true_for_registered_prefixes(self) -> None:
|
|
168
|
+
assert is_valid_shape(f"usr_{SAMPLE_HEX}")
|
|
169
|
+
|
|
170
|
+
def test_returns_false_for_malformed_shape(self) -> None:
|
|
171
|
+
assert not is_valid_shape("not an id")
|
|
172
|
+
assert not is_valid_shape(f"usr_{SAMPLE_HEX.upper()}")
|
|
173
|
+
assert not is_valid_shape("usr_ffffffffffffffffffffffffffffffff")
|