Resource
Data Resource commands help you work with individual data resources - the building blocks of Data Packages. These commands allow you to infer metadata from data files, validate resource structure, and explore resource properties.
Available Commands
Section titled “Available Commands”dpkit resource infer
Section titled “dpkit resource infer”Infer a data resource from a table by analyzing its structure and generating metadata including schema information.
dpkit resource infer <table-path>Options:
-p, --from-package: Path to package containing the resource-r, --from-resource: Name of resource within package-j, --json: Output as JSON-d, --debug: Enable debug mode
Table Dialect Options:
--delimiter: Field delimiter character--header: Whether files have headers--header-rows: Number of header rows--header-join: Join character for multi-row headers--comment-rows: Number of comment rows to skip--comment-char: Comment character--quote-char: Quote character for fields--double-quote: Whether quotes are doubled for escaping--escape-char: Escape character--null-sequence: Sequence representing null values--skip-initial-space: Skip initial whitespace--property: JSON property path for nested data--item-type: Type of items in arrays--item-keys: Keys for object items--sheet-number: Excel sheet number--sheet-name: Excel sheet name--table: Database table name--sample-bytes: Bytes to sample for inference
Table Schema Options:
--field-names: Override field names--field-types: Override field types--missing-values: Values to treat as missing--string-format: String format specification--decimal-char: Decimal separator character--group-char: Thousands separator character--bare-number: Allow bare numbers--true-values: Values to treat as true--false-values: Values to treat as false--datetime-format: DateTime format string--date-format: Date format string--time-format: Time format string--array-type: Type of array elements--list-delimiter: List item delimiter--list-item-type: Type of list items--geopoint-format: Geopoint format specification--geojson-format: GeoJSON format specification--sample-rows: Rows to sample for inference--confidence: Confidence threshold for type inference--comma-decimal: Use comma as decimal separator--month-first: Parse dates with month first--keep-strings: Keep string types when possible
Examples:
# Infer resource from CSV filedpkit resource infer data.csv
# Infer with custom delimiterdpkit resource infer data.csv --delimiter ";"
# Infer from remote filedpkit resource infer https://example.com/data.csv
# Infer from resource in packagedpkit resource infer --from-package datapackage.json --from-resource "users"
# Export as JSONdpkit resource infer data.csv --jsondpkit resource explore
Section titled “dpkit resource explore”Explore a data resource from a local or remote path to view its structure and metadata in an interactive format.
dpkit resource explore <descriptor-path>Options:
-p, --from-package: Path to package containing the resource-r, --from-resource: Name of resource within package-j, --json: Output as JSON-d, --debug: Enable debug mode
Examples:
# Explore resource descriptordpkit resource explore resource.json
# Explore remote resourcedpkit resource explore https://example.com/resource.json
# Explore resource from packagedpkit resource explore --from-package datapackage.json --from-resource "users"
# Export structure as JSONdpkit resource explore resource.json --jsondpkit resource validate
Section titled “dpkit resource validate”Validate a data resource from a local or remote path against the Data Resource specification.
dpkit resource validate [descriptor-path]Options:
--from-package: Path to package containing the resource--from-resource: Name of resource within package--json: Output validation results as JSON--debug: Enable debug mode-q, --quit: Exit immediately after validation (don’t prompt for error filtering)-a, --all: Skip selection prompts when all can be selected
Examples:
# Validate resource descriptordpkit resource validate resource.json
# Validate remote resourcedpkit resource validate https://example.com/resource.json
# Validate resource from packagedpkit resource validate --from-package datapackage.json --from-resource "users"
# Get validation results as JSONdpkit resource validate resource.json --json
# Interactive selection when no path provideddpkit resource validate --from-package datapackage.jsondpkit resource script
Section titled “dpkit resource script”Open an interactive scripting session with a loaded data resource. This provides a REPL environment where you can programmatically interact with the resource metadata.
dpkit resource script <descriptor-path>Options:
-p, --from-package: Path to package containing the resource-r, --from-resource: Name of resource within package-j, --json: Output as JSON-d, --debug: Enable debug mode
Available Variables:
dpkit: The dpkit library objectresource: The loaded resource object
Examples:
# Start scripting session with resourcedpkit resource script resource.json
# Script resource from packagedpkit resource script --from-package datapackage.json --from-resource "users"
# In the REPL session:dpkit> resource.schema.fields.lengthdpkit> resource.schema.fields[0].typedpkit> resource.pathCommon Workflows
Section titled “Common Workflows”Creating Resource Metadata
Section titled “Creating Resource Metadata”-
Infer from data file:
Terminal window dpkit resource infer data.csv --json > resource.json -
Validate the generated resource:
Terminal window dpkit resource validate resource.json -
Explore the resource structure:
Terminal window dpkit resource explore resource.json
Working with Package Resources
Section titled “Working with Package Resources”# Explore all resources in a package interactivelydpkit resource validate --from-package datapackage.json
# Infer metadata for specific resourcedpkit resource infer --from-package datapackage.json --from-resource "users"
# Script specific resource from packagedpkit resource script --from-package datapackage.json --from-resource "transactions"Resource Analysis Workflow
Section titled “Resource Analysis Workflow”# Infer resource with custom optionsdpkit resource infer data.csv \ --delimiter ";" \ --header-rows 2 \ --sample-rows 1000
# Validate the inferred resourcedpkit resource validate resource.json
# Explore interactively to verify structuredpkit resource explore resource.jsonRemote Resource Handling
Section titled “Remote Resource Handling”# Work with remote resourcesdpkit resource explore https://example.com/resource.jsondpkit resource validate https://example.com/resource.jsondpkit resource infer https://example.com/data.csvResource Selection
Section titled “Resource Selection”When working with resources from packages, you can either:
-
Specify explicitly:
Terminal window dpkit resource explore --from-package datapackage.json --from-resource "users" -
Interactive selection:
Terminal window dpkit resource validate --from-package datapackage.json# Will prompt to select from available resources
Output Formats
Section titled “Output Formats”All resource commands support multiple output formats:
- Interactive Display: Default rich terminal interface showing resource structure
- JSON: Use
--jsonflag for machine-readable output - Debug Mode: Use
--debugfor detailed operation logs
Integration with Package Commands
Section titled “Integration with Package Commands”Resource commands work seamlessly with package commands:
# Create package, then work with individual resourcesdpkit package infer *.csv --json > datapackage.jsondpkit resource validate --from-package datapackage.json --from-resource "data"dpkit resource explore --from-package datapackage.json --from-resource "users"