Frictionless supports parsing YAML tables.
We use the
path
argument to ensure that it will not be guessed to be a metadata file
You can read this format using Package/Resource
, for example:
from pprint import pprint
from frictionless import Resource, resources
resource = resources.TableResource(path='table.yaml')
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]
The same is actual for writing:
from frictionless import Resource, resources
source = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
target = resources.TableResource(path='table-output.yaml')
source.write(target)
print(target)
print(target.to_view())
{'name': 'table-output',
'type': 'table',
'path': 'table-output.yaml',
'scheme': 'file',
'format': 'yaml',
'mediatype': 'text/yaml'}
+----+-----------+
| id | name |
+====+===========+
| 1 | 'english' |
+----+-----------+
| 2 | 'german' |
+----+-----------+
There is a dialect to configure how Frictionless read and write files in this format. For example:
from pprint import pprint
from frictionless import Resource, resources, formats
control=formats.YamlControl(keyed=True)
resource = resources.TableResource(path='table.keyed.yaml', control=control)
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]
Yaml control representation.
(*, name: Optional[str] = None, title: Optional[str] = None, description: Optional[str] = None, keys: Optional[List[str]] = None, keyed: bool = False, property: Optional[str] = None) -> None
Specifies the keys/columns to read from the resource. For example: keys=["id","name"].
Optional[List[str]]
If set to True, It returns the data as key:value pair. Default value is False.
bool
This property specifies the path to the attribute in a json file, it it has nested fields.
Optional[str]