sourceledger 0.1.0__tar.gz → 0.2.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.
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: sourceledger
3
+ Version: 0.2.0
4
+ Summary: Fetch, verify and validate the public sources a dataset is built from, with a provenance record for every download
5
+ Keywords: provenance,data pipeline,reproducibility,open data,research software,FAIR
6
+ Author: Simon van Lierde
7
+ Author-email: Simon van Lierde <90462640+simonvanlierde@users.noreply.github.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
17
+ Classifier: Topic :: Scientific/Engineering
18
+ Classifier: Typing :: Typed
19
+ Requires-Dist: openpyxl>=3.1 ; extra == 'xlsx'
20
+ Requires-Python: >=3.12
21
+ Project-URL: Homepage, https://github.com/simonvanlierde/sourceledger
22
+ Project-URL: Issues, https://github.com/simonvanlierde/sourceledger/issues
23
+ Provides-Extra: xlsx
24
+ Description-Content-Type: text/markdown
25
+
26
+ # sourceledger
27
+
28
+ [![python](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml/badge.svg)](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml)
29
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
30
+
31
+ Build a dataset from public sources where every row says which download it came from.
32
+
33
+ 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.
45
+ - `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.
50
+
51
+ `init`, `status`, `attribution` and `verify` help around them: see [Other commands](#other-commands).
52
+
53
+ There are no dependencies. Excel files need the optional `xlsx` extra. The
54
+ [docs page](https://simonvanlierde.github.io/sourceledger/) walks through a fetch and a
55
+ publisher's silent revision.
56
+
57
+ ## Install
58
+
59
+ ```sh
60
+ uv add sourceledger # or 'sourceledger[xlsx]' to read Excel files
61
+ ```
62
+
63
+ ## Quick start
64
+
65
+ Write a `sources.toml` in the project root. `sourceledger init` writes one to start from,
66
+ with this example commented out:
67
+
68
+ ```toml
69
+ [[source]]
70
+ id = "co2"
71
+ status = "implemented"
72
+ url = "https://raw.githubusercontent.com/datasets/co2-ppm/main/data/co2-annmean-mlo.csv"
73
+ vintage = "main branch, unversioned"
74
+ terms = "ODC-PDDL-1.0 (datasets/co2-ppm package; original data from NOAA GML)"
75
+ terms_url = "https://opendatacommons.org/licenses/pddl/"
76
+ license = "PDDL-1.0"
77
+ redistribute = true
78
+ ```
79
+
80
+ Then run the stages from that directory:
81
+
82
+ ```sh
83
+ sourceledger fetch
84
+ sourceledger build
85
+ sourceledger validate
86
+ ```
87
+
88
+ `sourceledger` reads CSV (gzipped or not), JSON and Excel, by each source's `format` or its
89
+ URL's extension. For other formats, see [Your own readers](#your-own-readers).
90
+
91
+ ## What to commit
92
+
93
+ Commit `sources.toml` and `data/fetches.jsonl`. The log holds checksums and URLs, not
94
+ data: it's the history of every version you have fetched.
95
+
96
+ Keep `data/raw/` and `data/processed/` out of git, so the repository never redistributes
97
+ a publisher's data. The `.fetch.json` records live in `data/raw/` too, so a fresh clone
98
+ runs `fetch` before `build` and `validate`.
99
+
100
+ ## sources.toml
101
+
102
+ Each `[[source]]` table takes these keys:
103
+
104
+ | Key | Required | Meaning |
105
+ | --- | --- | --- |
106
+ | `id` | yes | ASCII letters, digits, `_` and `-`. Names the raw file (`id` plus the URL's extension) and the output. |
107
+ | `name` | no | A title for people. The data package and `attribution` show it in place of the id. |
108
+ | `status` | yes | `"implemented"`, read by every stage, or `"unimplemented"`: a source you know about but don't read yet. `validate` fails if one of those has output. |
109
+ | `url` | for implemented sources | What `fetch` downloads. Change it and `build` refuses the old download until you fetch again. |
110
+ | `terms`, `terms_url` | for implemented sources | The publisher's reuse terms in their words, and where they are stated. |
111
+ | `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
+ | `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. |
114
+ | `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. |
120
+ | `reason` | no | A note for people, such as why a source is unimplemented. sourceledger doesn't read it. |
121
+
122
+ `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.
125
+
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`:
128
+
129
+ ```toml
130
+ #:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/main/src/sourceledger/sources.schema.json
131
+ ```
132
+
133
+ The schema accepts exactly what sourceledger accepts. A test keeps the two in step.
134
+
135
+ ## How fetch behaves
136
+
137
+ - It tries four times, waiting 5, 10 and 20 s between attempts, on 429, 500, 502, 503,
138
+ 504, network errors and a body cut short. A `Retry-After` header, in seconds or as a
139
+ 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.
145
+ - Every source is tried. When some fail, the others are still written, and the run
146
+ 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
+ - A second fetch in the same project, while one runs, exits at once (a lock on
151
+ `data/raw/.lock`, Linux and macOS only).
152
+ - 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.
156
+
157
+ ## Other commands
158
+
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.
161
+ - `status` prints one line per source: its id, status and vintage, when its last logged
162
+ version was fetched (or `never`), the start of its SHA-256, its licence, and whether
163
+ the raw file may be republished. It reads the manifest and the log, never the network.
164
+ - `attribution` prints a Markdown table of the implemented sources, in manifest order:
165
+ name, terms in the publisher's words, licence, terms URL, and whether the raw file may be
166
+ republished. Paste it into a dataset's README or release notes.
167
+ - `verify DIR` is for someone who downloaded a published dataset. It reads
168
+ `DIR/datapackage.json` and checks that each file it lists exists, with the size and
169
+ SHA-256 it gives. It prints one line per problem and exits 1 if there are any. It needs
170
+ no `sources.toml` and no network.
171
+
172
+ `fetch`, `build` and `validate` take `--only ID`, as often as needed, to work on just those
173
+ sources. An id that is not in `sources.toml` is an error. `build --only` keeps the other
174
+ sources' entries in `datapackage.json` as the last build wrote them, and
175
+ `validate --only` skips the checks that cover the whole output.
176
+
177
+ ## Your own readers
178
+
179
+ `sourceledger` reads every source with `parse_source`, which hands it to `parse_csv`,
180
+ `parse_json` or `parse_xlsx`. For another format, a project writes its own reader, a
181
+ function from a source's manifest table and raw bytes to columns and rows, and its own
182
+ command:
183
+
184
+ ```python
185
+ # src/my_dataset/pipeline.py
186
+ import sourceledger
187
+ from sourceledger import Source
188
+
189
+
190
+ def parse(source: Source, payload: bytes) -> tuple[list[str], list[dict[str, str]]]:
191
+ """Branch on source["id"] for a source in a format sourceledger doesn't read."""
192
+ return sourceledger.parse_source(source, payload)
193
+
194
+
195
+ def main(argv: list[str] | None = None) -> int:
196
+ return sourceledger.main(argv, parse=parse, prog="my-dataset", user_agent="my-dataset")
197
+ ```
198
+
199
+ ```toml
200
+ # pyproject.toml
201
+ [project.scripts]
202
+ my-dataset = "my_dataset.pipeline:main"
203
+ ```
204
+
205
+ `my-dataset fetch`, `build` and `validate` then use that reader, and publishers see
206
+ `my-dataset` as the User-Agent. The
207
+ [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
209
+ functions: `load_manifest`, `fetch`, `build`, `validate`, `revisions`, `status`,
210
+ `attribution` and `verify`.
211
+
212
+ ## Compared with
213
+
214
+ Other tools cover parts of this. Use one of them when that part is all you need.
215
+
216
+ | Tool | What it does well | What sourceledger adds |
217
+ | --- | --- | --- |
218
+ | [pooch](https://www.fatiando.org/pooch/) | Downloads files with a known hash, caches them, retries. Made for packages that ship sample data. | A record of every fetch on disk, conditional re-fetches, a history of versions, provenance in each output row, and reuse terms checked per source. |
219
+ | [DVC](https://dvc.org) `import-url` | Tracks a downloaded file's URL with its checksum or ETag, and `dvc update` notices a change. The closest overlap. | No cache or `.dvc` files to adopt, reuse terms per source, provenance in each output row, and a Data Package for the outputs. |
220
+ | [DataLad](https://www.datalad.org) `download-url` | Records where every file came from in git and git-annex, as part of full dataset version control. | A plain manifest and one committed log, no git-annex, and reuse terms per source. |
221
+ | [frictionless-py](https://framework.frictionlessdata.io) | Describes and validates Data Packages, with licences, sources and hashes per resource. | The fetch, verify and revision steps. `build` writes a Data Package, so the two work together. |
222
+
223
+ Checked against each project's code and docs on 2026-10-18.
224
+
225
+ ## Stability
226
+
227
+ Until 1.0, the public API is `sourceledger`'s `__all__`, the keys of `sources.toml`, and
228
+ the format of fetch records and the log. A breaking change to any of them comes only in a
229
+ minor version, listed in [CHANGELOG.md](CHANGELOG.md), with a warning first where that's
230
+ cheap. Older fetch logs stay readable.
231
+
232
+ ## Development
233
+
234
+ ```sh
235
+ uv sync
236
+ uv tool install prek # once per machine
237
+ prek install # git hooks
238
+ just check # lint, types and tests, as CI runs them
239
+ ```
240
+
241
+ ## License
242
+
243
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,218 @@
1
+ # sourceledger
2
+
3
+ [![python](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml/badge.svg)](https://github.com/simonvanlierde/sourceledger/actions/workflows/python.yml)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+
6
+ Build a dataset from public sources where every row says which download it came from.
7
+
8
+ 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.
20
+ - `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.
25
+
26
+ `init`, `status`, `attribution` and `verify` help around them: see [Other commands](#other-commands).
27
+
28
+ There are no dependencies. Excel files need the optional `xlsx` extra. The
29
+ [docs page](https://simonvanlierde.github.io/sourceledger/) walks through a fetch and a
30
+ publisher's silent revision.
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ uv add sourceledger # or 'sourceledger[xlsx]' to read Excel files
36
+ ```
37
+
38
+ ## Quick start
39
+
40
+ Write a `sources.toml` in the project root. `sourceledger init` writes one to start from,
41
+ with this example commented out:
42
+
43
+ ```toml
44
+ [[source]]
45
+ id = "co2"
46
+ status = "implemented"
47
+ url = "https://raw.githubusercontent.com/datasets/co2-ppm/main/data/co2-annmean-mlo.csv"
48
+ vintage = "main branch, unversioned"
49
+ terms = "ODC-PDDL-1.0 (datasets/co2-ppm package; original data from NOAA GML)"
50
+ terms_url = "https://opendatacommons.org/licenses/pddl/"
51
+ license = "PDDL-1.0"
52
+ redistribute = true
53
+ ```
54
+
55
+ Then run the stages from that directory:
56
+
57
+ ```sh
58
+ sourceledger fetch
59
+ sourceledger build
60
+ sourceledger validate
61
+ ```
62
+
63
+ `sourceledger` reads CSV (gzipped or not), JSON and Excel, by each source's `format` or its
64
+ URL's extension. For other formats, see [Your own readers](#your-own-readers).
65
+
66
+ ## What to commit
67
+
68
+ Commit `sources.toml` and `data/fetches.jsonl`. The log holds checksums and URLs, not
69
+ data: it's the history of every version you have fetched.
70
+
71
+ Keep `data/raw/` and `data/processed/` out of git, so the repository never redistributes
72
+ a publisher's data. The `.fetch.json` records live in `data/raw/` too, so a fresh clone
73
+ runs `fetch` before `build` and `validate`.
74
+
75
+ ## sources.toml
76
+
77
+ Each `[[source]]` table takes these keys:
78
+
79
+ | Key | Required | Meaning |
80
+ | --- | --- | --- |
81
+ | `id` | yes | ASCII letters, digits, `_` and `-`. Names the raw file (`id` plus the URL's extension) and the output. |
82
+ | `name` | no | A title for people. The data package and `attribution` show it in place of the id. |
83
+ | `status` | yes | `"implemented"`, read by every stage, or `"unimplemented"`: a source you know about but don't read yet. `validate` fails if one of those has output. |
84
+ | `url` | for implemented sources | What `fetch` downloads. Change it and `build` refuses the old download until you fetch again. |
85
+ | `terms`, `terms_url` | for implemented sources | The publisher's reuse terms in their words, and where they are stated. |
86
+ | `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
+ | `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. |
89
+ | `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. |
95
+ | `reason` | no | A note for people, such as why a source is unimplemented. sourceledger doesn't read it. |
96
+
97
+ `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.
100
+
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`:
103
+
104
+ ```toml
105
+ #:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/main/src/sourceledger/sources.schema.json
106
+ ```
107
+
108
+ The schema accepts exactly what sourceledger accepts. A test keeps the two in step.
109
+
110
+ ## How fetch behaves
111
+
112
+ - It tries four times, waiting 5, 10 and 20 s between attempts, on 429, 500, 502, 503,
113
+ 504, network errors and a body cut short. A `Retry-After` header, in seconds or as a
114
+ 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.
120
+ - Every source is tried. When some fail, the others are still written, and the run
121
+ 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
+ - A second fetch in the same project, while one runs, exits at once (a lock on
126
+ `data/raw/.lock`, Linux and macOS only).
127
+ - 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.
131
+
132
+ ## Other commands
133
+
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.
136
+ - `status` prints one line per source: its id, status and vintage, when its last logged
137
+ version was fetched (or `never`), the start of its SHA-256, its licence, and whether
138
+ the raw file may be republished. It reads the manifest and the log, never the network.
139
+ - `attribution` prints a Markdown table of the implemented sources, in manifest order:
140
+ name, terms in the publisher's words, licence, terms URL, and whether the raw file may be
141
+ republished. Paste it into a dataset's README or release notes.
142
+ - `verify DIR` is for someone who downloaded a published dataset. It reads
143
+ `DIR/datapackage.json` and checks that each file it lists exists, with the size and
144
+ SHA-256 it gives. It prints one line per problem and exits 1 if there are any. It needs
145
+ no `sources.toml` and no network.
146
+
147
+ `fetch`, `build` and `validate` take `--only ID`, as often as needed, to work on just those
148
+ sources. An id that is not in `sources.toml` is an error. `build --only` keeps the other
149
+ sources' entries in `datapackage.json` as the last build wrote them, and
150
+ `validate --only` skips the checks that cover the whole output.
151
+
152
+ ## Your own readers
153
+
154
+ `sourceledger` reads every source with `parse_source`, which hands it to `parse_csv`,
155
+ `parse_json` or `parse_xlsx`. For another format, a project writes its own reader, a
156
+ function from a source's manifest table and raw bytes to columns and rows, and its own
157
+ command:
158
+
159
+ ```python
160
+ # src/my_dataset/pipeline.py
161
+ import sourceledger
162
+ from sourceledger import Source
163
+
164
+
165
+ def parse(source: Source, payload: bytes) -> tuple[list[str], list[dict[str, str]]]:
166
+ """Branch on source["id"] for a source in a format sourceledger doesn't read."""
167
+ return sourceledger.parse_source(source, payload)
168
+
169
+
170
+ def main(argv: list[str] | None = None) -> int:
171
+ return sourceledger.main(argv, parse=parse, prog="my-dataset", user_agent="my-dataset")
172
+ ```
173
+
174
+ ```toml
175
+ # pyproject.toml
176
+ [project.scripts]
177
+ my-dataset = "my_dataset.pipeline:main"
178
+ ```
179
+
180
+ `my-dataset fetch`, `build` and `validate` then use that reader, and publishers see
181
+ `my-dataset` as the User-Agent. The
182
+ [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
184
+ functions: `load_manifest`, `fetch`, `build`, `validate`, `revisions`, `status`,
185
+ `attribution` and `verify`.
186
+
187
+ ## Compared with
188
+
189
+ Other tools cover parts of this. Use one of them when that part is all you need.
190
+
191
+ | Tool | What it does well | What sourceledger adds |
192
+ | --- | --- | --- |
193
+ | [pooch](https://www.fatiando.org/pooch/) | Downloads files with a known hash, caches them, retries. Made for packages that ship sample data. | A record of every fetch on disk, conditional re-fetches, a history of versions, provenance in each output row, and reuse terms checked per source. |
194
+ | [DVC](https://dvc.org) `import-url` | Tracks a downloaded file's URL with its checksum or ETag, and `dvc update` notices a change. The closest overlap. | No cache or `.dvc` files to adopt, reuse terms per source, provenance in each output row, and a Data Package for the outputs. |
195
+ | [DataLad](https://www.datalad.org) `download-url` | Records where every file came from in git and git-annex, as part of full dataset version control. | A plain manifest and one committed log, no git-annex, and reuse terms per source. |
196
+ | [frictionless-py](https://framework.frictionlessdata.io) | Describes and validates Data Packages, with licences, sources and hashes per resource. | The fetch, verify and revision steps. `build` writes a Data Package, so the two work together. |
197
+
198
+ Checked against each project's code and docs on 2026-10-18.
199
+
200
+ ## Stability
201
+
202
+ Until 1.0, the public API is `sourceledger`'s `__all__`, the keys of `sources.toml`, and
203
+ the format of fetch records and the log. A breaking change to any of them comes only in a
204
+ minor version, listed in [CHANGELOG.md](CHANGELOG.md), with a warning first where that's
205
+ cheap. Older fetch logs stay readable.
206
+
207
+ ## Development
208
+
209
+ ```sh
210
+ uv sync
211
+ uv tool install prek # once per machine
212
+ prek install # git hooks
213
+ just check # lint, types and tests, as CI runs them
214
+ ```
215
+
216
+ ## License
217
+
218
+ MIT. See [LICENSE](LICENSE).
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sourceledger"
3
- version = "0.1.0"
3
+ version = "0.2.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"
@@ -18,6 +18,10 @@ classifiers = [
18
18
  "Development Status :: 3 - Alpha",
19
19
  "Intended Audience :: Science/Research",
20
20
  "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Programming Language :: Python :: 3.15",
21
25
  "Topic :: Scientific/Engineering",
22
26
  "Typing :: Typed",
23
27
  ]
@@ -34,8 +38,14 @@ sourceledger = "sourceledger.cli:main"
34
38
  Homepage = "https://github.com/simonvanlierde/sourceledger"
35
39
  Issues = "https://github.com/simonvanlierde/sourceledger/issues"
36
40
 
41
+ [project.optional-dependencies]
42
+ xlsx = ["openpyxl>=3.1"]
43
+
37
44
  [dependency-groups]
38
45
  dev = [
46
+ "frictionless>=5.20",
47
+ "jsonschema>=4.26",
48
+ "openpyxl>=3.1",
39
49
  "pytest>=9.1.1",
40
50
  "pytest-cov>=7.1.0",
41
51
  "ruff>=0.16.10",
@@ -102,6 +112,7 @@ branch = true
102
112
 
103
113
  [tool.coverage.report]
104
114
  show_missing = true
115
+ fail_under = 95
105
116
  exclude_also = [
106
117
  "if TYPE_CHECKING:",
107
118
  "raise NotImplementedError",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sourceledger"
3
- version = "0.1.0"
3
+ version = "0.2.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"
@@ -12,6 +12,10 @@ classifiers = [
12
12
  "Development Status :: 3 - Alpha",
13
13
  "Intended Audience :: Science/Research",
14
14
  "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ "Programming Language :: Python :: 3.15",
15
19
  "Topic :: Scientific/Engineering",
16
20
  "Typing :: Typed",
17
21
  ]
@@ -26,8 +30,16 @@ sourceledger = "sourceledger.cli:main"
26
30
  Homepage = "https://github.com/simonvanlierde/sourceledger"
27
31
  Issues = "https://github.com/simonvanlierde/sourceledger/issues"
28
32
 
33
+ [project.optional-dependencies]
34
+ xlsx = [
35
+ "openpyxl>=3.1",
36
+ ]
37
+
29
38
  [dependency-groups]
30
39
  dev = [
40
+ "frictionless>=5.20",
41
+ "jsonschema>=4.26",
42
+ "openpyxl>=3.1",
31
43
  "pytest>=9.1.1",
32
44
  "pytest-cov>=7.1.0",
33
45
  "ruff>=0.16.10",
@@ -88,12 +100,14 @@ addopts = ["-ra", "--strict-config", "--strict-markers", "--import-mode=importli
88
100
  testpaths = ["tests"]
89
101
 
90
102
  # Coverage is opt-in via `pytest --cov` (`just py-cov`), not addopts, because it
91
- # slows every plain test run. No fail_under until there is a suite worth setting
92
- # one against.
103
+ # slows every plain test run. CI's run fails under the fail_under below.
93
104
  [tool.coverage.run]
94
105
  source = ["src"]
95
106
  branch = true
96
107
 
97
108
  [tool.coverage.report]
98
109
  show_missing = true
110
+ # CI runs the suite with --cov and fails below this. Not in addopts: the release
111
+ # workflow tests the installed wheel, where src/ is not what runs.
112
+ fail_under = 95
99
113
  exclude_also = ["if TYPE_CHECKING:", "raise NotImplementedError"]
@@ -14,14 +14,20 @@ from sourceledger.ledger import (
14
14
  FetchRecord,
15
15
  Parser,
16
16
  Source,
17
+ attribution,
17
18
  build,
18
19
  fetch,
19
20
  load_manifest,
20
21
  parse_csv,
22
+ parse_json,
23
+ parse_source,
24
+ parse_xlsx,
21
25
  read_output,
22
26
  revisions,
27
+ status,
23
28
  validate,
24
29
  verified,
30
+ verify,
25
31
  )
26
32
 
27
33
  __all__ = [
@@ -30,13 +36,19 @@ __all__ = [
30
36
  "FetchRecord",
31
37
  "Parser",
32
38
  "Source",
39
+ "attribution",
33
40
  "build",
34
41
  "fetch",
35
42
  "load_manifest",
36
43
  "main",
37
44
  "parse_csv",
45
+ "parse_json",
46
+ "parse_source",
47
+ "parse_xlsx",
38
48
  "read_output",
39
49
  "revisions",
50
+ "status",
40
51
  "validate",
41
52
  "verified",
53
+ "verify",
42
54
  ]