c4py 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.
Files changed (57) hide show
  1. c4py-1.0.0/.github/workflows/ci.yml +23 -0
  2. c4py-1.0.0/.gitignore +17 -0
  3. c4py-1.0.0/DEVELOPMENT.md +217 -0
  4. c4py-1.0.0/LICENSE +191 -0
  5. c4py-1.0.0/PKG-INFO +215 -0
  6. c4py-1.0.0/README.md +184 -0
  7. c4py-1.0.0/examples/README.md +77 -0
  8. c4py-1.0.0/examples/backup_and_restore.py +101 -0
  9. c4py-1.0.0/examples/find_duplicates.py +48 -0
  10. c4py-1.0.0/examples/ml_data_leakage.py +85 -0
  11. c4py-1.0.0/examples/ml_dataset_diff.py +95 -0
  12. c4py-1.0.0/examples/ml_dataset_verify.py +71 -0
  13. c4py-1.0.0/examples/ml_experiment_snapshot.py +178 -0
  14. c4py-1.0.0/examples/ml_workspace.py +175 -0
  15. c4py-1.0.0/examples/portable_bundle.py +83 -0
  16. c4py-1.0.0/examples/render_farm_monitor.py +71 -0
  17. c4py-1.0.0/examples/shotgrid_delivery.py +76 -0
  18. c4py-1.0.0/examples/track_changes.py +74 -0
  19. c4py-1.0.0/examples/verify_delivery.py +64 -0
  20. c4py-1.0.0/examples/vfx_workspace.py +248 -0
  21. c4py-1.0.0/pyproject.toml +67 -0
  22. c4py-1.0.0/src/c4py/__init__.py +95 -0
  23. c4py-1.0.0/src/c4py/__main__.py +228 -0
  24. c4py-1.0.0/src/c4py/decoder.py +667 -0
  25. c4py-1.0.0/src/c4py/diff.py +632 -0
  26. c4py-1.0.0/src/c4py/encoder.py +211 -0
  27. c4py-1.0.0/src/c4py/entry.py +429 -0
  28. c4py-1.0.0/src/c4py/id.py +269 -0
  29. c4py-1.0.0/src/c4py/manifest.py +375 -0
  30. c4py-1.0.0/src/c4py/naturalsort.py +88 -0
  31. c4py-1.0.0/src/c4py/pool.py +243 -0
  32. c4py-1.0.0/src/c4py/py.typed +0 -0
  33. c4py-1.0.0/src/c4py/reconcile.py +319 -0
  34. c4py-1.0.0/src/c4py/safename.py +286 -0
  35. c4py-1.0.0/src/c4py/scanner.py +393 -0
  36. c4py-1.0.0/src/c4py/store.py +237 -0
  37. c4py-1.0.0/src/c4py/validator.py +362 -0
  38. c4py-1.0.0/src/c4py/verify.py +136 -0
  39. c4py-1.0.0/src/c4py/workspace.py +206 -0
  40. c4py-1.0.0/tests/__init__.py +0 -0
  41. c4py-1.0.0/tests/test_cli.py +244 -0
  42. c4py-1.0.0/tests/test_decoder.py +347 -0
  43. c4py-1.0.0/tests/test_diff.py +413 -0
  44. c4py-1.0.0/tests/test_encoder.py +252 -0
  45. c4py-1.0.0/tests/test_entry.py +267 -0
  46. c4py-1.0.0/tests/test_id.py +329 -0
  47. c4py-1.0.0/tests/test_manifest.py +494 -0
  48. c4py-1.0.0/tests/test_naturalsort.py +36 -0
  49. c4py-1.0.0/tests/test_pool.py +246 -0
  50. c4py-1.0.0/tests/test_reconcile.py +210 -0
  51. c4py-1.0.0/tests/test_safename.py +176 -0
  52. c4py-1.0.0/tests/test_scanner.py +278 -0
  53. c4py-1.0.0/tests/test_store.py +201 -0
  54. c4py-1.0.0/tests/test_validator.py +303 -0
  55. c4py-1.0.0/tests/test_verify.py +281 -0
  56. c4py-1.0.0/tests/test_workspace.py +226 -0
  57. c4py-1.0.0/tests/vectors/known_ids.json +90 -0
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, macos-latest]
15
+ python-version: ['3.10', '3.11', '3.12', '3.13']
16
+ runs-on: ${{ matrix.os }}
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: actions/setup-python@v5
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+ - run: pip install -e ".[dev]"
23
+ - run: python -m pytest
c4py-1.0.0/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .pytest_cache/
12
+ .coverage
13
+ htmlcov/
14
+ .venv/
15
+ venv/
16
+ *.so
17
+ .DS_Store
@@ -0,0 +1,217 @@
1
+ # c4py Development Guide
2
+
3
+ This document specifies the implementation requirements for c4py. The project is scaffolded — module skeletons with docstrings and type signatures exist, test vectors from the Go reference implementation are provided, and test files are ready.
4
+
5
+ ## Architecture
6
+
7
+ ```
8
+ src/c4py/
9
+ __init__.py # Public API (complete — re-exports from modules)
10
+ id.py # C4 ID computation (IMPLEMENTED — 27/27 cross-language tests pass)
11
+ store.py # Content store (IMPLEMENTED — 13/13 tests pass, adaptive trie sharding)
12
+ entry.py # Entry dataclass (partial — formatting TODO)
13
+ manifest.py # Manifest type (skeleton)
14
+ decoder.py # c4m parser (skeleton)
15
+ encoder.py # c4m writer (skeleton)
16
+ naturalsort.py # Natural sort (skeleton)
17
+ safename.py # Filename encoding (skeleton)
18
+ scanner.py # Directory scanner (skeleton)
19
+ diff.py # Diff operations (skeleton)
20
+ validator.py # Validation (skeleton)
21
+ ```
22
+
23
+ ## CLI Alignment (c4 v1.0.0)
24
+
25
+ c4py maps to the c4 CLI (8 commands: id, cat, diff, patch, merge, log, split, version).
26
+
27
+ | c4py function | c4 CLI | Description |
28
+ |---------------|--------|-------------|
29
+ | `identify()` / `scan()` | `c4 id` | Identify content, scan directories |
30
+ | `store.get()` | `c4 cat` | Retrieve content by C4 ID |
31
+ | `patch_diff()` | `c4 diff` | Produce c4m patch between two states |
32
+ | `resolve_chain()` | `c4 patch` | Resolve patch chain to final state |
33
+ | `merge()` | `c4 merge` | Three-way merge with LWW conflict resolution |
34
+ | `log_chain()` | `c4 log` | Enumerate patches in a chain |
35
+ | `diff()` | — | High-level comparison (added/removed/modified) |
36
+
37
+ Key interop points:
38
+ - **Shared content store:** TreeStore adaptive trie, same config (`C4_STORE` / `~/.c4/config`).
39
+ - **`scan(store=...)` maps to `c4 id -s`:** Single-pass identify + store.
40
+ - **Canonical output matches `c4 id`:** `c4py.dumps(manifest)` produces byte-identical output.
41
+ - **Reconciliation:** The Go CLI has `github.com/Avalanche-io/c4/reconcile` for applying manifest state to directories. c4py does not replicate this — use the CLI for filesystem reconciliation.
42
+
43
+ ## Implementation Priority
44
+
45
+ ### Phase 1: Core (must ship in v0.1.0)
46
+
47
+ 1. **id.py** — DONE. C4 ID computation, parsing, tree IDs. 27/27 cross-language tests pass.
48
+
49
+ 2. **store.py** — DONE. FSStore with adaptive trie sharding, open_store() config
50
+ discovery, ContentNotFound error. 13/13 tests pass. Compatible with Go CLI layout.
51
+
52
+ 3. **naturalsort.py** — Implement `natural_sort_key()`.
53
+ - Split names into alternating text/numeric segments
54
+ - Numeric: compare as integers, then by string length for ties
55
+ - Text sorts before numeric in mixed comparisons
56
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/naturalsort.go`
57
+ - Tests: `tests/test_naturalsort.py`
58
+
59
+ 4. **safename.py** — Implement all four functions.
60
+ - Tier 1: printable UTF-8 passthrough (except `¤` U+00A4 and `\`)
61
+ - Tier 2: `\0`, `\t`, `\n`, `\r`, `\\`
62
+ - Tier 3: non-printable → braille U+2800-U+28FF between `¤` delimiters
63
+ - Field escaping: space→`\ `, `"`→`\"`, `[`→`\[`, `]`→`\]`
64
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/safename.go`
65
+
66
+ 5. **entry.py** — Complete `format_mode()` and `canonical()`.
67
+ - Mode string: 10 chars, position 0 = file type, 1-9 = rwx with special bits
68
+ - Use Python's `stat` module constants for bit extraction
69
+ - Null mode (0) → `-`
70
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/entry.go`
71
+
72
+ 6. **decoder.py** — Implement `loads()` and `load()`.
73
+ - Parse entry lines: split fields, handle indentation
74
+ - Auto-detect indent width from first indented line
75
+ - Handle null values: `-` for mode, timestamp, size, c4id
76
+ - Parse timestamps: accept RFC3339 (canonical) and common variations
77
+ - Handle link operators: symlinks, hard links, flow links
78
+ - Reject @ directives, CR characters, invalid UTF-8
79
+ - Skip inline ID list lines (range data): len > 90, len % 90 == 0, all 90-char
80
+ chunks are valid C4 IDs. These are NOT patch boundaries.
81
+ - Bare C4 ID lines (exactly 90 chars) are patch boundaries
82
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/decoder.go`
83
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/chain.go`
84
+
85
+ 7. **encoder.py** — Implement `dumps()` and `dump()`.
86
+ - Canonical mode: no indent, single spaces, UTC, null as `-`
87
+ - Pretty mode: indented, padded sizes, column-aligned C4 IDs
88
+ - Pretty column: default 80, shift to next 10-col boundary if needed
89
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/encoder.go`
90
+
91
+ 8. **manifest.py** — Complete `sort_entries()` and `compute_c4id()`.
92
+ - Sort: files before directories at each depth, then natural sort
93
+ - C4 ID: format all entries canonical, hash the UTF-8 bytes
94
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/manifest.go`
95
+
96
+ 9. **scanner.py** — Implement `scan()`.
97
+ - Walk directory with `os.walk()` or `pathlib`
98
+ - Stat each file for mode, timestamp, size
99
+ - Compute C4 ID for regular files (streaming)
100
+ - When `store` is provided: tee read stream to store.put() (single pass,
101
+ zero extra I/O). This matches `c4 id -s` in the CLI.
102
+ - Record symlink targets
103
+ - Build entry tree with correct depth
104
+ - Sort and compute directory C4 IDs bottom-up
105
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/builder.go`
106
+
107
+ 10. **diff.py** — Implement all functions:
108
+ - `diff(a, b)` — high-level comparison: match by path, categorize as
109
+ added/removed/modified/same
110
+ - `patch_diff(old, new)` — produce c4m patch text. First line is bare C4 ID
111
+ of old (base state). Patch entry semantics: exact duplicate = removal,
112
+ same path different content = modification, new path = addition.
113
+ Maps to: `c4 diff before.c4m after.c4m`
114
+ - `apply_patch(base, entries)` — apply patch entries to base manifest
115
+ - `resolve_chain(manifest)` — resolve all patches to final state.
116
+ Maps to: `c4 patch project.c4m`
117
+ - `log_chain(manifest)` — enumerate patches with summary stats.
118
+ Maps to: `c4 log project.c4m`
119
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/operations.go`
120
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/design/cli/phase1_cli_redesign.md`
121
+
122
+ 11. **validator.py** — Implement `validate()`.
123
+ - Check for duplicate paths
124
+ - Check for path traversal (`../`, `./`)
125
+ - Check indentation consistency
126
+ - Check mode string format
127
+ - Check timestamp format
128
+ - Check C4 ID format (90 chars, c4 prefix, base58)
129
+ - Check directory names end with /
130
+ - Verify bare C4 ID patch boundaries match accumulated content
131
+ - Reference: `/Users/joshua/ws/active/c4/oss/c4/c4m/validator.go`
132
+
133
+ ### Phase 2: Polish (v0.1.0 nice-to-have)
134
+
135
+ - Sequence notation parsing (frame.[0001-0100].exr)
136
+ - Pretty-print with local timezone detection
137
+ - `c4 split` equivalent (extract patch range from chain)
138
+
139
+ ### Phase 3: Future (v0.2.0+)
140
+
141
+ - Network client integration (absorb current c4-python code)
142
+ - c4git Python API
143
+ - Performance: optional C extension for SHA-512 (hashlib is already C-backed)
144
+
145
+ ## Cross-Language Compatibility
146
+
147
+ **This is the most critical requirement.** c4py must produce byte-identical output to the Go reference implementation for:
148
+
149
+ 1. C4 ID strings (given same input bytes)
150
+ 2. Canonical c4m text (given same manifest)
151
+ 3. Natural sort order (given same entry names)
152
+ 4. Manifest C4 IDs (given same directory contents)
153
+
154
+ Test vectors are in `tests/vectors/known_ids.json`, generated from the Go implementation.
155
+
156
+ To generate additional test vectors:
157
+ ```bash
158
+ cd /Users/joshua/ws/active/c4/oss/c4
159
+ go run /tmp/c4vectors.go
160
+ ```
161
+
162
+ ## Running Tests
163
+
164
+ ```bash
165
+ cd /Users/joshua/ws/active/c4/oss/c4py
166
+ pip install -e ".[dev]"
167
+ pytest
168
+ pytest --cov=c4py
169
+ mypy src/
170
+ ruff check src/ tests/
171
+ ```
172
+
173
+ ## Code Style
174
+
175
+ - Python 3.10+ (use `X | Y` union syntax, not `Union[X, Y]`)
176
+ - Type annotations on all public functions
177
+ - mypy strict mode must pass
178
+ - ruff for linting
179
+ - No external dependencies (stdlib only)
180
+ - Docstrings on all public classes and functions
181
+ - Keep it minimal — match the C4 philosophy
182
+
183
+ ## Key Design Decisions
184
+
185
+ - **Pure Python, zero dependencies.** hashlib.sha512 is C-backed and fast enough.
186
+ - **Streaming identification.** `identify()` reads in chunks, constant memory.
187
+ - **Immutable C4ID.** The digest is set once at construction.
188
+ - **Lenient parser, strict encoder.** Accept variations, always output canonical.
189
+ - **Cross-language tests are the spec.** If Go produces X for input Y, c4py must too.
190
+
191
+ ## Reference Files
192
+
193
+ All paths are in the Go reference implementation at `/Users/joshua/ws/active/c4/oss/c4/`:
194
+
195
+ | Module | Go Reference |
196
+ |--------|-------------|
197
+ | id.py | `id.go` (C4ID, Parse, Identify) |
198
+ | store.py | `store/treestore.go`, `store/config.go` |
199
+ | entry.py | `c4m/entry.go` |
200
+ | manifest.py | `c4m/manifest.go` |
201
+ | decoder.py | `c4m/decoder.go`, `c4m/chain.go` (patch chain parsing) |
202
+ | encoder.py | `c4m/encoder.go` |
203
+ | naturalsort.py | `c4m/naturalsort.go` |
204
+ | safename.py | `c4m/safename.go` |
205
+ | scanner.py | `cmd/c4/internal/scan/` (progressive scanner with modes) |
206
+ | diff.py | `c4m/operations.go` (PatchDiff, ApplyPatch, Diff), `c4m/chain.go` (ResolvePatchChain), `c4m/merge.go` (Merge) |
207
+ | validator.py | `c4m/validator.go` |
208
+
209
+ **Key specs:**
210
+ - c4m format: `c4m/SPECIFICATION.md`
211
+ - c4m standard (ABNF grammar): `c4m/C4M-STANDARD.md`
212
+ - Unix recipes: `docs/c4m-unix-recipes.md`
213
+
214
+ **Note:** The c4 v1.0.0 release (branch `release/v1.0`) contains 6 packages:
215
+ `c4`, `c4m`, `store`, `reconcile`, `cmd/c4`, `cmd/c4/internal/scan`.
216
+ Non-essential packages (chunk, transform, db, hashlib, progscan) were stripped.
217
+ Only depend on APIs from the shipping packages.
c4py-1.0.0/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Joshua Ian Kolden
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
c4py-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,215 @@
1
+ Metadata-Version: 2.4
2
+ Name: c4py
3
+ Version: 1.0.0
4
+ Summary: C4 universal content identification — SMPTE ST 2114:2017
5
+ Project-URL: Homepage, https://github.com/Avalanche-io/c4py
6
+ Project-URL: Documentation, https://github.com/Avalanche-io/c4py
7
+ Project-URL: Repository, https://github.com/Avalanche-io/c4py
8
+ Project-URL: Issues, https://github.com/Avalanche-io/c4py/issues
9
+ Author-email: Joshua Kolden <joshua@avalanche.io>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: c4,c4m,content-addressing,hash,identification,manifest,smpte
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Classifier: Topic :: System :: Filesystems
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Provides-Extra: dev
26
+ Requires-Dist: mypy>=1.0; extra == 'dev'
27
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
28
+ Requires-Dist: pytest>=7.0; extra == 'dev'
29
+ Requires-Dist: ruff>=0.4; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # c4py
33
+
34
+ [![CI](https://github.com/Avalanche-io/c4py/actions/workflows/ci.yml/badge.svg)](https://github.com/Avalanche-io/c4py/actions/workflows/ci.yml)
35
+ [![Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](./LICENSE)
36
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org)
37
+ [![Tests](https://img.shields.io/badge/tests-418-brightgreen.svg)](./tests)
38
+
39
+ Pure Python implementation of [C4](https://github.com/Avalanche-io/c4) universal content identification (SMPTE ST 2114:2017).
40
+
41
+ ```python
42
+ import c4py
43
+
44
+ # Verify a delivery matches the manifest
45
+ manifest = c4py.load("delivery-v3.c4m")
46
+ for path, entry in manifest.flat_entries():
47
+ if entry.c4id and not c4py.verify(f"/deliveries/v3/{path}", entry.c4id):
48
+ print(f"MISMATCH: {path}")
49
+
50
+ # Identify any file — same content always produces the same ID
51
+ c4id = c4py.identify_file("render.1001.exr")
52
+
53
+ # Compare two snapshots of a project
54
+ old = c4py.load("delivery-v2.c4m")
55
+ new = c4py.load("delivery-v3.c4m")
56
+ diff = c4py.diff(old, new)
57
+ print(f"+{len(diff.added)} -{len(diff.removed)} ~{len(diff.modified)}")
58
+ ```
59
+
60
+ ## Install
61
+
62
+ ```bash
63
+ pip install c4py
64
+ ```
65
+
66
+ ## What is C4?
67
+
68
+ C4 IDs are universally unique, unforgeable identifiers derived from content using SHA-512. They are standardized as [SMPTE ST 2114:2017](https://ieeexplore.ieee.org/document/7971777). Same content always produces the same 90-character ID, regardless of filename, location, or time.
69
+
70
+ ```python
71
+ >>> import c4py
72
+ >>> c4py.identify_bytes(b"hello world")
73
+ C4ID('c41yP4cqy7jmaRDzC2bmcGNZkuQb3VdftMk6YH7ynQ2Qw4zktKsyA9fk52xghNQNAdkpF9iFmFkKh2bNVG4kDWhsok')
74
+ ```
75
+
76
+ ## C4M Format
77
+
78
+ A **c4m file** is a human-readable text file that describes a filesystem. It captures file names, sizes, permissions, timestamps, and C4 IDs in a format you can read, edit, diff, and email.
79
+
80
+ ```
81
+ -rw-r--r-- 2025-06-15T12:00:00Z 3 README.md c45xZeXwMSpq...
82
+ drwxr-xr-x 2025-06-15T12:00:00Z 3 src/ -
83
+ -rw-r--r-- 2025-06-15T12:00:00Z 3 main.go c45KgBYEvEE7...
84
+ ```
85
+
86
+ A 2 KB c4m file can describe an 8 TB project. Compare two c4m files to find exactly which frames changed across a delivery — in seconds, not hours.
87
+
88
+ ## API
89
+
90
+ ### Identification
91
+
92
+ ```python
93
+ # Identify a file on disk
94
+ c4id = c4py.identify_file("render.1001.exr")
95
+
96
+ # Verify a file matches an expected ID
97
+ assert c4py.verify("render.1001.exr", expected_id)
98
+
99
+ # From file-like object (streaming, constant memory)
100
+ c4id = c4py.identify(file_obj)
101
+
102
+ # From bytes
103
+ c4id = c4py.identify_bytes(b"data")
104
+
105
+ # Parse a C4 ID string (also works as C4ID constructor)
106
+ c4id = c4py.parse("c45xZeXwMSpq...")
107
+ c4id = c4py.C4ID("c45xZeXwMSpq...") # same thing
108
+
109
+ # C4 ID properties
110
+ str(c4id) # 90-character string
111
+ bytes(c4id) # 64-byte digest
112
+ c4id.hex() # hex digest
113
+ bool(c4id) # False for nil ID, True otherwise
114
+ ```
115
+
116
+ ### Tree IDs (Set Identity)
117
+
118
+ ```python
119
+ # Compute a single ID for a set of IDs (order-independent)
120
+ tree_id = c4py.tree_id([id_a, id_b, id_c])
121
+ ```
122
+
123
+ ### C4M Files
124
+
125
+ ```python
126
+ # Parse
127
+ manifest = c4py.load("project.c4m")
128
+ manifest = c4py.loads(text)
129
+
130
+ # Write
131
+ c4py.dump(manifest, file_obj)
132
+ text = c4py.dumps(manifest)
133
+ text = c4py.dumps(manifest, pretty=True)
134
+
135
+ # Scan directory
136
+ manifest = c4py.scan("/path/to/dir")
137
+
138
+ # Iterate entries
139
+ for entry in manifest:
140
+ print(entry.name, entry.size, entry.c4id)
141
+ ```
142
+
143
+ ### Content Store
144
+
145
+ c4py shares the same content store as the `c4` CLI and `c4sh`. Content stored by any tool is immediately available to the others.
146
+
147
+ ```python
148
+ # Open a store (auto-discovers from C4_STORE env or ~/.c4/config)
149
+ store = c4py.open_store()
150
+
151
+ # Or specify a path
152
+ store = c4py.open_store("/data/c4store")
153
+
154
+ # Store and retrieve content
155
+ c4id = store.put(open("render.exr", "rb"))
156
+ assert store.has(c4id)
157
+ content = store.get(c4id)
158
+
159
+ # Scan + store in one pass (zero extra I/O)
160
+ manifest = c4py.scan("/projects/HERO", store=store)
161
+ ```
162
+
163
+ ### Diff and Patch Chains
164
+
165
+ ```python
166
+ # Compare two manifests
167
+ diff = c4py.diff(old_manifest, new_manifest)
168
+ diff.added # entries only in new
169
+ diff.removed # entries only in old
170
+ diff.modified # same path, different content
171
+ diff.same # identical entries
172
+
173
+ # Produce a c4m patch (like `c4 diff before.c4m after.c4m`)
174
+ patch_text = c4py.patch_diff(old_manifest, new_manifest)
175
+
176
+ # c4m files can contain version histories (base + patches)
177
+ # Resolve a chain to its final state (like `c4 patch project.c4m`)
178
+ final = c4py.resolve_chain(manifest)
179
+
180
+ # Enumerate patches (like `c4 log project.c4m`)
181
+ for info in c4py.log_chain(manifest):
182
+ print(f"{info.index} {info.c4id} +{info.added} -{info.removed} ~{info.modified}")
183
+ ```
184
+
185
+ ### Validation
186
+
187
+ ```python
188
+ result = c4py.validate(manifest)
189
+ for issue in result.errors:
190
+ print(issue)
191
+ ```
192
+
193
+ ## Works With
194
+
195
+ c4py is part of the [C4 ecosystem](https://github.com/Avalanche-io/c4):
196
+
197
+ - **[c4](https://github.com/Avalanche-io/c4)** — Go CLI for identification and content storage (`c4 id`, `c4 cat`, `c4 diff`)
198
+ - **[c4sh](https://github.com/Avalanche-io/c4sh)** — Shell integration that makes c4m files behave as directories
199
+ - **[c4git](https://github.com/Avalanche-io/c4git)** — Git clean/smudge filter for large media assets
200
+
201
+ All tools share the same content store and produce identical C4 IDs.
202
+
203
+ ## Compatibility
204
+
205
+ c4py produces byte-identical output to the [Go reference implementation](https://github.com/Avalanche-io/c4). Cross-language test vectors ensure this.
206
+
207
+ Zero external dependencies. Pure Python. Works offline.
208
+
209
+ ## Design Decisions
210
+
211
+ See the [FAQ](https://github.com/Avalanche-io/c4/blob/main/docs/faq.md) for design decisions including SHA-512 permanence, the c4m format, and content store scaling.
212
+
213
+ ## License
214
+
215
+ MIT