Edit page in Livemark
(2022-09-19 18:33)

Resource Steps

The Resource steps are only available for a package transformation. 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

Signature

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

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

steps.resource_add.name (property)

NOTE: add docs

Signature

str

steps.resource_add.descriptor (property)

NOTE: add docs

Signature

dict

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

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)

NOTE: add docs

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

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)

NOTE: add docs

Signature

str

steps.resource_transform.steps (property)

NOTE: add docs

Signature

List[Step]

Update Resource

This step update a resource's metadata.

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

Signature

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

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

steps.resource_update.name (property)

NOTE: add docs

Signature

str

steps.resource_update.descriptor (property)

NOTE: add docs

Signature

IDescriptor

It's a beta version of Frictionless Framework (v5). Read Frictionless Framework (v4) docs for a version that is currently installed by default by pip.