Skip to content

Manifest and commands

This page lists the manifest keys, the commands, their JSON reports and the HTML provenance report. Recipes covers custom readers and other download tools, and download behavior the retries and limits.

sources.toml

A source is one file you download. A vintage is the edition you expect to use, such as a release year. The manifest records its reuse terms; it does not decide whether those terms permit your intended use.

Set output_format before the first [[source]] table to choose the project's table outputs:

output_format = "parquet"

Install the CLI with uv tool install 'sourceledger[parquet]' first. For a Python project, use uv add 'sourceledger[parquet]' and run commands with uv run sourceledger. build writes <id>.parquet with zstd compression and an explicit string schema, including the five provenance columns. Values such as 001, 1.10 and empty strings keep their spelling. validate and read_output read these tables with the same extra. The Parquet extra uses PyArrow. Writing and validation process at most 10,000 rows per batch. Validation decodes every column, including ordinary data columns, to detect unreadable pages. Memory also depends on row width, file metadata and encoded column dictionaries; this is not a fixed byte cap. JSON, Excel and custom readers still hold their input and parsed rows in memory. read_output yields one row at a time, so a large table is never held in memory; wrap it in list() to hold it all. It is a generator: a missing or unreadable file raises on the first next(), not at the call, and an iterator left unfinished keeps the file open, which on Windows blocks replacing the output. datapackage.json records the format and media type; verify checks the bytes without needing the extra.

The default is output_format = "csv". format = "file" sources keep their original bytes in either mode. Every CSV row repeats the five provenance columns, so a CSV output of a narrow table is many times the size of its raw file: a two-column table of 200,000 rows came out 14 times larger. Parquet stores those repeated values once per column chunk; the same table was smaller than its raw file. Use Parquet for large tables. data/processed/ holds only build outputs and datapackage.json: validate reports any other file there, so keep a project's own files elsewhere, as data/extra/. When switching formats, move old outputs out of data/processed/ before rebuilding; validate reports them as unclaimed files. Library callers pass output_format="parquet" to both build and validate; load_manifest returns only source tables.

To record the code that built a resource, pass build_revision to the Python build, main or entry function. The value appears in the resource's sourceledger.build_revision in datapackage.json. A build with --only keeps the other resources and their revisions. Dataset releases preserve this field.

Set release_formats there too to have release write the optional metadata files:

release_formats = ["ro-crate", "croissant"]

Without it, release writes neither; see release a dataset.

Set name there to name the data package in datapackage.json:

name = "co2-annual"

Put it above the first [[source]]: below one, TOML makes it that source's title. It takes lower case letters, digits, ., _ and -, and validate and release check that datapackage.json has it. Without it, build uses the [project] name in ./pyproject.toml, or else the current folder's name, made lower case. The folder differs between clones, worktrees and CI, so set name or keep a pyproject.toml when the file must be the same everywhere. Library callers pass name= to build, validate and release; load_package_name reads it. Without name=, validate and release skip the name check, as the fallbacks differ between checkouts. The check runs under validate --only too.

name, output_format, release_formats and [[source]] are the only top-level keys. Any other, such as a misspelt [[sources]], is refused, with the intended name when one is close, so a typo never reads as an empty manifest. A source table may hold extra keys for your own reader.

Each [[source]] table takes these keys:

