sourceledger 0.2.0__tar.gz → 0.3.1__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.
@@ -1,14 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sourceledger
3
- Version: 0.2.0
3
+ Version: 0.3.1
4
4
  Summary: Fetch, verify and validate the public sources a dataset is built from, with a provenance record for every download
5
5
  Keywords: provenance,data pipeline,reproducibility,open data,research software,FAIR
6
6
  Author: Simon van Lierde
7
- Author-email: Simon van Lierde <90462640+simonvanlierde@users.noreply.github.com>
7
+ Author-email: Simon van Lierde <code@duinlab.nl>
8
8
  License-Expression: MIT
9
9
  License-File: LICENSE
10
10
  Classifier: Development Status :: 3 - Alpha
11
11
  Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: POSIX
12
13
  Classifier: Programming Language :: Python :: 3
13
14
  Classifier: Programming Language :: Python :: 3.12
14
15
  Classifier: Programming Language :: Python :: 3.13
@@ -27,28 +28,28 @@ Description-Content-Type: text/markdown
27
28
 
28
29
  [![python](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml/badge.svg)](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml)
29
30
  [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
31
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23460694.svg)](https://doi.org/10.5281/zenodo.23460694)
32
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/simonvanlierde/sourceledger/badge)](https://scorecard.dev/viewer/?uri=github.com/simonvanlierde/sourceledger)
33
+ [![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://app.codspeed.io/simonvanlierde/sourceledger?utm_source=badge)
30
34
 
31
35
  Build a dataset from public sources where every row says which download it came from.
32
36
 
33
37
  A project lists its inputs in `sources.toml`: each source's URL, the publisher's reuse
34
- terms, and whether the raw file may be republished. sourceledger runs four stages over it:
35
-
36
- - `fetch` downloads each source into `data/raw/` and writes a record beside it: the URL,
37
- the time, the SHA-256 and size, the vintage, and the server's ETag. The next fetch
38
- sends the ETag back, so an unchanged source isn't downloaded again. Each new version is
39
- also added to `data/fetches.jsonl`.
40
- - `build` re-hashes each download, reads it, and writes `data/processed/<id>.csv` with five
41
- provenance columns in front: `source_id`, `source_url`, `retrieved_at`, `vintage` and
42
- `raw_sha256`. It also writes `datapackage.json`, a
43
- [Frictionless Data Package](https://datapackage.org) that describes every output. The
44
- same records always give the same files.
38
+ terms, and whether the raw file may be republished. sourceledger runs three stages over it.
39
+ [How it works](docs/architecture.md) has the detail of each.
40
+
41
+ - `fetch` downloads each source into `data/raw/`, with a record beside it: the URL, the
42
+ time, the SHA-256 and size, the vintage, and the server's ETag and Last-Modified. An
43
+ unchanged source isn't downloaded again. Each new version is added to
44
+ `data/fetches.jsonl`.
45
+ - `build` writes `data/processed/<id>.csv` with five provenance columns in front, and a
46
+ [Frictionless Data Package](https://datapackage.org), `datapackage.json`, that describes
47
+ every output. The same records always give the same files.
45
48
  - `validate` re-reads the outputs and lists every problem it finds, such as an output from
46
- an older fetch, an edited raw file, a record made for another URL, vintage or pin, a
47
- source without reuse terms, or a `datapackage.json` that no longer matches.
48
- - `revisions OLD_LOG` lists the sources whose bytes changed since an earlier copy of the
49
- log. A weekly CI run can use it to report a publisher's revision.
49
+ an older fetch, an edited raw file, or a source without reuse terms.
50
50
 
51
- `init`, `status`, `attribution` and `verify` help around them: see [Other commands](#other-commands).
51
+ `init`, `status`, `attribution`, `verify` and `revisions` are commands around them: see
52
+ [Other commands](#other-commands).
52
53
 
53
54
  There are no dependencies. Excel files need the optional `xlsx` extra. The
54
55
  [docs page](https://simonvanlierde.github.io/sourceledger/) walks through a fetch and a
@@ -60,10 +61,46 @@ publisher's silent revision.
60
61
  uv add sourceledger # or 'sourceledger[xlsx]' to read Excel files
61
62
  ```
62
63
 
64
+ It needs Python 3.12 or later, and runs on Linux and macOS only (POSIX).
65
+
66
+ ### Verify a release
67
+
68
+ Each release is built and published by the
69
+ [release workflow](.github/workflows/python-release.yml), with no API token. PyPI keeps a
70
+ signed record of the workflow run that built each file. To check a wheel you downloaded,
71
+ pass its path:
72
+
73
+ ```sh
74
+ uvx pypi-attestations verify pypi --repository https://github.com/simonvanlierde/sourceledger \
75
+ sourceledger-0.3.1-py3-none-any.whl
76
+ ```
77
+
78
+ From 0.2.0, GitHub also keeps a signed build-provenance attestation for each file:
79
+
80
+ ```sh
81
+ gh attestation verify sourceledger-0.3.1-py3-none-any.whl --repo simonvanlierde/sourceledger
82
+ ```
83
+
84
+ Both fail unless the file is byte for byte the one this repository's workflow built.
85
+ From 0.3.1, the same provenance is also attached to each GitHub release as
86
+ `sourceledger-<version>.sigstore.json`.
87
+
88
+ You can also rebuild a release from its tag and compare. Built with the uv version the
89
+ release workflow pins (0.13.1 for 0.3.1), the wheel and sdist match the ones on PyPI byte
90
+ for byte:
91
+
92
+ ```sh
93
+ git clone https://github.com/simonvanlierde/sourceledger && cd sourceledger
94
+ mkdir sl-0.3.1 && git archive v0.3.1 | tar -x -C sl-0.3.1
95
+ uvx --from uv==0.13.1 uv build sl-0.3.1 -o dist
96
+ sha256sum dist/*
97
+ ```
98
+
99
+ Compare the hashes with the ones under "Download files" on PyPI.
100
+
63
101
  ## Quick start
64
102
 
65
- Write a `sources.toml` in the project root. `sourceledger init` writes one to start from,
66
- with this example commented out:
103
+ Write a `sources.toml` in the project root (`sourceledger init` writes a starter):
67
104
 
68
105
  ```toml
69
106
  [[source]]
@@ -110,24 +147,24 @@ Each `[[source]]` table takes these keys:
110
147
  | `terms`, `terms_url` | for implemented sources | The publisher's reuse terms in their words, and where they are stated. |
111
148
  | `license` | for implemented sources | The same terms as an [SPDX id](https://spdx.org/licenses/), such as `"CC-BY-4.0"`, or `"LicenseRef-<name>"` for terms with none. |
112
149
  | `redistribute` | for implemented sources | `true` if the terms let you republish the raw file, `false` if not. |
113
- | `vintage` | no | The edition you expect, such as `"2024 release"` or a TOML date. Recorded with each fetch and stamped on each row. `"not stated"` when absent. The old key `release` still works, with a warning. |
150
+ | `vintage` | no | The edition you expect, such as `"2024 release"` or a TOML date. Recorded with each fetch and stamped on each row. `"not stated"` when absent. The old name `release` is refused. |
114
151
  | `sha256` | no | The SHA-256 the download must have. Pin it for a fixed release, and `fetch` refuses bytes that changed upstream. |
115
- | `max_bytes` | no | The largest download `fetch` accepts. 200 MiB unless set. |
116
- | `format` | no | `"csv"`, `"json"` (an array of objects) or `"xlsx"`. Otherwise from the URL's extension: `.json`, `.xlsx`, and CSV for anything else. A gzipped CSV or JSON file is decompressed, within `max_bytes`. |
117
- | `sheet` | no | The Excel sheet to read. The first unless set. |
118
- | `headers` | no | Extra request headers, such as an API key, each value naming an environment variable: `{ Authorization = "env:EIA_TOKEN" }`. A literal value is refused, so a secret never lands in the manifest. The record keeps the header names, not the values, and a redirect to another host drops them. |
119
- | `archive` | no | `true` to ask the Internet Archive's [Save Page Now](https://web.archive.org/save) to snapshot the URL after each fetch that brings new bytes. The record keeps the snapshot's address as `archive_url`. Only for http and https URLs. The archive's request does not send `headers`, so don't use it on a source that needs a login. |
152
+ | `max_bytes` | no | The largest download `fetch` accepts. 200 MiB unless set. A gzipped file or Excel workbook that unpacks past it is refused. |
153
+ | `format` | no | `"csv"`, `"json"` (an array of objects) or `"xlsx"`. Otherwise from the URL's extension: `.json`, `.xlsx`, and CSV for anything else. A gzipped CSV or JSON file is decompressed, within `max_bytes`. JSON numbers are written as they appear in the file (`1e5` stays `1e5`, `1.10` stays `1.10`). |
154
+ | `sheet` | no | The Excel sheet to read. The first unless set. A cell right of the last header cell is refused, and a missing cell in a row reads as `""`. |
155
+ | `headers` | no | Extra request headers, such as an API key, each value naming an environment variable: `{ Authorization = "env:EIA_TOKEN" }`. A literal value is refused, and so is a `url` that is not https. The record keeps the header names, not the values. A redirect to another scheme, host or port drops them. |
156
+ | `archive` | no | `true` to ask the Internet Archive's [Save Page Now](https://web.archive.org/save) to snapshot the URL after each fetch that brings new bytes. The record keeps the snapshot's address as `archive_url`. Only for http and https URLs, and not for a source that needs `headers`: the archive's request sends none. |
120
157
  | `reason` | no | A note for people, such as why a source is unimplemented. sourceledger doesn't read it. |
121
158
 
122
159
  `validate` reports a missing `terms`, `terms_url`, `license` or `redistribute`. The other
123
- keys are checked when the manifest loads. Keys not listed here are kept, for a project's
124
- own reader.
160
+ keys are checked when the manifest loads. Keys not listed here are kept for your own reader.
125
161
 
126
- To have an editor with a TOML language server (Tombi, Taplo) check the manifest as you
127
- type, put this line at the top of `sources.toml`:
162
+ For checks in an editor with a TOML language server (Tombi, Taplo), put this line at the
163
+ top of `sources.toml`. `init` writes it, with the version you have installed in place of
164
+ `v0.3.1`:
128
165
 
129
166
  ```toml
130
- #:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/main/src/sourceledger/sources.schema.json
167
+ #:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/v0.3.1/src/sourceledger/sources.schema.json
131
168
  ```
132
169
 
133
170
  The schema accepts exactly what sourceledger accepts. A test keeps the two in step.
@@ -137,27 +174,32 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
137
174
  - It tries four times, waiting 5, 10 and 20 s between attempts, on 429, 500, 502, 503,
138
175
  504, network errors and a body cut short. A `Retry-After` header, in seconds or as a
139
176
  date, raises the wait to at most 120 s. Any other error status fails at once.
140
- - Each connect and read times out after 30 s, and one source's whole fetch after 300 s.
141
- - It asks for the file uncompressed, and refuses a compressed reply. The checksum is
142
- always of the file as published.
143
- - It refuses a redirect from a public host to a loopback, private or link-local
144
- address. When a redirect is followed, the record keeps the final URL too.
177
+ - Each connect and read times out after 30 s, and one source's whole fetch after 300 s. The
178
+ 300 s holds against a server that sends bytes slowly, give or take one 30 s socket timeout.
145
179
  - Every source is tried. When some fail, the others are still written, and the run
146
180
  exits 1 with one line per failed source.
147
- - Each download streams to a temporary file, hashed on the way, and is renamed into
148
- place. Memory stays small, and a crash never leaves half a file. A log line cut off by
149
- a crash is dropped on the next run.
150
181
  - A second fetch in the same project, while one runs, exits at once (a lock on
151
- `data/raw/.lock`, Linux and macOS only).
182
+ `data/raw/.lock`).
152
183
  - Each line it prints says `new` or `unchanged`, against the last version in the log.
153
- - For a source with `archive = true`, each connect and read of the Internet Archive
154
- request times out after 15 s. When it fails, fetch prints a warning, leaves
155
- `archive_url` empty, and still succeeds.
184
+ - For a source with `archive = true`, the Internet Archive request times out after 120 s
185
+ per connect and read. When it fails, fetch prints a warning, leaves `archive_url` empty,
186
+ and still succeeds. Save Page Now answers only once the snapshot is taken (49 s for a
187
+ GitHub page on 2026-10-20), and it captures one URL at most 5 times a day across all its
188
+ users. Past that it answers HTTP 429 with no `Retry-After`, and that fetch records no
189
+ snapshot.
190
+
191
+ The checks on redirects, compression and keys are in [Use sourceledger
192
+ safely](docs/secure-use.md). [How it works](docs/architecture.md#fetch) has the steps and
193
+ the crash safety.
156
194
 
157
195
  ## Other commands
158
196
 
159
- - `init` writes a starter `sources.toml` in the current directory: the schema line and one
160
- example source, commented out. It refuses to overwrite a `sources.toml` that exists.
197
+ - `init` writes a starter `sources.toml` in the current directory, or at `--manifest PATH`:
198
+ the schema line and one example source, commented out. It won't overwrite an existing one.
199
+ - `revisions OLD_LOG` lists the sources whose bytes changed since an earlier copy of the
200
+ log. Copy the log before you fetch (`cp data/fetches.jsonl before.jsonl`), then run
201
+ `sourceledger revisions before.jsonl`. A weekly CI run can use it to report a
202
+ publisher's revision.
161
203
  - `status` prints one line per source: its id, status and vintage, when its last logged
162
204
  version was fetched (or `never`), the start of its SHA-256, its licence, and whether
163
205
  the raw file may be republished. It reads the manifest and the log, never the network.
@@ -169,11 +211,17 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
169
211
  SHA-256 it gives. It prints one line per problem and exits 1 if there are any. It needs
170
212
  no `sources.toml` and no network.
171
213
 
214
+ Every command exits 1 on a failure or a problem. `revisions` exits 0 when sources changed,
215
+ by design: a test decides what a revision breaks.
216
+
172
217
  `fetch`, `build` and `validate` take `--only ID`, as often as needed, to work on just those
173
218
  sources. An id that is not in `sources.toml` is an error. `build --only` keeps the other
174
219
  sources' entries in `datapackage.json` as the last build wrote them, and
175
220
  `validate --only` skips the checks that cover the whole output.
176
221
 
222
+ Every command that reads the manifest reads `./sources.toml` unless given `--manifest PATH`.
223
+ The data folder stays `data/` in the current directory either way.
224
+
177
225
  ## Your own readers
178
226
 
179
227
  `sourceledger` reads every source with `parse_source`, which hands it to `parse_csv`,
@@ -203,11 +251,13 @@ my-dataset = "my_dataset.pipeline:main"
203
251
  ```
204
252
 
205
253
  `my-dataset fetch`, `build` and `validate` then use that reader, and publishers see
206
- `my-dataset` as the User-Agent. The
254
+ `my-dataset` as the User-Agent. A project that ships its `sources.toml` inside its package
255
+ passes the path as `manifest=Path(__file__).with_name("sources.toml")`. The
207
256
  [project-templates](https://github.com/simonvanlierde/project-templates) `data-pipeline`
208
- kind sets this up for you, with CI and a weekly revision report. The stages are also
257
+ kind sets this up, with CI and a weekly revision report. The stages are also
209
258
  functions: `load_manifest`, `fetch`, `build`, `validate`, `revisions`, `status`,
210
- `attribution` and `verify`.
259
+ `attribution` and `verify`. `verified(source)` returns a source's fetch record and raw
260
+ bytes after checking that both are current, for a reader that needs them.
211
261
 
212
262
  ## Compared with
213
263
 
@@ -229,6 +279,18 @@ the format of fetch records and the log. A breaking change to any of them comes
229
279
  minor version, listed in [CHANGELOG.md](CHANGELOG.md), with a warning first where that's
230
280
  cheap. Older fetch logs stay readable.
231
281
 
282
+ ## Roadmap
283
+
284
+ - A `release` stage that writes the metadata for a dataset release (RO-Crate, Croissant,
285
+ CodeMeta, Zenodo and a `SHA256SUMS` file), checks each with its official validator, and
286
+ keeps the data of `redistribute = false` sources out of the release.
287
+ - An error class per kind of failure, under `ValueError` and `OSError`, once the release
288
+ stage needs to tell them apart. This will not break code that catches the base classes.
289
+ - A review by [pyOpenSci](https://www.pyopensci.org) once the project has users besides
290
+ its own template.
291
+
292
+ Ideas and requests are welcome as [issues](https://github.com/simonvanlierde/sourceledger/issues).
293
+
232
294
  ## Development
233
295
 
234
296
  ```sh
@@ -238,6 +300,16 @@ prek install # git hooks
238
300
  just check # lint, types and tests, as CI runs them
239
301
  ```
240
302
 
303
+ [CONTRIBUTING.md](.github/CONTRIBUTING.md) has the coding standard, the test policy and
304
+ how dependencies are chosen. [GOVERNANCE.md](GOVERNANCE.md) says who decides what.
305
+ [docs/architecture.md](docs/architecture.md) explains how the stages fit together, and
306
+ [docs/secure-use.md](docs/secure-use.md) what sourceledger checks for you. Report a
307
+ vulnerability as [SECURITY.md](.github/SECURITY.md) describes.
308
+
309
+ The tests never touch the network, except those marked `live`. The mutation-testing run
310
+ (`just py-mutation`, about 2 minutes) and its baseline are explained in
311
+ [CONTRIBUTING.md](.github/CONTRIBUTING.md#tests).
312
+
241
313
  ## License
242
314
 
243
315
  MIT. See [LICENSE](LICENSE).
@@ -2,28 +2,28 @@
2
2
 
3
3
  [![python](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml/badge.svg)](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml)
4
4
  [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23460694.svg)](https://doi.org/10.5281/zenodo.23460694)
6
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/simonvanlierde/sourceledger/badge)](https://scorecard.dev/viewer/?uri=github.com/simonvanlierde/sourceledger)
7
+ [![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://app.codspeed.io/simonvanlierde/sourceledger?utm_source=badge)
5
8
 
6
9
  Build a dataset from public sources where every row says which download it came from.
7
10
 
8
11
  A project lists its inputs in `sources.toml`: each source's URL, the publisher's reuse
9
- terms, and whether the raw file may be republished. sourceledger runs four stages over it:
10
-
11
- - `fetch` downloads each source into `data/raw/` and writes a record beside it: the URL,
12
- the time, the SHA-256 and size, the vintage, and the server's ETag. The next fetch
13
- sends the ETag back, so an unchanged source isn't downloaded again. Each new version is
14
- also added to `data/fetches.jsonl`.
15
- - `build` re-hashes each download, reads it, and writes `data/processed/<id>.csv` with five
16
- provenance columns in front: `source_id`, `source_url`, `retrieved_at`, `vintage` and
17
- `raw_sha256`. It also writes `datapackage.json`, a
18
- [Frictionless Data Package](https://datapackage.org) that describes every output. The
19
- same records always give the same files.
12
+ terms, and whether the raw file may be republished. sourceledger runs three stages over it.
13
+ [How it works](docs/architecture.md) has the detail of each.
14
+
15
+ - `fetch` downloads each source into `data/raw/`, with a record beside it: the URL, the
16
+ time, the SHA-256 and size, the vintage, and the server's ETag and Last-Modified. An
17
+ unchanged source isn't downloaded again. Each new version is added to
18
+ `data/fetches.jsonl`.
19
+ - `build` writes `data/processed/<id>.csv` with five provenance columns in front, and a
20
+ [Frictionless Data Package](https://datapackage.org), `datapackage.json`, that describes
21
+ every output. The same records always give the same files.
20
22
  - `validate` re-reads the outputs and lists every problem it finds, such as an output from
21
- an older fetch, an edited raw file, a record made for another URL, vintage or pin, a
22
- source without reuse terms, or a `datapackage.json` that no longer matches.
23
- - `revisions OLD_LOG` lists the sources whose bytes changed since an earlier copy of the
24
- log. A weekly CI run can use it to report a publisher's revision.
23
+ an older fetch, an edited raw file, or a source without reuse terms.
25
24
 
26
- `init`, `status`, `attribution` and `verify` help around them: see [Other commands](#other-commands).
25
+ `init`, `status`, `attribution`, `verify` and `revisions` are commands around them: see
26
+ [Other commands](#other-commands).
27
27
 
28
28
  There are no dependencies. Excel files need the optional `xlsx` extra. The
29
29
  [docs page](https://simonvanlierde.github.io/sourceledger/) walks through a fetch and a
@@ -35,10 +35,46 @@ publisher's silent revision.
35
35
  uv add sourceledger # or 'sourceledger[xlsx]' to read Excel files
36
36
  ```
37
37
 
38
+ It needs Python 3.12 or later, and runs on Linux and macOS only (POSIX).
39
+
40
+ ### Verify a release
41
+
42
+ Each release is built and published by the
43
+ [release workflow](.github/workflows/python-release.yml), with no API token. PyPI keeps a
44
+ signed record of the workflow run that built each file. To check a wheel you downloaded,
45
+ pass its path:
46
+
47
+ ```sh
48
+ uvx pypi-attestations verify pypi --repository https://github.com/simonvanlierde/sourceledger \
49
+ sourceledger-0.3.1-py3-none-any.whl
50
+ ```
51
+
52
+ From 0.2.0, GitHub also keeps a signed build-provenance attestation for each file:
53
+
54
+ ```sh
55
+ gh attestation verify sourceledger-0.3.1-py3-none-any.whl --repo simonvanlierde/sourceledger
56
+ ```
57
+
58
+ Both fail unless the file is byte for byte the one this repository's workflow built.
59
+ From 0.3.1, the same provenance is also attached to each GitHub release as
60
+ `sourceledger-<version>.sigstore.json`.
61
+
62
+ You can also rebuild a release from its tag and compare. Built with the uv version the
63
+ release workflow pins (0.13.1 for 0.3.1), the wheel and sdist match the ones on PyPI byte
64
+ for byte:
65
+
66
+ ```sh
67
+ git clone https://github.com/simonvanlierde/sourceledger && cd sourceledger
68
+ mkdir sl-0.3.1 && git archive v0.3.1 | tar -x -C sl-0.3.1
69
+ uvx --from uv==0.13.1 uv build sl-0.3.1 -o dist
70
+ sha256sum dist/*
71
+ ```
72
+
73
+ Compare the hashes with the ones under "Download files" on PyPI.
74
+
38
75
  ## Quick start
39
76
 
40
- Write a `sources.toml` in the project root. `sourceledger init` writes one to start from,
41
- with this example commented out:
77
+ Write a `sources.toml` in the project root (`sourceledger init` writes a starter):
42
78
 
43
79
  ```toml
44
80
  [[source]]
@@ -85,24 +121,24 @@ Each `[[source]]` table takes these keys:
85
121
  | `terms`, `terms_url` | for implemented sources | The publisher's reuse terms in their words, and where they are stated. |
86
122
  | `license` | for implemented sources | The same terms as an [SPDX id](https://spdx.org/licenses/), such as `"CC-BY-4.0"`, or `"LicenseRef-<name>"` for terms with none. |
87
123
  | `redistribute` | for implemented sources | `true` if the terms let you republish the raw file, `false` if not. |
88
- | `vintage` | no | The edition you expect, such as `"2024 release"` or a TOML date. Recorded with each fetch and stamped on each row. `"not stated"` when absent. The old key `release` still works, with a warning. |
124
+ | `vintage` | no | The edition you expect, such as `"2024 release"` or a TOML date. Recorded with each fetch and stamped on each row. `"not stated"` when absent. The old name `release` is refused. |
89
125
  | `sha256` | no | The SHA-256 the download must have. Pin it for a fixed release, and `fetch` refuses bytes that changed upstream. |
90
- | `max_bytes` | no | The largest download `fetch` accepts. 200 MiB unless set. |
91
- | `format` | no | `"csv"`, `"json"` (an array of objects) or `"xlsx"`. Otherwise from the URL's extension: `.json`, `.xlsx`, and CSV for anything else. A gzipped CSV or JSON file is decompressed, within `max_bytes`. |
92
- | `sheet` | no | The Excel sheet to read. The first unless set. |
93
- | `headers` | no | Extra request headers, such as an API key, each value naming an environment variable: `{ Authorization = "env:EIA_TOKEN" }`. A literal value is refused, so a secret never lands in the manifest. The record keeps the header names, not the values, and a redirect to another host drops them. |
94
- | `archive` | no | `true` to ask the Internet Archive's [Save Page Now](https://web.archive.org/save) to snapshot the URL after each fetch that brings new bytes. The record keeps the snapshot's address as `archive_url`. Only for http and https URLs. The archive's request does not send `headers`, so don't use it on a source that needs a login. |
126
+ | `max_bytes` | no | The largest download `fetch` accepts. 200 MiB unless set. A gzipped file or Excel workbook that unpacks past it is refused. |
127
+ | `format` | no | `"csv"`, `"json"` (an array of objects) or `"xlsx"`. Otherwise from the URL's extension: `.json`, `.xlsx`, and CSV for anything else. A gzipped CSV or JSON file is decompressed, within `max_bytes`. JSON numbers are written as they appear in the file (`1e5` stays `1e5`, `1.10` stays `1.10`). |
128
+ | `sheet` | no | The Excel sheet to read. The first unless set. A cell right of the last header cell is refused, and a missing cell in a row reads as `""`. |
129
+ | `headers` | no | Extra request headers, such as an API key, each value naming an environment variable: `{ Authorization = "env:EIA_TOKEN" }`. A literal value is refused, and so is a `url` that is not https. The record keeps the header names, not the values. A redirect to another scheme, host or port drops them. |
130
+ | `archive` | no | `true` to ask the Internet Archive's [Save Page Now](https://web.archive.org/save) to snapshot the URL after each fetch that brings new bytes. The record keeps the snapshot's address as `archive_url`. Only for http and https URLs, and not for a source that needs `headers`: the archive's request sends none. |
95
131
  | `reason` | no | A note for people, such as why a source is unimplemented. sourceledger doesn't read it. |
96
132
 
97
133
  `validate` reports a missing `terms`, `terms_url`, `license` or `redistribute`. The other
98
- keys are checked when the manifest loads. Keys not listed here are kept, for a project's
99
- own reader.
134
+ keys are checked when the manifest loads. Keys not listed here are kept for your own reader.
100
135
 
101
- To have an editor with a TOML language server (Tombi, Taplo) check the manifest as you
102
- type, put this line at the top of `sources.toml`:
136
+ For checks in an editor with a TOML language server (Tombi, Taplo), put this line at the
137
+ top of `sources.toml`. `init` writes it, with the version you have installed in place of
138
+ `v0.3.1`:
103
139
 
104
140
  ```toml
105
- #:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/main/src/sourceledger/sources.schema.json
141
+ #:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/v0.3.1/src/sourceledger/sources.schema.json
106
142
  ```
107
143
 
108
144
  The schema accepts exactly what sourceledger accepts. A test keeps the two in step.
@@ -112,27 +148,32 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
112
148
  - It tries four times, waiting 5, 10 and 20 s between attempts, on 429, 500, 502, 503,
113
149
  504, network errors and a body cut short. A `Retry-After` header, in seconds or as a
114
150
  date, raises the wait to at most 120 s. Any other error status fails at once.
115
- - Each connect and read times out after 30 s, and one source's whole fetch after 300 s.
116
- - It asks for the file uncompressed, and refuses a compressed reply. The checksum is
117
- always of the file as published.
118
- - It refuses a redirect from a public host to a loopback, private or link-local
119
- address. When a redirect is followed, the record keeps the final URL too.
151
+ - Each connect and read times out after 30 s, and one source's whole fetch after 300 s. The
152
+ 300 s holds against a server that sends bytes slowly, give or take one 30 s socket timeout.
120
153
  - Every source is tried. When some fail, the others are still written, and the run
121
154
  exits 1 with one line per failed source.
122
- - Each download streams to a temporary file, hashed on the way, and is renamed into
123
- place. Memory stays small, and a crash never leaves half a file. A log line cut off by
124
- a crash is dropped on the next run.
125
155
  - A second fetch in the same project, while one runs, exits at once (a lock on
126
- `data/raw/.lock`, Linux and macOS only).
156
+ `data/raw/.lock`).
127
157
  - Each line it prints says `new` or `unchanged`, against the last version in the log.
128
- - For a source with `archive = true`, each connect and read of the Internet Archive
129
- request times out after 15 s. When it fails, fetch prints a warning, leaves
130
- `archive_url` empty, and still succeeds.
158
+ - For a source with `archive = true`, the Internet Archive request times out after 120 s
159
+ per connect and read. When it fails, fetch prints a warning, leaves `archive_url` empty,
160
+ and still succeeds. Save Page Now answers only once the snapshot is taken (49 s for a
161
+ GitHub page on 2026-10-20), and it captures one URL at most 5 times a day across all its
162
+ users. Past that it answers HTTP 429 with no `Retry-After`, and that fetch records no
163
+ snapshot.
164
+
165
+ The checks on redirects, compression and keys are in [Use sourceledger
166
+ safely](docs/secure-use.md). [How it works](docs/architecture.md#fetch) has the steps and
167
+ the crash safety.
131
168
 
132
169
  ## Other commands
133
170
 
134
- - `init` writes a starter `sources.toml` in the current directory: the schema line and one
135
- example source, commented out. It refuses to overwrite a `sources.toml` that exists.
171
+ - `init` writes a starter `sources.toml` in the current directory, or at `--manifest PATH`:
172
+ the schema line and one example source, commented out. It won't overwrite an existing one.
173
+ - `revisions OLD_LOG` lists the sources whose bytes changed since an earlier copy of the
174
+ log. Copy the log before you fetch (`cp data/fetches.jsonl before.jsonl`), then run
175
+ `sourceledger revisions before.jsonl`. A weekly CI run can use it to report a
176
+ publisher's revision.
136
177
  - `status` prints one line per source: its id, status and vintage, when its last logged
137
178
  version was fetched (or `never`), the start of its SHA-256, its licence, and whether
138
179
  the raw file may be republished. It reads the manifest and the log, never the network.
@@ -144,11 +185,17 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
144
185
  SHA-256 it gives. It prints one line per problem and exits 1 if there are any. It needs
145
186
  no `sources.toml` and no network.
146
187
 
188
+ Every command exits 1 on a failure or a problem. `revisions` exits 0 when sources changed,
189
+ by design: a test decides what a revision breaks.
190
+
147
191
  `fetch`, `build` and `validate` take `--only ID`, as often as needed, to work on just those
148
192
  sources. An id that is not in `sources.toml` is an error. `build --only` keeps the other
149
193
  sources' entries in `datapackage.json` as the last build wrote them, and
150
194
  `validate --only` skips the checks that cover the whole output.
151
195
 
196
+ Every command that reads the manifest reads `./sources.toml` unless given `--manifest PATH`.
197
+ The data folder stays `data/` in the current directory either way.
198
+
152
199
  ## Your own readers
153
200
 
154
201
  `sourceledger` reads every source with `parse_source`, which hands it to `parse_csv`,
@@ -178,11 +225,13 @@ my-dataset = "my_dataset.pipeline:main"
178
225
  ```
179
226
 
180
227
  `my-dataset fetch`, `build` and `validate` then use that reader, and publishers see
181
- `my-dataset` as the User-Agent. The
228
+ `my-dataset` as the User-Agent. A project that ships its `sources.toml` inside its package
229
+ passes the path as `manifest=Path(__file__).with_name("sources.toml")`. The
182
230
  [project-templates](https://github.com/simonvanlierde/project-templates) `data-pipeline`
183
- kind sets this up for you, with CI and a weekly revision report. The stages are also
231
+ kind sets this up, with CI and a weekly revision report. The stages are also
184
232
  functions: `load_manifest`, `fetch`, `build`, `validate`, `revisions`, `status`,
185
- `attribution` and `verify`.
233
+ `attribution` and `verify`. `verified(source)` returns a source's fetch record and raw
234
+ bytes after checking that both are current, for a reader that needs them.
186
235
 
187
236
  ## Compared with
188
237
 
@@ -204,6 +253,18 @@ the format of fetch records and the log. A breaking change to any of them comes
204
253
  minor version, listed in [CHANGELOG.md](CHANGELOG.md), with a warning first where that's
205
254
  cheap. Older fetch logs stay readable.
206
255
 
256
+ ## Roadmap
257
+
258
+ - A `release` stage that writes the metadata for a dataset release (RO-Crate, Croissant,
259
+ CodeMeta, Zenodo and a `SHA256SUMS` file), checks each with its official validator, and
260
+ keeps the data of `redistribute = false` sources out of the release.
261
+ - An error class per kind of failure, under `ValueError` and `OSError`, once the release
262
+ stage needs to tell them apart. This will not break code that catches the base classes.
263
+ - A review by [pyOpenSci](https://www.pyopensci.org) once the project has users besides
264
+ its own template.
265
+
266
+ Ideas and requests are welcome as [issues](https://github.com/simonvanlierde/sourceledger/issues).
267
+
207
268
  ## Development
208
269
 
209
270
  ```sh
@@ -213,6 +274,16 @@ prek install # git hooks
213
274
  just check # lint, types and tests, as CI runs them
214
275
  ```
215
276
 
277
+ [CONTRIBUTING.md](.github/CONTRIBUTING.md) has the coding standard, the test policy and
278
+ how dependencies are chosen. [GOVERNANCE.md](GOVERNANCE.md) says who decides what.
279
+ [docs/architecture.md](docs/architecture.md) explains how the stages fit together, and
280
+ [docs/secure-use.md](docs/secure-use.md) what sourceledger checks for you. Report a
281
+ vulnerability as [SECURITY.md](.github/SECURITY.md) describes.
282
+
283
+ The tests never touch the network, except those marked `live`. The mutation-testing run
284
+ (`just py-mutation`, about 2 minutes) and its baseline are explained in
285
+ [CONTRIBUTING.md](.github/CONTRIBUTING.md#tests).
286
+
216
287
  ## License
217
288
 
218
289
  MIT. See [LICENSE](LICENSE).
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sourceledger"
3
- version = "0.2.0"
3
+ version = "0.3.1"
4
4
  description = "Fetch, verify and validate the public sources a dataset is built from, with a provenance record for every download"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -17,6 +17,7 @@ keywords = [
17
17
  classifiers = [
18
18
  "Development Status :: 3 - Alpha",
19
19
  "Intended Audience :: Science/Research",
20
+ "Operating System :: POSIX",
20
21
  "Programming Language :: Python :: 3",
21
22
  "Programming Language :: Python :: 3.12",
22
23
  "Programming Language :: Python :: 3.13",
@@ -29,7 +30,7 @@ dependencies = []
29
30
 
30
31
  [[project.authors]]
31
32
  name = "Simon van Lierde"
32
- email = "90462640+simonvanlierde@users.noreply.github.com"
33
+ email = "code@duinlab.nl"
33
34
 
34
35
  [project.scripts]
35
36
  sourceledger = "sourceledger.cli:main"
@@ -44,13 +45,16 @@ xlsx = ["openpyxl>=3.1"]
44
45
  [dependency-groups]
45
46
  dev = [
46
47
  "frictionless>=5.20",
48
+ "hypothesis>=6.170.1",
47
49
  "jsonschema>=4.26",
48
50
  "openpyxl>=3.1",
49
51
  "pytest>=9.1.1",
52
+ "pytest-codspeed>=5.0.3",
50
53
  "pytest-cov>=7.1.0",
51
54
  "ruff>=0.16.10",
52
55
  "ty>=0.0.84",
53
56
  ]
57
+ mutation = ["mutmut>=3.8.0"]
54
58
 
55
59
  [build-system]
56
60
  requires = ["uv_build>=0.12.19,<0.14.0"]
@@ -103,7 +107,10 @@ addopts = [
103
107
  "--strict-config",
104
108
  "--strict-markers",
105
109
  "--import-mode=importlib",
110
+ "-m",
111
+ "not live",
106
112
  ]
113
+ markers = ["live: calls a real external service; deselected unless run with -m live"]
107
114
  testpaths = ["tests"]
108
115
 
109
116
  [tool.coverage.run]
@@ -117,3 +124,11 @@ exclude_also = [
117
124
  "if TYPE_CHECKING:",
118
125
  "raise NotImplementedError",
119
126
  ]
127
+
128
+ [tool.mutmut]
129
+ source_paths = ["src"]
130
+ also_copy = [
131
+ "README.md",
132
+ "docs",
133
+ ]
134
+ do_not_mutate_patterns = ['^\s*_logger\.\w+\(']