Edit page in Livemark
(2024-11-07 15:17)

Resource Steps

The Resource steps are only available for a package transformation (except for steps.resource_update available for standalone resources). This includes some basic resource management operations like adding or removing resources along with the hierarchical transform_resource step.

Add Resource

This step add a new resource to a data package.

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Package(resources=[Resource(name='main', path="transform.csv")])
target = transform(
    source,
    steps=[
        steps.resource_add(name='extra', descriptor={'path': 'transform.csv'}),
    ],
)
print(target.resource_names)
print(target.get_resource('extra').schema)
print(target.get_resource('extra').to_view())
['main', 'extra']
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+-----------+------------+
| id | name      | population |
+====+===========+============+
|  1 | 'germany' |         83 |
+----+-----------+------------+
|  2 | 'france'  |         66 |
+----+-----------+------------+
|  3 | 'spain'   |         47 |
+----+-----------+------------+

Reference

steps.resource_add (class)

steps.resource_add (class)

Add resource. This step can be added using the `steps` parameter for the `transform` function.

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, name: str, descriptor: Dict[str, Any]) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • name (str)
  • descriptor (Dict[str, Any])

steps.resource_add.name (property)

Name of the resource to add.

Signature

str

steps.resource_add.descriptor (property)

A descriptor for the resource.

Signature

Dict[str, Any]

Remove Resource

This step remove an existent resource from a data package.

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Package(resources=[Resource(name='main', path="transform.csv")])
target = transform(
    source,
    steps=[
        steps.resource_remove(name='main'),
    ],
)
print(target)
{'resources': []}

Reference

steps.resource_remove (class)

steps.resource_remove (class)

Remove resource. This step can be added using the `steps` parameter for the `transform` function.

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, name: str) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • name (str)

steps.resource_remove.name (property)

Name of the resource to remove.

Signature

str

Transform Resource

It's a hierarchical step allowing to transform a data package's resource. It's possible to use any resource steps as a part of this package step.

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Package(resources=[Resource(name='main', path="transform.csv")])
target = transform(
    source,
    steps=[
        steps.resource_transform(name='main', steps=[
            steps.row_sort(field_names=['name'])
        ]),
    ],
)
print(target.resource_names)
print(target.get_resource('main').schema)
print(target.get_resource('main').to_view())
['main']
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+-----------+------------+
| id | name      | population |
+====+===========+============+
|  2 | 'france'  |         66 |
+----+-----------+------------+
|  1 | 'germany' |         83 |
+----+-----------+------------+
|  3 | 'spain'   |         47 |
+----+-----------+------------+

Reference

steps.resource_transform (class)

steps.resource_transform (class)

Transform resource. This step can be added using the `steps` parameter for the `transform` function.

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, name: str, steps: List[Step]) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • name (str)
  • steps (List[Step])

steps.resource_transform.name (property)

Name of the resource to transform.

Signature

str

steps.resource_transform.steps (property)

List of transformation steps to apply to the given resource.

Signature

List[Step]

Update Resource

This step update a resource's metadata. It can be used for both resource and package transformations.

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Package(resources=[Resource(name='main', path="transform.csv")])
target = transform(
    source,
    steps=[
        steps.resource_update(
          name='main',
          descriptor={'title': 'Main Resource', 'description': 'For the docs'}
        ),
    ],
)
print(target.get_resource('main'))
{'name': 'main',
 'type': 'table',
 'title': 'Main Resource',
 'description': 'For the docs',
 'path': 'transform.csv',
 'scheme': 'file',
 'format': 'csv',
 'mediatype': 'text/csv'}

Reference

steps.resource_update (class)

steps.resource_update (class)

Update resource. This step can be added using the `steps` parameter for the `transform` function.

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, name: Optional[str] = None, descriptor: types.IDescriptor) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • name (Optional[str])
  • descriptor (types.IDescriptor)

steps.resource_update.name (property)

Name of the resource to update.

Signature

Optional[str]

steps.resource_update.descriptor (property)

New descriptor for the resource to update metadata.

Signature

types.IDescriptor