Key Required Meaning
id yes ASCII letters, digits, _ and -. Names the raw file (id plus the URL's extension) and the output. Unique ignoring case, and not a Windows device name (CON, PRN, AUX, NUL, COM1 to COM9, LPT1 to LPT9), since either would name the wrong file on some system.
name no A title for people. The data package and attribution show it in place of the id.
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.
url for implemented sources What fetch downloads. Change it and build refuses the old download until you fetch again. A user name or password in it is refused: send it in headers. Outside the host it must be ASCII: percent-encode other characters as UTF-8, as d%C3%A4.csv for dä.csv. A non-ASCII host is fine.
terms, terms_url for implemented sources The publisher's reuse terms in their words, and where they are stated.
license for implemented sources The same terms as an SPDX id, such as "CC-BY-4.0", or "LicenseRef-<name>" for terms with none.
redistribute for implemented sources true if the terms let you republish the raw file, false if not.
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.
sha256 no The SHA-256 the download must have. Pin it for a fixed release, and fetch refuses bytes that changed upstream.
max_bytes no The largest download fetch accepts. 200 MiB unless set. A gzipped file or Excel workbook that unpacks past it is refused.
timeout_s no A positive finite number of seconds for one source's download, retries and waits included. 300 unless set.
format no "file" copies bytes unchanged. Table formats are "csv", "json" and "xlsx"; see the details below.
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 "".
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.
archive no true to ask the Internet Archive's Save Page Now 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. record asks for no snapshot. It keeps the one logged for the same bytes, and otherwise leaves archive_url empty.
reason no A note for people, such as why a source is unimplemented. sourceledger doesn't read it.

Without format, the URL extension selects JSON (.json) or Excel (.xlsx); other extensions select CSV. CSV and JSON can be gzipped; decompression stays within max_bytes. CSV and JSON input must be UTF-8, with or without a byte-order mark. build refuses any other encoding, names the source and the first bad byte, and says to re-save the file as UTF-8. JSON input must be an array of objects. Numbers keep their spelling: 1e5 stays 1e5, and 1.10 stays 1.10. format = "file" keeps archives, rasters and other files unchanged, without unpacking or parsing them.

validate reports a missing terms, terms_url, license or redistribute. The other keys are checked when the manifest loads. Keys not listed here are kept for your own reader.

For checks in an editor with a TOML language server (Tombi, Taplo), put this line at the top of sources.toml. init writes it with the version you have installed in place of the one shown:

#:schema https://raw.githubusercontent.com/simonvanlierde/sourceledger/v0.7.0/src/sourceledger/sources.schema.json

The schema accepts exactly what sourceledger accepts. A test keeps the two in step.

Other commands

  • init writes a starter sources.toml in the current directory, or at --manifest PATH: the schema line and one example source, commented out. It won't overwrite an existing one.

  • record ID PATH takes in a file that another tool, such as pooch, DVC or your own script, downloaded for source ID. It copies the file into data/raw/, checks the sha256 pin, and writes the same log line and record as fetch, with recorded_at set to now. The file must be a regular file within the source's max_bytes. The library function is record().

  • - as PATH reads stdin and stores the bytes under the name fetch gives the source. Use ./- for a file named -. The read finishes before SourceLedger takes the lock, so a slow pipe leaves fetch free to run. SourceLedger rejects empty input. Set the manifest's sha256 to the expected hash to catch incomplete input or an HTTP error body. A terminal or closed stdin gives a usage error. --dry-run still reads stdin to report the hash and size.
  • --retrieved-at TIME is when the file was downloaded, in ISO 8601 with a time zone (2026-11-05T09:30:00Z). A value that is not ISO 8601 is a usage error. Without it, the record and the rows' retrieved_at stay empty rather than claim a download time.
  • --url URL names where the file came from, if that is not the source's url. Its query and fragment are dropped, since a signed download URL keeps its secret there.
  • --etag and --last-modified keep the server's validators for a later conditional fetch, but only when the URL is the source's own.
  • --parameter NAME=VALUE, repeatable, keeps request metadata such as a query's country code. It is published with the dataset, as text, so a name such as token, x-api-key or sig is refused (safe use lists the rule).
  • --dry-run makes every check and hashes the file, then prints what it would record and writes nothing.

The report and datapackage.json show the output as recorded, not fetched. status shows the record time when there is no download time. A later fetch of the same bytes logs a fetch over the record and prints relogged with a reminder to run build, since the outputs still name the record.

  • revisions OLD_LOG lists the sources whose bytes changed since an earlier copy of the log. Copy the log before you fetch (cp data/fetches.jsonl before.jsonl), then run sourceledger revisions before.jsonl. It prints no revisions when no source changed. A weekly CI run can use it to report a publisher's revision.

  • status prints one line per source: its id, status and vintage, when its last logged version was fetched (or never), the start of its SHA-256, its licence, and whether the raw file may be republished. It reads the manifest and the log, never the network.

  • attribution prints a Markdown table of the implemented sources, in manifest order: name, terms in the publisher's words, licence, terms URL, and whether the raw file may be republished. Paste it into a dataset's README or release notes.

  • report writes a standalone HTML provenance report to stdout. Save it with sourceledger report > provenance.html. It works offline and returns 0 when it produces a report, including one that lists integrity problems.

  • verify DIR is for someone who downloaded a published dataset. It reads DIR/datapackage.json and checks that each file it lists exists, with the size and SHA-256 it gives. It prints one line per problem and exits 1 if there are any. It needs no sources.toml and no network.

Options, output and exit codes

sourceledger STAGE --help lists the options of one stage. Options go after the stage name. Write each option in full: a prefix such as --j is refused.

Option Stages Effect
--manifest PATH all but revisions and verify Read this manifest instead of ./sources.toml. The data folder stays data/ in the current directory.
--only ID fetch, build, validate Work on just this source; repeat it for more. build --only keeps the other sources' entries in datapackage.json as the last build wrote them, and validate --only skips the checks that cover the whole output.
--dry-run fetch, record, build, release Say what would happen and write nothing: no download, no log line, no output. build --dry-run still checks each raw file against its fetch record, record --dry-run still checks and hashes the file, and release --dry-run still runs validate.
--json fetch, record, build, validate, status, revisions, verify, release Print one JSON object on stdout instead of text; see JSON reports.

In text mode, stdout lists fetches, written files, and the problems validate and verify find, followed by their count. Text errors and warnings go to stderr. With --json, errors appear in the report on stdout. A text error is one line in the form error: <what went wrong>, followed by help: <what to do> when there is a known next step:

error: sources.toml is missing
help: run `sourceledger init` to write one, or pass --manifest PATH

When stderr is a terminal and --json is off, fetch also prints fetching ID (n of N) there before each source. The output has no colour. It is UTF-8 with LF line ends on every system, also when redirected to a file on Windows.

Exit code Meaning
0 Done, with nothing to report. revisions exits 0 when sources changed: your downstream checks decide what a revision breaks. report exits 0 when it writes a report, even one that lists problems.
1 Problems found: validate or verify found at least one, or release refused its input or found a problem in the folder.
2 Usage error: an unknown stage or option, a missing argument, or an --only or record id that is not in sources.toml, a --retrieved-at that is not an ISO 8601 time, or record ID - with no input piped to stdin. Nothing is written.
3 Could not run: a missing or invalid file, a failed download, another fetch holding the lock, a validator release needs that is not installed or that stopped without a result, or an unexpected error such as a project's parser failing, printed as one error: line with its type. When some sources fail to fetch, the others are still written and logged.
130 Interrupted with Ctrl-C. The help message explains how to retry. For record ID -, check the recorded file and fetch log, then pipe in the input again if needed. With --json the report still prints, and fetch lists the sources fetched before. The command ends by SIGINT, so a shell loop around it stops too. On Windows it exits 130. main() returns 130, so a project's own command calls sourceledger.entry() to end by SIGINT (custom readers).

JSON reports

Use --json when a script needs to read a report:

sourceledger status --json
sourceledger validate --json --only co2
sourceledger revisions before.jsonl --json
sourceledger fetch --json
sourceledger build --json

These commands print one JSON object on stdout. They do not print the usual text report. Every object has schema_version (now 1; it goes up when a field changes meaning or goes away), stage (the command name) and errors. Each error is an object with message and help, the same two lines the text output prints; help is null when there is no known next step. A successful run has an empty errors list. Warnings can still appear on stderr. init, attribution and report do not accept --json: they write a starter file, Markdown or HTML. report.schema.json is the JSON Schema of every report, failures included. Use the schema for the version you run. A later version may add fields.

Command Result field Meaning
fetch records One fetch record per source fetched, with the fields of a line in data/fetches.jsonl and new: true when its bytes differ from the last ones logged, and relogged: true when the same bytes were logged again because they came in another way (fetched after a record or under a new url or vintage, or recorded with other details), so the outputs need a build. A missing raw file restored from bytes already logged, which the text output marks fetched, has both false, as an unchanged one does. A run where some sources failed lists the ones that worked.
record records The one record, as for fetch.
status sources One object per source, in manifest order.
build outputs, package One {path, rows} object per file written, with rows null for a file copied unchanged, and the path of datapackage.json.
validate problems The same list of problem messages the Python function returns.
verify problems The same list of problem messages the Python function returns.
revisions revisions One object per changed source, in current-log order. New sources are excluded, as in text output.
release files, excluded, formats, validators The paths in the folder, the ids left out, "written" or "skipped" for each optional format, and the file, name and version of each check that ran. A refused release has problems and validators instead.
release --check problems, validators The problems found, and each check that ran.

With --dry-run, the object also has "dry_run": true. fetch --dry-run lists would_fetch, one {"source_id", "url"} object per source, in place of records, and build --dry-run lists would_write, the paths, in place of outputs and package. record --dry-run gives the record it would write.

Source status

Each sources object has source_id, status, vintage, retrieved_at, recorded_at, sha256, license and redistribute. Hashes have all 64 characters. Missing fetch information is null; an absent licence or unknown redistribution flag is also null. recorded_at is null for a fetched file and the record time for a file record took in; its retrieved_at is then "" when the other tool reported no download time. redistribute is otherwise a JSON boolean. The status field is text, or null when absent. The command reads no raw files and makes no network requests.

Revisions

Each revision has source_id, before_sha256 and after. before_sha256 is the earlier full hash. after is the complete latest fetch record, with the same fields as a line in data/fetches.jsonl. The two logs must exist. An empty revisions list means no existing source changed bytes.

Problems, failures and exit codes

A validation run with no problems prints:

{"schema_version": 1, "stage": "validate", "problems": [], "errors": []}

Validation problems go in problems and cause exit code 1. Runtime failures, such as a missing manifest or log, go in errors and cause exit code 3. A failed run omits its result field, except fetch, which lists the sources that worked. For example:

{"schema_version": 1, "stage": "status", "errors": [{"message": "sources.toml is missing", "help": "run `sourceledger init` to write one, or pass --manifest PATH"}]}

An --only id that is not in sources.toml is also reported in errors, with exit code 2. Other usage errors, such as a missing revisions path or a --parameter that is not NAME=VALUE, are found before the stage runs. With --json they print the same failure object on stdout and nothing on stderr; without it they print the usage and the text error on stderr. Either way the exit code is 2. A usage error before the stage is known, such as an unknown stage, is always text. The exit code table holds the rest.

These JSON structures are part of the CLI contract. Read fields by name; JSON object key order and whitespace are not significant. The stability policy applies.

Release a dataset

release OUT_DIR writes the folder you publish, from a build that validate passes:

sourceledger release release-v1
sourceledger release --check release-v1

It runs validate first and stops with exit code 1 if it finds a problem. OUT_DIR must be new or empty. The folder holds:

  • data/: the output of each implemented source whose redistribute is true. The list comes from sources.toml, not from the files in data/processed/, so a source with redistribute = false is left out, whether it is a copied file or a table, and listed as excluded.
  • datapackage.json: the one build wrote, with shipped resources under data/. When the Python API supplies excluded cache files, excluded_inputs lists their source IDs, byte counts and SHA-256 checksums. verify checks the folder against the descriptor.
  • ro-crate-metadata.json (RO-Crate 1.3) and croissant.json (Croissant 1.1), only when release_formats asks for them; otherwise each is reported as skipped. The RO-Crate lists each shipped file with its SHA-256, and every source with its URL, licence, terms and download time, an excluded one marked as such. The Croissant lists each file with the same SHA-256, and the columns of each table.
  • SHA256SUMS: every other file, written last, in the format of sha256sum -b, so sha256sum -c SHA256SUMS checks the folder without sourceledger.

The dataset's name, description, authors, contributors, publisher, keywords, licence, version, identifier, datePublished and url come from codemeta.json in the current directory, the project's CodeMeta file, or from the file --codemeta PATH names (codemeta= in the library). release --check takes no --codemeta: it reads only the folder. Its license becomes the dataset's licence. A publisher given as text, or as an object without @type, is written as an Organization, as both formats require. A contributor without an @id gets #contributor-<n>; in the RO-Crate, a person listed twice, or as author and contributor, is one entity. When the data has another licence than the code, as when the code is MIT and the data CC-BY-4.0, keep a CodeMeta file for the dataset and pass it with --codemeta. release does not write it, and reads it only when release_formats asks for a format. If the file is missing then, release exits 1 and names it. citesync 0.5.0 or later keeps it in step with CITATION.cff, and its check also compares the ro-crate-metadata.json and croissant.json of a release folder you list under manifests, so a release made from a stale CodeMeta file fails it. Both CodeMeta 2 and 3 files work: CodeMeta 3's id and type are written as @id and @type, so an author's ORCID stays its @id.

RO-Crate needs name, description, license and datePublished. Croissant needs name, description, license and url. A missing one stops release with exit code 1, naming it.

After writing, release hashes every file in the folder. It refuses with exit code 1 when one has the bytes of a restricted source's raw file or output, whatever its name. Then it runs the same checks as release --check DIR, which checks a folder that exists:

File Check
SHA256SUMS Every listed file is there with its SHA-256, and no file is unlisted. Built in.
ro-crate-metadata.json rocrate-validator validate, profile ro-crate-1.3. It downloads the context that the crate names, so it needs the network, and on a folder you received it makes the requests that crate asks for.
croissant.json mlcroissant validate --jsonld.

Each validator runs in its own process, and every finding is a problem with exit code 1. A validator that stops without findings, such as roc-validator offline, or that runs past 10 minutes, exits 3: the folder was not checked. The report names each check that ran, with its version.

The two validators come with the release extra: uv tool install 'sourceledger[release]', or uv add 'sourceledger[release]' in a project. When a metadata file is there but its validator is not, release exits 3 with both install lines. It reads codemeta.json first, so a missing field shows before that.

The folder is written beside OUT_DIR and moved into place only once every check passes, so a refused release leaves nothing at OUT_DIR. A killed release leaves .OUT_DIR.part beside it, and the next run refuses until you delete that folder. An OUT_DIR that already exists and is empty, such as a mounted volume, is kept and the files are moved into it.

Above 100 files, release warns: Zenodo takes at most 100 files a record, so zip the folder yourself. release does not upload, and it writes no .zenodo.json, DataCite fields, dataset card or licence files.

In Python, release() returns the fields of the --json report. It raises ReleaseError, a ValueError, for refused input and findings: RestrictedSourceError when a restricted file reached the folder, and ValidatorFailed when a validator reported findings. ValidatorMissing and ValidatorCouldNotRun are OSErrors. check_release(DIR) is release --check DIR: it returns the problems and the checks that ran.

Release outputs from excluded cache files

The Python API can record a file in an existing cache. Mark its source as implemented with format = "file" and redistribute = false. Set max_bytes in the manifest if the file is larger than the default limit. Record the exact input used to produce the outputs and keep the cache stable until the release finishes. Record the other inputs as usual before building.

from pathlib import Path

import sourceledger

sources = sourceledger.load_manifest()
by_id = {source["id"]: source for source in sources}
cache_files = {"bulk": Path("cache/bulk.bin")}
for source_id, path in cache_files.items():
    sourceledger.record(by_id[source_id], path, copy=False)

processed = Path("data/release-build")
built_ids = [s["id"] for s in sources if s["status"] == "implemented" and s["id"] not in cache_files]
name = sourceledger.load_package_name()
output_format = sourceledger.load_output_format()
sourceledger.build(sources, only=built_ids, processed=processed, name=name, output_format=output_format)
release_dir = Path("release-v1")
sourceledger.release(
    sources, release_dir, processed=processed, name=name, output_format=output_format, external_inputs=cache_files
)
problems = sourceledger.verify(release_dir, external_inputs=cache_files)
if problems:
    raise ValueError("\n".join(problems))

record(copy=False) writes the log and a checksum sidecar. The file stays in the cache. From then on build, validate and a release without external_inputs refuse the source, also on the command line, which cannot record in this mode: run sourceledger build --only and sourceledger validate --only with the other sources, and release from Python. Recording or fetching a copy again ends this mode. Use a fresh processed folder when switching an existing project to this mode. A partial build in a reused folder can keep old outputs and descriptor entries. The release checks the cache files against their records before publishing and refuses a shipped file that matches any recorded revision of those restricted sources. Keep the fetch log. If you set a custom log in record, pass it to release as well. The package's fingerprints contain no cache paths.

verify checks only the shipped files by default, so a reader without the cache can use sourceledger verify DIR offline. Supply external_inputs to the library to also verify the cache files. Include a path for every listed ID. Paths come from the caller rather than the downloaded descriptor.

HTML provenance report

After building a dataset, create a standalone HTML report for someone who receives it:

sourceledger report > provenance.html

Keep the report outside data/processed/: validation expects that folder to hold only outputs described by the data package. Open provenance.html in a browser. It uses no scripts, remote styles, fonts or network requests. See an example report, made from the test suite's sample sources.

The command reads sources.toml, data/fetches.jsonl and the built package in data/processed/. It checks that the listed outputs match the implemented manifest sources and that their files match the package. It also flags a build that predates the last logged revision. Each output links to its source details: URL, vintage, fetch timestamp, raw and output hashes, licence and reuse terms. For a file that record took in from another tool, the report gives the download time that tool reported, or "not stated", and the time it was recorded, instead of a fetch time.

Source details come from the current manifest; the fetch stamps describe the last build. If a file or its provenance is stale, the report lists the problem. The command returns 0 when it produces a report, including one with integrity problems. A fatal input error exits 3 and writes no HTML. A missing fetch log produces a provenance problem in the report. Run validate to gate a pipeline on those problems.

The report includes no raw values or header names and values. Displayed HTTP URLs omit user information, query parameters and fragments. URLs that are not HTTP or HTTPS are omitted. Review free-text names and reuse terms before sharing: sourceledger cannot recognize secrets someone wrote into those fields or into a URL path. Displayed metadata is escaped so it cannot become executable HTML.

Passing integrity checks does not authenticate the package, establish scientific correctness or grant publication permission. Recipients must obtain the package and report from a source they trust, and review the source terms.

In Python, sourceledger.report(sources, processed=folder, log=fetch_log) returns the HTML as a string. It reads the same files and does not write the report itself.