Edit page in Livemark
(2024-01-29 13:37)

Inline Format

Frictionless supports working with Inline Data from memory.

Reading Data

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'}]

Writing Data

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 | '中国人'     |
+----+-----------+

Configuration

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 |
+-----------+----+

Reference

formats.InlineControl (class)

formats.InlineControl (class)

Inline control representation. Control class to set params for Inline reader/writer.

Signature

(*, name: Optional[str] = None, title: Optional[str] = None, description: Optional[str] = None, keys: Optional[List[str]] = None, keyed: bool = False) -> None

Parameters

  • name (Optional[str])
  • title (Optional[str])
  • description (Optional[str])
  • keys (Optional[List[str]])
  • keyed (bool)

formats.inlineControl.keys (property)

Specify the keys/columns to read from the resource. For example: keys=["id","name"].

Signature

Optional[List[str]]

formats.inlineControl.keyed (property)

If set to True, It returns the data as key:value pair.

Signature

bool