sourceledger 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sourceledger-0.2.0 → sourceledger-0.3.0}/PKG-INFO +103 -47
- {sourceledger-0.2.0 → sourceledger-0.3.0}/README.md +100 -45
- {sourceledger-0.2.0 → sourceledger-0.3.0}/pyproject.toml +17 -2
- {sourceledger-0.2.0 → sourceledger-0.3.0}/pyproject.toml.orig +20 -5
- {sourceledger-0.2.0 → sourceledger-0.3.0}/src/sourceledger/cli.py +21 -12
- {sourceledger-0.2.0 → sourceledger-0.3.0}/src/sourceledger/ledger.py +400 -125
- {sourceledger-0.2.0 → sourceledger-0.3.0}/src/sourceledger/sources.schema.json +7 -5
- {sourceledger-0.2.0 → sourceledger-0.3.0}/LICENSE +0 -0
- {sourceledger-0.2.0 → sourceledger-0.3.0}/src/sourceledger/__init__.py +0 -0
- {sourceledger-0.2.0 → sourceledger-0.3.0}/src/sourceledger/py.typed +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sourceledger
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
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 <
|
|
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
|
[](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml)
|
|
29
30
|
[](LICENSE)
|
|
31
|
+
[](https://doi.org/10.5281/zenodo.23460694)
|
|
32
|
+
[](https://scorecard.dev/viewer/?uri=github.com/simonvanlierde/sourceledger)
|
|
33
|
+
[](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
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
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 `
|
|
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,31 @@ 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.0-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.0-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
|
+
|
|
63
86
|
## Quick start
|
|
64
87
|
|
|
65
|
-
Write a `sources.toml` in the project root
|
|
66
|
-
with this example commented out:
|
|
88
|
+
Write a `sources.toml` in the project root (`sourceledger init` writes a starter):
|
|
67
89
|
|
|
68
90
|
```toml
|
|
69
91
|
[[source]]
|
|
@@ -110,21 +132,20 @@ Each `[[source]]` table takes these keys:
|
|
|
110
132
|
| `terms`, `terms_url` | for implemented sources | The publisher's reuse terms in their words, and where they are stated. |
|
|
111
133
|
| `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
134
|
| `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
|
|
135
|
+
| `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
136
|
| `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
|
|
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
|
|
137
|
+
| `max_bytes` | no | The largest download `fetch` accepts. 200 MiB unless set. A gzipped file or Excel workbook that unpacks past it is refused. |
|
|
138
|
+
| `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`). |
|
|
139
|
+
| `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 `""`. |
|
|
140
|
+
| `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. |
|
|
141
|
+
| `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
142
|
| `reason` | no | A note for people, such as why a source is unimplemented. sourceledger doesn't read it. |
|
|
121
143
|
|
|
122
144
|
`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
|
|
124
|
-
own reader.
|
|
145
|
+
keys are checked when the manifest loads. Keys not listed here are kept for your own reader.
|
|
125
146
|
|
|
126
|
-
|
|
127
|
-
|
|
147
|
+
For checks in an editor with a TOML language server (Tombi, Taplo), put this line at the
|
|
148
|
+
top of `sources.toml`:
|
|
128
149
|
|
|
129
150
|
```toml
|
|
130
151
|
#:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/main/src/sourceledger/sources.schema.json
|
|
@@ -137,27 +158,32 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
|
|
|
137
158
|
- It tries four times, waiting 5, 10 and 20 s between attempts, on 429, 500, 502, 503,
|
|
138
159
|
504, network errors and a body cut short. A `Retry-After` header, in seconds or as a
|
|
139
160
|
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
|
-
|
|
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.
|
|
161
|
+
- Each connect and read times out after 30 s, and one source's whole fetch after 300 s. The
|
|
162
|
+
300 s holds against a server that sends bytes slowly, give or take one 30 s socket timeout.
|
|
145
163
|
- Every source is tried. When some fail, the others are still written, and the run
|
|
146
164
|
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
165
|
- A second fetch in the same project, while one runs, exits at once (a lock on
|
|
151
|
-
`data/raw/.lock
|
|
166
|
+
`data/raw/.lock`).
|
|
152
167
|
- Each line it prints says `new` or `unchanged`, against the last version in the log.
|
|
153
|
-
- For a source with `archive = true`,
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
- For a source with `archive = true`, the Internet Archive request times out after 120 s
|
|
169
|
+
per connect and read. When it fails, fetch prints a warning, leaves `archive_url` empty,
|
|
170
|
+
and still succeeds. Save Page Now answers only once the snapshot is taken (49 s for a
|
|
171
|
+
GitHub page on 2026-10-20), and it captures one URL at most 5 times a day across all its
|
|
172
|
+
users. Past that it answers HTTP 429 with no `Retry-After`, and that fetch records no
|
|
173
|
+
snapshot.
|
|
174
|
+
|
|
175
|
+
The checks on redirects, compression and keys are in [Use sourceledger
|
|
176
|
+
safely](docs/secure-use.md). [How it works](docs/architecture.md#fetch) has the steps and
|
|
177
|
+
the crash safety.
|
|
156
178
|
|
|
157
179
|
## Other commands
|
|
158
180
|
|
|
159
|
-
- `init` writes a starter `sources.toml` in the current directory
|
|
160
|
-
example source, commented out. It
|
|
181
|
+
- `init` writes a starter `sources.toml` in the current directory, or at `--manifest PATH`:
|
|
182
|
+
the schema line and one example source, commented out. It won't overwrite an existing one.
|
|
183
|
+
- `revisions OLD_LOG` lists the sources whose bytes changed since an earlier copy of the
|
|
184
|
+
log. Copy the log before you fetch (`cp data/fetches.jsonl before.jsonl`), then run
|
|
185
|
+
`sourceledger revisions before.jsonl`. A weekly CI run can use it to report a
|
|
186
|
+
publisher's revision.
|
|
161
187
|
- `status` prints one line per source: its id, status and vintage, when its last logged
|
|
162
188
|
version was fetched (or `never`), the start of its SHA-256, its licence, and whether
|
|
163
189
|
the raw file may be republished. It reads the manifest and the log, never the network.
|
|
@@ -169,11 +195,17 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
|
|
|
169
195
|
SHA-256 it gives. It prints one line per problem and exits 1 if there are any. It needs
|
|
170
196
|
no `sources.toml` and no network.
|
|
171
197
|
|
|
198
|
+
Every command exits 1 on a failure or a problem. `revisions` exits 0 when sources changed,
|
|
199
|
+
by design: a test decides what a revision breaks.
|
|
200
|
+
|
|
172
201
|
`fetch`, `build` and `validate` take `--only ID`, as often as needed, to work on just those
|
|
173
202
|
sources. An id that is not in `sources.toml` is an error. `build --only` keeps the other
|
|
174
203
|
sources' entries in `datapackage.json` as the last build wrote them, and
|
|
175
204
|
`validate --only` skips the checks that cover the whole output.
|
|
176
205
|
|
|
206
|
+
Every command that reads the manifest reads `./sources.toml` unless given `--manifest PATH`.
|
|
207
|
+
The data folder stays `data/` in the current directory either way.
|
|
208
|
+
|
|
177
209
|
## Your own readers
|
|
178
210
|
|
|
179
211
|
`sourceledger` reads every source with `parse_source`, which hands it to `parse_csv`,
|
|
@@ -203,11 +235,13 @@ my-dataset = "my_dataset.pipeline:main"
|
|
|
203
235
|
```
|
|
204
236
|
|
|
205
237
|
`my-dataset fetch`, `build` and `validate` then use that reader, and publishers see
|
|
206
|
-
`my-dataset` as the User-Agent.
|
|
238
|
+
`my-dataset` as the User-Agent. A project that ships its `sources.toml` inside its package
|
|
239
|
+
passes the path as `manifest=Path(__file__).with_name("sources.toml")`. The
|
|
207
240
|
[project-templates](https://github.com/simonvanlierde/project-templates) `data-pipeline`
|
|
208
|
-
kind sets this up
|
|
241
|
+
kind sets this up, with CI and a weekly revision report. The stages are also
|
|
209
242
|
functions: `load_manifest`, `fetch`, `build`, `validate`, `revisions`, `status`,
|
|
210
|
-
`attribution` and `verify`.
|
|
243
|
+
`attribution` and `verify`. `verified(source)` returns a source's fetch record and raw
|
|
244
|
+
bytes after checking that both are current, for a reader that needs them.
|
|
211
245
|
|
|
212
246
|
## Compared with
|
|
213
247
|
|
|
@@ -229,6 +263,18 @@ the format of fetch records and the log. A breaking change to any of them comes
|
|
|
229
263
|
minor version, listed in [CHANGELOG.md](CHANGELOG.md), with a warning first where that's
|
|
230
264
|
cheap. Older fetch logs stay readable.
|
|
231
265
|
|
|
266
|
+
## Roadmap
|
|
267
|
+
|
|
268
|
+
- A `release` stage that writes the metadata for a dataset release (RO-Crate, Croissant,
|
|
269
|
+
CodeMeta, Zenodo and a `SHA256SUMS` file), checks each with its official validator, and
|
|
270
|
+
keeps the data of `redistribute = false` sources out of the release.
|
|
271
|
+
- An error class per kind of failure, under `ValueError` and `OSError`, once the release
|
|
272
|
+
stage needs to tell them apart. This will not break code that catches the base classes.
|
|
273
|
+
- A review by [pyOpenSci](https://www.pyopensci.org) once the project has users besides
|
|
274
|
+
its own template.
|
|
275
|
+
|
|
276
|
+
Ideas and requests are welcome as [issues](https://github.com/simonvanlierde/sourceledger/issues).
|
|
277
|
+
|
|
232
278
|
## Development
|
|
233
279
|
|
|
234
280
|
```sh
|
|
@@ -238,6 +284,16 @@ prek install # git hooks
|
|
|
238
284
|
just check # lint, types and tests, as CI runs them
|
|
239
285
|
```
|
|
240
286
|
|
|
287
|
+
[CONTRIBUTING.md](.github/CONTRIBUTING.md) has the coding standard, the test policy and
|
|
288
|
+
how dependencies are chosen. [GOVERNANCE.md](GOVERNANCE.md) says who decides what.
|
|
289
|
+
[docs/architecture.md](docs/architecture.md) explains how the stages fit together, and
|
|
290
|
+
[docs/secure-use.md](docs/secure-use.md) what sourceledger checks for you. Report a
|
|
291
|
+
vulnerability as [SECURITY.md](.github/SECURITY.md) describes.
|
|
292
|
+
|
|
293
|
+
The tests never touch the network, except those marked `live`. The mutation-testing run
|
|
294
|
+
(`just py-mutation`, about 2 minutes) and its baseline are explained in
|
|
295
|
+
[CONTRIBUTING.md](.github/CONTRIBUTING.md#tests).
|
|
296
|
+
|
|
241
297
|
## License
|
|
242
298
|
|
|
243
299
|
MIT. See [LICENSE](LICENSE).
|
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml)
|
|
4
4
|
[](LICENSE)
|
|
5
|
+
[](https://doi.org/10.5281/zenodo.23460694)
|
|
6
|
+
[](https://scorecard.dev/viewer/?uri=github.com/simonvanlierde/sourceledger)
|
|
7
|
+
[](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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
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 `
|
|
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,31 @@ 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.0-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.0-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
|
+
|
|
38
60
|
## Quick start
|
|
39
61
|
|
|
40
|
-
Write a `sources.toml` in the project root
|
|
41
|
-
with this example commented out:
|
|
62
|
+
Write a `sources.toml` in the project root (`sourceledger init` writes a starter):
|
|
42
63
|
|
|
43
64
|
```toml
|
|
44
65
|
[[source]]
|
|
@@ -85,21 +106,20 @@ Each `[[source]]` table takes these keys:
|
|
|
85
106
|
| `terms`, `terms_url` | for implemented sources | The publisher's reuse terms in their words, and where they are stated. |
|
|
86
107
|
| `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
108
|
| `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
|
|
109
|
+
| `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
110
|
| `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
|
|
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
|
|
111
|
+
| `max_bytes` | no | The largest download `fetch` accepts. 200 MiB unless set. A gzipped file or Excel workbook that unpacks past it is refused. |
|
|
112
|
+
| `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`). |
|
|
113
|
+
| `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 `""`. |
|
|
114
|
+
| `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. |
|
|
115
|
+
| `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
116
|
| `reason` | no | A note for people, such as why a source is unimplemented. sourceledger doesn't read it. |
|
|
96
117
|
|
|
97
118
|
`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
|
|
99
|
-
own reader.
|
|
119
|
+
keys are checked when the manifest loads. Keys not listed here are kept for your own reader.
|
|
100
120
|
|
|
101
|
-
|
|
102
|
-
|
|
121
|
+
For checks in an editor with a TOML language server (Tombi, Taplo), put this line at the
|
|
122
|
+
top of `sources.toml`:
|
|
103
123
|
|
|
104
124
|
```toml
|
|
105
125
|
#:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/main/src/sourceledger/sources.schema.json
|
|
@@ -112,27 +132,32 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
|
|
|
112
132
|
- It tries four times, waiting 5, 10 and 20 s between attempts, on 429, 500, 502, 503,
|
|
113
133
|
504, network errors and a body cut short. A `Retry-After` header, in seconds or as a
|
|
114
134
|
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
|
-
|
|
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.
|
|
135
|
+
- Each connect and read times out after 30 s, and one source's whole fetch after 300 s. The
|
|
136
|
+
300 s holds against a server that sends bytes slowly, give or take one 30 s socket timeout.
|
|
120
137
|
- Every source is tried. When some fail, the others are still written, and the run
|
|
121
138
|
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
139
|
- A second fetch in the same project, while one runs, exits at once (a lock on
|
|
126
|
-
`data/raw/.lock
|
|
140
|
+
`data/raw/.lock`).
|
|
127
141
|
- Each line it prints says `new` or `unchanged`, against the last version in the log.
|
|
128
|
-
- For a source with `archive = true`,
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
- For a source with `archive = true`, the Internet Archive request times out after 120 s
|
|
143
|
+
per connect and read. When it fails, fetch prints a warning, leaves `archive_url` empty,
|
|
144
|
+
and still succeeds. Save Page Now answers only once the snapshot is taken (49 s for a
|
|
145
|
+
GitHub page on 2026-10-20), and it captures one URL at most 5 times a day across all its
|
|
146
|
+
users. Past that it answers HTTP 429 with no `Retry-After`, and that fetch records no
|
|
147
|
+
snapshot.
|
|
148
|
+
|
|
149
|
+
The checks on redirects, compression and keys are in [Use sourceledger
|
|
150
|
+
safely](docs/secure-use.md). [How it works](docs/architecture.md#fetch) has the steps and
|
|
151
|
+
the crash safety.
|
|
131
152
|
|
|
132
153
|
## Other commands
|
|
133
154
|
|
|
134
|
-
- `init` writes a starter `sources.toml` in the current directory
|
|
135
|
-
example source, commented out. It
|
|
155
|
+
- `init` writes a starter `sources.toml` in the current directory, or at `--manifest PATH`:
|
|
156
|
+
the schema line and one example source, commented out. It won't overwrite an existing one.
|
|
157
|
+
- `revisions OLD_LOG` lists the sources whose bytes changed since an earlier copy of the
|
|
158
|
+
log. Copy the log before you fetch (`cp data/fetches.jsonl before.jsonl`), then run
|
|
159
|
+
`sourceledger revisions before.jsonl`. A weekly CI run can use it to report a
|
|
160
|
+
publisher's revision.
|
|
136
161
|
- `status` prints one line per source: its id, status and vintage, when its last logged
|
|
137
162
|
version was fetched (or `never`), the start of its SHA-256, its licence, and whether
|
|
138
163
|
the raw file may be republished. It reads the manifest and the log, never the network.
|
|
@@ -144,11 +169,17 @@ The schema accepts exactly what sourceledger accepts. A test keeps the two in st
|
|
|
144
169
|
SHA-256 it gives. It prints one line per problem and exits 1 if there are any. It needs
|
|
145
170
|
no `sources.toml` and no network.
|
|
146
171
|
|
|
172
|
+
Every command exits 1 on a failure or a problem. `revisions` exits 0 when sources changed,
|
|
173
|
+
by design: a test decides what a revision breaks.
|
|
174
|
+
|
|
147
175
|
`fetch`, `build` and `validate` take `--only ID`, as often as needed, to work on just those
|
|
148
176
|
sources. An id that is not in `sources.toml` is an error. `build --only` keeps the other
|
|
149
177
|
sources' entries in `datapackage.json` as the last build wrote them, and
|
|
150
178
|
`validate --only` skips the checks that cover the whole output.
|
|
151
179
|
|
|
180
|
+
Every command that reads the manifest reads `./sources.toml` unless given `--manifest PATH`.
|
|
181
|
+
The data folder stays `data/` in the current directory either way.
|
|
182
|
+
|
|
152
183
|
## Your own readers
|
|
153
184
|
|
|
154
185
|
`sourceledger` reads every source with `parse_source`, which hands it to `parse_csv`,
|
|
@@ -178,11 +209,13 @@ my-dataset = "my_dataset.pipeline:main"
|
|
|
178
209
|
```
|
|
179
210
|
|
|
180
211
|
`my-dataset fetch`, `build` and `validate` then use that reader, and publishers see
|
|
181
|
-
`my-dataset` as the User-Agent.
|
|
212
|
+
`my-dataset` as the User-Agent. A project that ships its `sources.toml` inside its package
|
|
213
|
+
passes the path as `manifest=Path(__file__).with_name("sources.toml")`. The
|
|
182
214
|
[project-templates](https://github.com/simonvanlierde/project-templates) `data-pipeline`
|
|
183
|
-
kind sets this up
|
|
215
|
+
kind sets this up, with CI and a weekly revision report. The stages are also
|
|
184
216
|
functions: `load_manifest`, `fetch`, `build`, `validate`, `revisions`, `status`,
|
|
185
|
-
`attribution` and `verify`.
|
|
217
|
+
`attribution` and `verify`. `verified(source)` returns a source's fetch record and raw
|
|
218
|
+
bytes after checking that both are current, for a reader that needs them.
|
|
186
219
|
|
|
187
220
|
## Compared with
|
|
188
221
|
|
|
@@ -204,6 +237,18 @@ the format of fetch records and the log. A breaking change to any of them comes
|
|
|
204
237
|
minor version, listed in [CHANGELOG.md](CHANGELOG.md), with a warning first where that's
|
|
205
238
|
cheap. Older fetch logs stay readable.
|
|
206
239
|
|
|
240
|
+
## Roadmap
|
|
241
|
+
|
|
242
|
+
- A `release` stage that writes the metadata for a dataset release (RO-Crate, Croissant,
|
|
243
|
+
CodeMeta, Zenodo and a `SHA256SUMS` file), checks each with its official validator, and
|
|
244
|
+
keeps the data of `redistribute = false` sources out of the release.
|
|
245
|
+
- An error class per kind of failure, under `ValueError` and `OSError`, once the release
|
|
246
|
+
stage needs to tell them apart. This will not break code that catches the base classes.
|
|
247
|
+
- A review by [pyOpenSci](https://www.pyopensci.org) once the project has users besides
|
|
248
|
+
its own template.
|
|
249
|
+
|
|
250
|
+
Ideas and requests are welcome as [issues](https://github.com/simonvanlierde/sourceledger/issues).
|
|
251
|
+
|
|
207
252
|
## Development
|
|
208
253
|
|
|
209
254
|
```sh
|
|
@@ -213,6 +258,16 @@ prek install # git hooks
|
|
|
213
258
|
just check # lint, types and tests, as CI runs them
|
|
214
259
|
```
|
|
215
260
|
|
|
261
|
+
[CONTRIBUTING.md](.github/CONTRIBUTING.md) has the coding standard, the test policy and
|
|
262
|
+
how dependencies are chosen. [GOVERNANCE.md](GOVERNANCE.md) says who decides what.
|
|
263
|
+
[docs/architecture.md](docs/architecture.md) explains how the stages fit together, and
|
|
264
|
+
[docs/secure-use.md](docs/secure-use.md) what sourceledger checks for you. Report a
|
|
265
|
+
vulnerability as [SECURITY.md](.github/SECURITY.md) describes.
|
|
266
|
+
|
|
267
|
+
The tests never touch the network, except those marked `live`. The mutation-testing run
|
|
268
|
+
(`just py-mutation`, about 2 minutes) and its baseline are explained in
|
|
269
|
+
[CONTRIBUTING.md](.github/CONTRIBUTING.md#tests).
|
|
270
|
+
|
|
216
271
|
## License
|
|
217
272
|
|
|
218
273
|
MIT. See [LICENSE](LICENSE).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sourceledger"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
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 = "
|
|
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+\(']
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sourceledger"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
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"
|
|
7
|
-
authors = [{ name = "Simon van Lierde", email = "
|
|
7
|
+
authors = [{ name = "Simon van Lierde", email = "code@duinlab.nl" }]
|
|
8
8
|
license = "MIT"
|
|
9
9
|
license-files = ["LICENSE"]
|
|
10
10
|
keywords = ["provenance", "data pipeline", "reproducibility", "open data", "research software", "FAIR"]
|
|
11
11
|
classifiers = [
|
|
12
12
|
"Development Status :: 3 - Alpha",
|
|
13
13
|
"Intended Audience :: Science/Research",
|
|
14
|
+
"Operating System :: POSIX",
|
|
14
15
|
"Programming Language :: Python :: 3",
|
|
15
16
|
"Programming Language :: Python :: 3.12",
|
|
16
17
|
"Programming Language :: Python :: 3.13",
|
|
@@ -38,21 +39,26 @@ xlsx = [
|
|
|
38
39
|
[dependency-groups]
|
|
39
40
|
dev = [
|
|
40
41
|
"frictionless>=5.20",
|
|
42
|
+
"hypothesis>=6.170.1",
|
|
41
43
|
"jsonschema>=4.26",
|
|
42
44
|
"openpyxl>=3.1",
|
|
43
45
|
"pytest>=9.1.1",
|
|
46
|
+
"pytest-codspeed>=5.0.3",
|
|
44
47
|
"pytest-cov>=7.1.0",
|
|
45
48
|
"ruff>=0.16.10",
|
|
46
49
|
"ty>=0.0.84",
|
|
47
50
|
]
|
|
51
|
+
mutation = [
|
|
52
|
+
"mutmut>=3.8.0",
|
|
53
|
+
]
|
|
48
54
|
|
|
49
55
|
[build-system]
|
|
50
56
|
requires = ["uv_build>=0.12.19,<0.14.0"]
|
|
51
57
|
build-backend = "uv_build"
|
|
52
58
|
|
|
53
59
|
# Resolve only releases at least a week old: a compromised release is usually
|
|
54
|
-
# caught and yanked within that window.
|
|
55
|
-
# not user-wide, so every machine writes the same uv.lock.
|
|
60
|
+
# caught and yanked within that window. Renovate's minimumReleaseAge waits the same.
|
|
61
|
+
# Set here, not user-wide, so every machine writes the same uv.lock.
|
|
56
62
|
[tool.uv]
|
|
57
63
|
exclude-newer = "1 week"
|
|
58
64
|
|
|
@@ -96,7 +102,9 @@ allow-magic-value-types = ["int"]
|
|
|
96
102
|
max-args = 10
|
|
97
103
|
|
|
98
104
|
[tool.pytest.ini_options]
|
|
99
|
-
|
|
105
|
+
# `live` tests reach real services; `pytest -m live` runs only them (the last -m wins).
|
|
106
|
+
addopts = ["-ra", "--strict-config", "--strict-markers", "--import-mode=importlib", "-m", "not live"]
|
|
107
|
+
markers = ["live: calls a real external service; deselected unless run with -m live"]
|
|
100
108
|
testpaths = ["tests"]
|
|
101
109
|
|
|
102
110
|
# Coverage is opt-in via `pytest --cov` (`just py-cov`), not addopts, because it
|
|
@@ -111,3 +119,10 @@ show_missing = true
|
|
|
111
119
|
# workflow tests the installed wheel, where src/ is not what runs.
|
|
112
120
|
fail_under = 95
|
|
113
121
|
exclude_also = ["if TYPE_CHECKING:", "raise NotImplementedError"]
|
|
122
|
+
|
|
123
|
+
# `just py-mutation` runs it. The docs tests read the README and docs/ from the copy.
|
|
124
|
+
[tool.mutmut]
|
|
125
|
+
source_paths = ["src"]
|
|
126
|
+
also_copy = ["README.md", "docs"]
|
|
127
|
+
# Log calls only change diagnostics; their mutants would all survive.
|
|
128
|
+
do_not_mutate_patterns = ['^\s*_logger\.\w+\(']
|