coffeejson 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. coffeejson-0.1.0/.gitignore +18 -0
  2. coffeejson-0.1.0/CHANGELOG.md +42 -0
  3. coffeejson-0.1.0/LICENSE +190 -0
  4. coffeejson-0.1.0/PKG-INFO +300 -0
  5. coffeejson-0.1.0/README.md +271 -0
  6. coffeejson-0.1.0/pyproject.toml +69 -0
  7. coffeejson-0.1.0/src/coffeejson/__init__.py +134 -0
  8. coffeejson-0.1.0/src/coffeejson/__main__.py +5 -0
  9. coffeejson-0.1.0/src/coffeejson/_association.py +37 -0
  10. coffeejson-0.1.0/src/coffeejson/_data.py +27 -0
  11. coffeejson-0.1.0/src/coffeejson/_readers.py +119 -0
  12. coffeejson-0.1.0/src/coffeejson/_units.py +110 -0
  13. coffeejson-0.1.0/src/coffeejson/cli.py +136 -0
  14. coffeejson-0.1.0/src/coffeejson/codec.py +442 -0
  15. coffeejson-0.1.0/src/coffeejson/data/coffeejson-1.0.authoring.schema.json +1764 -0
  16. coffeejson-0.1.0/src/coffeejson/data/coffeejson-1.0.schema.json +852 -0
  17. coffeejson-0.1.0/src/coffeejson/data/gear.json +278 -0
  18. coffeejson-0.1.0/src/coffeejson/gear_labels.py +64 -0
  19. coffeejson-0.1.0/src/coffeejson/normalize.py +509 -0
  20. coffeejson-0.1.0/src/coffeejson/py.typed +0 -0
  21. coffeejson-0.1.0/src/coffeejson/schema.py +247 -0
  22. coffeejson-0.1.0/src/coffeejson/version.py +21 -0
  23. coffeejson-0.1.0/src/coffeejson/vocabularies.py +94 -0
  24. coffeejson-0.1.0/tests/conftest.py +91 -0
  25. coffeejson-0.1.0/tests/test_conformance.py +391 -0
  26. coffeejson-0.1.0/tests/test_normalize.py +461 -0
  27. coffeejson-0.1.0/tests/test_public_surface.py +46 -0
  28. coffeejson-0.1.0/tests/test_transport.py +550 -0
  29. coffeejson-0.1.0/tests/test_vendored.py +30 -0
  30. coffeejson-0.1.0/tests/test_vocabularies.py +96 -0
