Edit page in Livemark
(2024-11-07 15:17)

Buffer Scheme

Frictionless supports working with bytes loaded into memory.

Reading Data

You can read Buffer Data using Package/Resource API, for example:

from pprint import pprint
from frictionless import Resource

resource = Resource(b'id,name\n1,english\n2,german', format='csv')
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': 'german'}]

Writing Data

A similiar approach can be used for writing:

from frictionless import Resource

source = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
target = source.write(scheme='buffer', format='csv')
print(target)
print(target.read_rows())
{'name': 'memory',
 'type': 'table',
 'data': [],
 'scheme': 'buffer',
 'format': 'csv',
 'mediatype': 'text/csv'}
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': 'german'}]