Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,21 @@ print(dataset)
# }
```

Validating an in-memory dataset descriptor:
Validating an in-memory dataset model:

```python
from fairspec import validate_dataset
from fairspec import Dataset, validate_dataset

report = validate_dataset({"resources": "bad"})
dataset = Dataset(resources=[])
report = validate_dataset(dataset)

print(report.valid)
# False
# True
print(report.errors)
# [
# {
# "type": "metadata",
# "message": "must have type array",
# "jsonPointer": "/resources",
# }
# ]
# []
```

Loading a dataset from a remote descriptor and saving it locally as a zip archive, and then using it as a local dataset:
Loading a dataset from Zenodo and saving it locally as a zip archive, and then using it as a local dataset:

```python
from fairspec import (
Expand All @@ -75,9 +70,7 @@ from fairspec import (
)

archive_path = get_temp_file_path()
source_dataset = load_dataset(
"https://raw.githubusercontent.com/roll/currency-codes/refs/heads/master/datapackage.json",
)
source_dataset = load_dataset("https://zenodo.org/records/10053903")

save_dataset_to_zip(source_dataset, archive_path=archive_path)
target_dataset = load_dataset_from_zip(archive_path)
Expand Down
8 changes: 5 additions & 3 deletions docs/python/dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ dataset = Dataset(

## Loading a Dataset

Load a dataset descriptor from a local path or remote URL:
Load a dataset descriptor from a local path or a source supported by one of the dataset plugins:

```python
from fairspec import load_dataset

# Load from local file
descriptor = load_dataset("dataset.json")

# Load from a remote URL
descriptor = load_dataset("https://example.com/dataset.json")
# Load from a supported remote source, such as Zenodo
descriptor = load_dataset("https://zenodo.org/records/10053903")
```

`load_dataset` dispatches to the appropriate plugin based on the source (folder, zip, GitHub, Zenodo, CKAN, …) and returns a `Descriptor` (a dict-like JSON object) or `None` if no plugin recognises the source.

To load an arbitrary local or remote Fairspec descriptor file directly, use `load_dataset_descriptor`.

To get a typed `Dataset` model, validate the descriptor:

```python
Expand Down