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.
This step add a new resource to a data package.
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 |
+----+-----------+------------+
Add resource. This step can be added using the `steps` parameter for the `transform` function.
(*, title: Optional[str] = None, description: Optional[str] = None, name: str, descriptor: Dict[str, Any]) -> None
Name of the resource to add.
str
A descriptor for the resource.
Dict[str, Any]
This step remove an existent resource from a data package.
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': []}
Remove resource. This step can be added using the `steps` parameter for the `transform` function.
(*, title: Optional[str] = None, description: Optional[str] = None, name: str) -> None
Name of the resource to remove.
str
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.
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 |
+----+-----------+------------+
Transform resource. This step can be added using the `steps` parameter for the `transform` function.
(*, title: Optional[str] = None, description: Optional[str] = None, name: str, steps: List[Step]) -> None
Name of the resource to transform.
str
List of transformation steps to apply to the given resource.
List[Step]
This step update a resource's metadata. It can be used for both resource and package transformations.
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'}
Update resource. This step can be added using the `steps` parameter for the `transform` function.
(*, title: Optional[str] = None, description: Optional[str] = None, name: Optional[str] = None, descriptor: types.IDescriptor) -> None
Name of the resource to update.
Optional[str]
New descriptor for the resource to update metadata.
types.IDescriptor