Software
Fairspec Extension provides SDKs for Python and TypeScript/JavaScript to make it easy to publish and consume Extension datasets.
Python
Section titled “Python”Installation
Section titled “Installation”pip install fairspec fairspec-extensionPublication
Section titled “Publication”from fairspec_extension import Dataset, Table1, Table2from fairspec import saveDatasetDescriptor
# Create Table1 recordsrecord1 = Table1( id="t1-001", name="First Entity", status="active", value=100.5, itemCount=5, isVerified=True, createdDate="2024-01-15", description="This is the first example entity",)
# Create Table2 recordsrecord2 = Table2( id="t2-001", table1Id="t1-001", title="Related Item", amount=99.99, priority="high", percentage=75.5, notes="This item is related to the first entity", isActive=True,)
dataset = Dataset( { "$schema": "https://datisthq.github.io/fairspec-extension/profiles/v0.1.5/dataset.json", "resources": [ { "name": "table1", "data": [record1], "tableSchema": "https://datisthq.github.io/fairspec-extension/schemas/v0.1.5/table1.json", }, { "name": "table2", "data": [record2], "tableSchema": "https://datisthq.github.io/fairspec-extension/schemas/v0.1.5/table2.json", }, ], })
saveDatasetDescriptor(dataset, path="dataset.json")Validation
Section titled “Validation”from fairspec import validateDataset
report = validateDataset("dataset.json")print(report)Consumption
Section titled “Consumption”from fairspec import loadDatasetDescriptor
dataset = loadDatasetDescriptor("dataset.json")print(dataset)TypeScript
Section titled “TypeScript”Installation
Section titled “Installation”npm install fairspec fairspec-extensionPublication
Section titled “Publication”import type { Table1, Table2, Dataset } from "fairspec-extension";import { savePackageDescriptor } from "fairspec";
const record1: Table1 = { id: "t1-001", name: "First Entity", status: "active", value: 100.5, itemCount: 5, isVerified: true, createdDate: "2024-01-15", description: "This is the first example entity",};
const record2: Table2 = { id: "t2-001", table1Id: "t1-001", title: "Related Item", amount: 99.99, priority: "high", percentage: 75.5, notes: "This item is related to the first entity", isActive: true,};
const dataset: Dataset = { $schema: "https://fairspec.github.io/fairspec-extension/profiles/v0.1.5/datast.json", resources: [ { name: "table1", data: [record1], tableSchema: "https://fairspec.github.io/fairspec-extension/schemas/v0.1.5/table1.json", }, { name: "table2", data: [record2], tableSchema: "https://fairspec.github.io/fairspec-extension/schemas/v0.1.5/table2.json", }, ],};
await saveDatasetDescriptor(dataset, { path: "dataset.json", overwrite: true,});Validation
Section titled “Validation”import { validateDataset } from "fairspec";
const { valid, errors } = await validateDataset("dataset.json");console.log(valid, errors);Consumption
Section titled “Consumption”import { loadDatasetDescriptor } from "fairspec";
const dataset = await loadDatasetDescriptor("dataset.json");console.log(dataset);