Frictionless supports working with Inline Data from memory.
You can read data in this format using Package/Resource
, for example:
from pprint import pprint
from frictionless import Resource
resource = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': 'german'}]
The same is actual for writing:
from frictionless import Resource
source = Resource('table.csv')
target = source.write(format='inline', datatype='table')
print(target)
print(target.to_view())
{'name': 'memory',
'type': 'table',
'data': [['id', 'name'], [1, 'english'], [2, '中国人']],
'format': 'inline'}
+----+-----------+
| id | name |
+====+===========+
| 1 | 'english' |
+----+-----------+
| 2 | '中国人' |
+----+-----------+
There is a dialect to configure this format, for example:
from frictionless import Resource, formats
control = formats.InlineControl(keyed=True, keys=['name', 'id'])
resource = Resource(data=[{'id': 1, 'name': 'english'}, {'id': 2, 'name': 'german'}], control=control)
print(resource.to_view())
+-----------+----+
| name | id |
+===========+====+
| 'english' | 1 |
+-----------+----+
| 'german' | 2 |
+-----------+----+
Inline control representation. Control class to set params for Inline reader/writer.
(*, name: Optional[str] = None, title: Optional[str] = None, description: Optional[str] = None, keys: Optional[List[str]] = None, keyed: bool = False) -> None
Specify 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.
bool