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”dp resource infer
Section titled “dp resource infer”Infer a data resource from a table by analyzing its structure and generating metadata including schema information.
dp 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 filedp resource infer data.csv
# Infer with custom delimiterdp resource infer data.csv --delimiter ";"
# Infer from remote filedp resource infer https://example.com/data.csv
# Infer from resource in packagedp resource infer --from-package datapackage.json --from-resource "users"
# Export as JSONdp resource infer data.csv --jsondp resource explore
Section titled “dp resource explore”Explore a data resource from a local or remote path to view its structure and metadata in an interactive format.
dp 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 descriptordp resource explore resource.json
# Explore remote resourcedp resource explore https://example.com/resource.json
# Explore resource from packagedp resource explore --from-package datapackage.json --from-resource "users"
# Export structure as JSONdp resource explore resource.json --jsondp resource validate
Section titled “dp resource validate”Validate a data resource from a local or remote path against the Data Resource specification.
dp 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 descriptordp resource validate resource.json
# Validate remote resourcedp resource validate https://example.com/resource.json
# Validate resource from packagedp resource validate --from-package datapackage.json --from-resource "users"
# Get validation results as JSONdp resource validate resource.json --json
# Interactive selection when no path provideddp resource validate --from-package datapackage.jsondp resource script
Section titled “dp 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.
dp 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 resourcedp resource script resource.json
# Script resource from packagedp resource script --from-package datapackage.json --from-resource "users"
# In the REPL session:dp> resource.schema.fields.lengthdp> resource.schema.fields[0].typedp> resource.pathCommon Workflows
Section titled “Common Workflows”Creating Resource Metadata
Section titled “Creating Resource Metadata”-
Infer from data file:
Terminal window dp resource infer data.csv --json > resource.json -
Validate the generated resource:
Terminal window dp resource validate resource.json -
Explore the resource structure:
Terminal window dp resource explore resource.json
Working with Package Resources
Section titled “Working with Package Resources”# Explore all resources in a package interactivelydp resource validate --from-package datapackage.json
# Infer metadata for specific resourcedp resource infer --from-package datapackage.json --from-resource "users"
# Script specific resource from packagedp resource script --from-package datapackage.json --from-resource "transactions"Resource Analysis Workflow
Section titled “Resource Analysis Workflow”# Infer resource with custom optionsdp resource infer data.csv \ --delimiter ";" \ --header-rows 2 \ --sample-rows 1000
# Validate the inferred resourcedp resource validate resource.json
# Explore interactively to verify structuredp resource explore resource.jsonRemote Resource Handling
Section titled “Remote Resource Handling”# Work with remote resourcesdp resource explore https://example.com/resource.jsondp resource validate https://example.com/resource.jsondp 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 dp resource explore --from-package datapackage.json --from-resource "users" -
Interactive selection:
Terminal window dp 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 resourcesdp package infer *.csv --json > datapackage.jsondp resource validate --from-package datapackage.json --from-resource "data"dp resource explore --from-package datapackage.json --from-resource "users"