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

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')
print(target)
print(target.to_view())
{'name': 'memory',
 'type': 'file',
 'data': [['id', 'name'], [1, 'english'], [2, '中国人']],
 'scheme': '',
 'format': 'inline',
 'mediatype': 'application/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

Signature

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

Parameters

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

formats.inlineControl.keys (property)

NOTE: add docs

Signature

Optional[List[str]]

formats.inlineControl.keyed (property)

NOTE: add docs

Signature

bool

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.