@@ -0,0 +1,18 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ .venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .mypy_cache/
11
+
12
+ # macOS / editors
13
+ .DS_Store
14
+ .vscode/
15
+ .idea/
16
+
17
+ # Claude Code local state
18
+ .claude/settings.local.json
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+
3
+ All notable changes to this package are recorded here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package
5
+ follows [Semantic Versioning](https://semver.org/) independently of the
6
+ format's own version.
7
+
8
+ ## [0.1.0] - 2026-12-01
9
+
10
+ The first release, reading and writing CoffeeJSON 1.1.
11
+
12
+ ### Added
13
+
14
+ - Decoding of the share-URL and file bindings as
15
+ [Transport § Encoding](https://coffeejson.org/docs/transport#encoding) and
16
+ § Compression state them: `decode_scanned`, `decode_payload`,
17
+ `decode_document_text`, `decode_document_bytes` and `check_envelope`, raising
18
+ `DecodeError` with one of the twelve `DECODE_ERROR_KINDS`. The first decoded
19
+ byte selects plain JSON or zlib once; zlib output is bounded at the 8192-byte
20
+ cap while inflating. A payload may use either Base64 alphabet and carry ASCII
21
+ whitespace and any trailing `=`, which are removed before the payload is
22
+ read; any other character is `malformed_base64`.
23
+ - Validation against the vendored runtime schema (`validate`, `is_valid`), and
24
+ against the authoring schema with `strict=True`, reporting `Issue`s with the
25
+ keyword, instance path and leaf the format's own harness uses, and a message
26
+ from jsonschema.
27
+ A recipe title, or a localized title, of whitespace alone is rejected.
28
+ - `normalize`: a total projection of any JSON value onto frozen dataclasses,
29
+ with the reference implementation's derivations — `is_espresso` (an absent
30
+ `basis` is `water`, only an unrecognized one is derived from the quantities
31
+ present, and `method` never decides), ratio, water from ratio, per-pour deltas, extraction yield, association by
32
+ `bean_ref` / `recipe_ref` and co-location, calendar-day checks and gear
33
+ labels from the registry. A measurement in a unit outside the Units
34
+ vocabulary reads as absent, as the
35
+ [Measurement object](https://coffeejson.org/docs/spec/03-recipe#measurement-object)
36
+ rules require of a consumer.
37
+ - Encoding: `encode_payload`, `share_url`, `dumps` and `dump`, dropping `None`
38
+ members and writing the linking members in NFC.
39
+ - Every closed vocabulary the schema defines, read from the vendored schema;
40
+ the gear registry's labels; `convert_measurement`; `FORMAT_VERSION`,
41
+ `SUPPORTED_MAJOR`, `MEDIA_TYPE` and `MAX_PAYLOAD_BYTES`.
42
+ - `python -m coffeejson validate | decode | encode`.
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Ken Tominaga
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,300 @@
1
+ Metadata-Version: 2.5
2
+ Name: coffeejson
3
+ Version: 0.1.0
4
+ Summary: Read, validate, normalize and write CoffeeJSON, the open JSON format for a coffee brew and the coffee it was made from.
5
+ Project-URL: Homepage, https://coffeejson.org
6
+ Project-URL: Repository, https://github.com/coffeejson-org/coffeejson-python
7
+ Author: CoffeeJSON contributors
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: coffee,coffeejson,json,json-schema,recipe
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: 3.15
22
+ Classifier: Topic :: File Formats :: JSON
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: jsonschema>=4.18
27
+ Requires-Dist: rfc3986-validator>=0.1.1
28
+ Description-Content-Type: text/markdown
29
+
30
+ # coffeejson
31
+
32
+ The [CoffeeJSON](https://coffeejson.org) codec for Python.
33
+
34
+ CoffeeJSON is the open JSON format for a coffee brew and the coffee it was made
35
+ from. This package reads and writes it: it decodes share links, QR codes and
36
+ files, validates documents against the published schema, projects any document
37
+ onto a typed, read-only view, and encodes documents back into links and files.
38
+ It is a reference implementation beside `@coffeejson/core` (TypeScript) and
39
+ `coffeejson-swift`, and it behaves as they do, down to the failure names;
40
+ [`NOTES.md`](https://github.com/coffeejson-org/coffeejson-python/blob/main/NOTES.md)
41
+ lists the few places where it does not.
42
+
43
+ - Python 3.10 or later
44
+ - Runtime dependencies: `jsonschema` and `rfc3986-validator` (so `format: uri`
45
+ is enforced). Everything else is the standard library.
46
+ - Fully typed (`py.typed`), checked with `mypy --strict`.
47
+
48
+ ## Install
49
+
50
+ ```sh
51
+ pip install coffeejson
52
+ # or
53
+ uv add coffeejson
54
+ ```
55
+
56
+ ## Decode
57
+
58
+ A share link carries the whole document in its `d` query parameter, plain or
59
+ zlib-compressed ([Transport § Encoding](https://coffeejson.org/docs/transport#encoding)).
60
+ `decode_scanned` takes whatever a QR scanner or link handler hands you and
61
+ accepts a link from any host:
62
+
63
+ ```python
64
+ from coffeejson import DecodeError, decode_scanned
65
+
66
+ link = (
67
+ "https://coffeejson.org/r?d=eyJjb2ZmZWVqc29uIjoiMS4wIiwicmVjaXBlcyI6W3sidGl0bGUiOiJF"
68
+ "dmVyeWRheSBWNjAiLCJjb2ZmZWUiOnsidmFsdWUiOjE1LCJ1bml0IjoiZ3JhbSJ9LCJ3YXRlciI6eyJ2YWx1"
69
+ "ZSI6MjUwLCJ1bml0IjoiZ3JhbSJ9fV19"
70
+ )
71
+ doc = decode_scanned(link)
72
+ print(doc["recipes"][0]["title"]) # Everyday V60
73
+
74
+ try:
75
+ decode_scanned("Everyday V60 — 15 g / 250 g")
76
+ except DecodeError as e:
77
+ print(e.kind) # not_a_url
78
+ ```
79
+
80
+ The other entry points share the same rules and the same failure names:
81
+
82
+ | Function | Reads |
83
+ | --- | --- |
84
+ | `decode_scanned(text)` | scanned or pasted text: requires an `http(s)` URL, reads the first `d` query item, never the fragment |
85
+ | `decode_payload(raw)` | the bare `d` value |
86
+ | `decode_document_text(text)` | the text of a file; one leading U+FEFF is discarded |
87
+ | `decode_document_bytes(data)` | the bytes of a file; strict UTF-8, one leading byte-order mark discarded |
88
+ | `check_envelope(value)` | already-parsed JSON, such as an HTTP body |
89
+
90
+ Each returns the document as a `dict` once it is past the envelope check: a JSON
91
+ object with a `coffeejson` version of major 1 and a non-empty `beans` or
92
+ `recipes`. A decode never looks inside a collection and never validates — the
93
+ schema is a producer gate, not an import gate.
94
+
95
+ ## Validate
96
+
97
+ ```python
98
+ from coffeejson import is_valid, validate
99
+
100
+ doc = {
101
+ "coffeejson": "1.1",
102
+ "recipes": [{"title": "Weekday V60", "coffee": {"value": 15, "unit": "g"}, "ratio": 16}],
103
+ }
104
+ print(is_valid(doc)) # False
105
+ for issue in validate(doc):
106
+ # enum coffee.unit ('recipes', 0, 'coffee', 'unit')
107
+ print(issue.keyword, issue.leaf, issue.path)
108
+ ```
109
+
110
+ `validate` checks against the shipped runtime schema
111
+ (`https://coffeejson.org/schema/1.0`, JSON Schema 2020-12) with `format: uri` and
112
+ `format: date` enforced. Each `Issue` carries `keyword` (in the spelling the
113
+ format's own harness uses: a `false` subschema is `"false schema"`), `path`,
114
+ `leaf` (the member the issue fired on, owner-qualified when its name is generic,
115
+ such as `coffee.unit` or `author.name`) and `message`. Pass `strict=True` to lint
116
+ with the [authoring schema](https://coffeejson.org/schema/authoring/1.0), which
117
+ closes every object so a typo'd member fails loudly.
118
+
119
+ ## Normalize
120
+
121
+ `normalize` projects any JSON value onto frozen dataclasses. It never raises and
122
+ never validates: what it cannot read it drops, and every derivation follows the
123
+ reference implementation.
124
+
125
+ ```python
126
+ from coffeejson import normalize
127
+
128
+ view = normalize(
129
+ {
130
+ "coffeejson": "1.1",
131
+ "beans": [{"name": "Nano Challa", "roast_date": "2026-02-30"}],
132
+ "recipes": [
133
+ {
134
+ "title": "Roaster's V60",
135
+ "brewer": {"id": "hario-v60", "variant": "02"},
136
+ "coffee": {"value": 20, "unit": "gram"},
137
+ "ratio": 15,
138
+ "steps": [
139
+ {"kind": "bloom", "to_water": {"value": 60, "unit": "gram"}},
140
+ {"kind": "wait"},
141
+ {"to_water": {"value": 300, "unit": "gram"}},
142
+ ],
143
+ }
144
+ ],
145
+ }
146
+ )
147
+ recipe = view.recipes[0]
148
+ print(recipe.water) # Measurement(unit='gram', value=300.0, min=None, max=None) — from the ratio
149
+ print(recipe.brewer_label) # Hario V60 02
150
+ print([s.pour_delta.value for s in recipe.steps if s.pour_delta]) # [60, 240]
151
+ print(recipe.bean.name) # Nano Challa — the single bean, by co-location
152
+ print(view.beans[0].roast_date) # None — February has no 30th
153
+ ```
154
+
155
+ ## Encode
156
+
157
+ ```python
158
+ from coffeejson import dumps, encode_payload, share_url
159
+
160
+ doc = {
161
+ "coffeejson": "1.1",
162
+ "recipes": [
163
+ {
164
+ "title": "Everyday V60",
165
+ "coffee": {"value": 15, "unit": "gram"},
166
+ "water": {"value": 250, "unit": "gram"},
167
+ }
168
+ ],
169
+ }
170
+ print(share_url(doc)) # https://coffeejson.org/r?d=eN… (zlib-compressed by default)
171
+ print(encode_payload(doc)) # eyJjb2ZmZWVqc29uIjoiMS4xIi… (plain)
172
+ text = dumps(doc) # the File binding: UTF-8 JSON, no byte-order mark
173
+ ```
174
+
175
+ Encoding works on a copy: members whose value is `None` are dropped (absence is
176
+ the null), the linking members `id`, `bean_ref` and `recipe_ref` are written in
177
+ Unicode NFC so byte-exact association holds, and `encode_payload` spells numbers
178
+ up to 2^53 as the reference encoder spells them, so a document makes the same
179
+ plain payload as `@coffeejson/core`, with two exceptions: a null member, which that
180
+ encoder keeps, and a member name that is a whole number, which JavaScript orders
181
+ first. An integer past 2^53 keeps every digit. `share_url` compresses by default,
182
+ which that encoder does not.
183
+ `dumps` spells floats as Python does, such as `1.5e-07`. `encode_payload` refuses
184
+ a document past the 8192-byte cap, since every conformant consumer would reject
185
+ the link, and both refuse a document nested too deeply to write. `dump(doc, fp)`
186
+ writes the same bytes to a binary file.
187
+
188
+ The package also vends every closed vocabulary the schema defines
189
+ (`BREW_METHODS`, `STEP_KINDS`, `PROCESSES`, `ROAST_LEVELS`, the unit sets, …),
190
+ the gear registry's labels (`GEAR_LABELS`, `gear_label`), the unit conversions
191
+ (`convert_measurement`), and `FORMAT_VERSION`, `SUPPORTED_MAJOR`, `MEDIA_TYPE`
192
+ and `MAX_PAYLOAD_BYTES`.
193
+
194
+ ## Public API
195
+
196
+ `coffeejson.__all__` is the public surface; submodule names are not, and may move.
197
+ It holds:
198
+
199
+ - Decode: `decode_scanned`, `decode_payload`, `decode_document_text`,
200
+ `decode_document_bytes`, `check_envelope`, `DecodeError`, `DecodeErrorKind`,
201
+ `DECODE_ERROR_KINDS`, `MAX_PAYLOAD_BYTES`
202
+ - Validate: `validate`, `is_valid`, `load_schema`, `Issue`
203
+ - Normalize: `normalize`, `NormalizedDoc`, `NormalizedRecipe`, `NormalizedBean`,
204
+ `NormalizedTasting`, `NormalizedStep`, `NormalizedGrind`, `NormalizedParty`,
205
+ `NormalizedOriginItem`, `NormalizedAddition`, `NormalizedFilter`,
206
+ `NormalizedGenerator`, `NormalizedPerceived`, `NormalizedMeasured`,
207
+ `Measurement`
208
+ - Encode: `encode_payload`, `share_url`, `dumps`, `dump`
209
+ - Units and gear: `convert_measurement`, `UnitSystem`, `gear_label`, `GEAR_LABELS`
210
+ - Version: `FORMAT_VERSION`, `SUPPORTED_MAJOR`, `MEDIA_TYPE`
211
+ - Vocabularies: `BREW_METHODS`, `STEP_KINDS`, `DEFAULT_STEP_KIND`, `PROCESSES`,
212
+ `ROAST_LEVELS`, `BEAN_FORMS`, `FILTER_MATERIALS`, `GRIND_SIZES`,
213
+ `QUANTITY_BASES`, `DEFAULT_QUANTITY_BASIS`, `ORIGIN_TYPES`, `PARTY_TYPES`,
214
+ `PREFERRED_EXTRACTIONS`, `MASS_UNITS`, `WATER_UNITS`, `TEMPERATURE_UNITS`,
215
+ `PRESSURE_UNITS`, `ALTITUDE_UNITS`, `UNITS`, `RECOMMENDED_ADDITION_TYPES`,
216
+ `RECOMMENDED_PRODUCER_ROLES`
217
+
218
+ ## Command line
219
+
220
+ ```sh
221
+ python -m coffeejson validate recipe.json [--strict]
222
+ python -m coffeejson decode 'https://coffeejson.org/r?d=…'
223
+ python -m coffeejson encode recipe.json [--compress] [--url] [--host apps.example]
224
+ ```
225
+
226
+ `decode` prints the decoded document as indented JSON with its members, order,
227
+ `null`s and ids unchanged; only `encode` rewrites, as `dumps` does. Each command
228
+ exits 0 on success, 1 when the document or the file fails, and 2 on a usage error.
229
+
230
+ ## Error vocabulary
231
+
232
+ `DecodeError.kind` is always one of `DECODE_ERROR_KINDS`, the twelve names the
233
+ [integration guide](https://coffeejson.org/docs/integration-guide) tabulates;
234
+ `DecodeError.detail` is optional prose.
235
+
236
+ | `kind` | Meaning |
237
+ | --- | --- |
238
+ | `no_payload` | no `d` parameter, or an empty one |
239
+ | `malformed_base64` | characters outside the Base64 alphabet |
240
+ | `unrecognized_encoding` | the first decoded byte is neither `{` nor a zlib header |
241
+ | `damaged_compression` | a zlib stream that did not survive the wire |
242
+ | `too_large` | past the 8192-byte cap, as sent or after inflating |
243
+ | `not_utf8` | the bytes are not UTF-8 text |
244
+ | `not_json` | text, but not JSON (`NaN` and `Infinity` are not JSON) |
245
+ | `not_a_document` | JSON, but no string `coffeejson` member |
246
+ | `unsupported_version` | a major other than 1, or a version outside the `MAJOR.MINOR` grammar |
247
+ | `empty_document` | neither `beans` nor `recipes` carries anything |
248
+ | `not_a_url` | scanned text that is not a URL at all |
249
+ | `not_http` | a URL of another scheme, such as `javascript:` or `data:` |
250
+
251
+ ## Conformance
252
+
253
+ Measured against the specification repository at commit `39379ad`, with
254
+ `uv run pytest -q` (715 tests, all passing, none skipped):
255
+
256
+ | Line | What | Result |
257
+ | --- | --- | --- |
258
+ | 1 | every `fixtures/valid/*.json` validates | 50 / 50 |
259
+ | 2 | every `fixtures/invalid/*.json` fails on the `Fails on` token its `fixtures/README.md` row declares | 62 / 62 |
260
+ | 2 | …and still decodes, or is refused by the envelope check with the right kind (6 fixtures) | 62 / 62 |
261
+ | 3 | every `recipes/*.json` corpus document validates (`catalog.json` is the index, not a document) | 80 / 80 |
262
+ | 4 | every scan vector in `fixtures/transport/scan-vectors.json` decodes to its document or rejects with its `kind` | 39 / 39 |
263
+ | 5 | every `document` vector round-trips plain, compressed and through `share_url` | 51 / 51 (17 × 3) |
264
+ | 6 | `fixtures/transport/bom-prefixed-file.json` keeps its mark, decodes and validates | 1 / 1 |
265
+ | 7 | the authoring schema accepts every valid fixture and corpus document but the four runtime-leniency fixtures | 126 / 126 |
266
+ | 7 | …and rejects what the runtime schema accepts (a typo'd member, and four more probes) | 5 / 5 |
267
+ | 8 | the vendored schemas and gear registry are byte-identical to the specification's | 3 / 3 |
268
+ | 9 | every closed set vended equals the schema's `enum` for its member, in order | 16 / 16 |
269
+ | 10 | `normalize` derivation tests | 71 / 71 |
270
+
271
+ The plain payloads of all 12 plain `document` vectors are also reproduced byte
272
+ for byte by `encode_payload`. Reproduce with:
273
+
274
+ ```sh
275
+ git clone https://github.com/coffeejson-org/coffeejson ../coffeejson
276
+ git -C ../coffeejson checkout 39379ad
277
+ uv run pytest -q
278
+ ```
279
+
280
+ ## Development
281
+
282
+ ```sh
283
+ uv sync
284
+ uv run pytest -q
285
+ uv run ruff check . && uv run ruff format --check .
286
+ uv run mypy src
287
+ ```
288
+
289
+ The suite reads the fixtures and the corpus from a checkout of the
290
+ [specification repository](https://github.com/coffeejson-org/coffeejson), found
291
+ through `COFFEEJSON_SPEC_DIR` and defaulting to `../coffeejson` beside this
292
+ repository. Without a checkout, or with one whose fixtures or corpus are missing,
293
+ the run fails; it never skips. The schemas and
294
+ the gear registry under `src/coffeejson/data/` are vendored byte for byte from
295
+ that repository, and a test fails the moment they drift.
296
+
297
+ ## License
298
+
299
+ Apache-2.0. The format itself — specification, schema, fixtures and
300
+ registries — is CC0.