Skip to content

Resource

Here is a list of available actions for Data Resource

  • check_package -- check the descriptor against JSON Schema(s)
  • convert_package -- convert the descriptor from one notation to another

Reference

dplib.actions.resource.check.check_resource(resource)

Check the validity of a Data Resource descriptor

This validates the descriptor against the JSON Schema profiles to ensure conformity with Data Package standard and Data Package extensions.

Parameters:

Name Type Description Default
resource Union[str, IDict, Resource]

The Data Resource descriptor

required

Returns:

Type Description
List[MetadataError]

A list of errors

Source code in dplib/actions/resource/check.py
def check_resource(resource: Union[str, types.IDict, Resource]) -> List[MetadataError]:
    """Check the validity of a Data Resource descriptor

    This validates the descriptor against the JSON Schema profiles to ensure
    conformity with Data Package standard and Data Package extensions.

    Parameters:
        resource: The Data Resource descriptor

    Returns:
        A list of errors
    """
    basepath = None
    if isinstance(resource, str):
        basepath = infer_basepath(resource)
        resource = read_dict(resource)
    if isinstance(resource, Resource):
        basepath = resource.basepath
        resource = resource.to_dict()

    # Validate (including nested descriptors)
    errors = check_metadata(resource, type="resource")
    for type in ["dialect", "schema"]:
        value = resource.get(type)
        if isinstance(value, str):
            assert_safe_path(value, basepath=basepath)
            metadata = read_dict(value, basepath=basepath)
            errors.extend(check_metadata(metadata, type=type))  # type: ignore

    return errors

dplib.actions.resource.convert.convert_resource(path, *, format=None, source=None, target=None)

Convert a Data Resource descriptor from one notation to another

Parameters:

Name Type Description Default
path str

Path to the descriptor

required
format Optional[str]

Format of the descriptor

None
source Optional[INotation]

Source notation e.g. ckan (default dp)

None
target Optional[INotation]

Target notation e.g. dcat (default dp)

None

Returns:

Type Description
Model

Resource model

Source code in dplib/actions/resource/convert.py
def convert_resource(
    path: str,
    *,
    format: Optional[str] = None,
    source: Optional[INotation] = None,
    target: Optional[INotation] = None,
) -> Model:
    """Convert a Data Resource descriptor from one notation to another

    Parameters:
        path: Path to the descriptor
        format: Format of the descriptor
        source: Source notation e.g. ckan (default dp)
        target: Target notation e.g. dcat (default dp)

    Returns:
        Resource model
    """
    return convert_metadata(
        path, type="resource", format=format, source=source, target=target
    )