Skip to content

Package

Here is a list of available actions for Data Package

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

Reference

dplib.actions.package.check.check_package(package)

Check the validity of a Data Package 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
package Union[str, IDict, Package]

The Data Package descriptor

required

Returns:

Type Description
List[MetadataError]

A list of errors

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

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

    Parameters:
        package: The Data Package descriptor

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

    # Validate (including nested descriptors)
    errors = check_metadata(package, type="package")
    resources = package.get("resources", [])
    if isinstance(resources, list):
        for resource in resources:  # type: ignore
            for type in ["dialect", "schema"]:
                value = resource.get(type)  # type: ignore
                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.package.convert.convert_package(path, *, format=None, source=None, target=None)

Convert a Data Package 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

Package model

Source code in dplib/actions/package/convert.py
def convert_package(
    path: str,
    *,
    format: Optional[str] = None,
    source: Optional[INotation] = None,
    target: Optional[INotation] = None,
) -> Model:
    """Convert a Data Package 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:
        Package model
    """
    return convert_metadata(
        path, type="package", format=format, source=source, target=target
    )