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

Sql Format

Frictionless supports reading and writing SQL databases.

pip install frictionless[sql]
pip install 'frictionless[sql]' # for zsh shell

Reading Data

You can read SQL database:

from pprint import pprint
from frictionless import Package

package = Package.from_sql('postgresql://database')
pprint(package)
for resource in package.resources:
  pprint(resource.read_rows())

SQLite

Here is a example of reading a table from a SQLite database using basepath:

from frictionless import Resource, formats

control = SqlControl(table="test_table", basepath='data')
with Resource(path="sqlite:///sqlite.db", control=control) as resource:
    print(resource.read_rows())

Writing Data

You can write SQL databases:

from frictionless import Package

package = Package('path/to/datapackage.json')
package.to_sql('postgresql://database')

Configuration

There is a dialect to configure how Frictionless read and write files in this format. For example:

from frictionless import Resource, formats

control = SqlControl(table='table', order_by='field', where='field > 20')
resource = Resource('postgresql://database', control=control)

Reference

formats.SqlControl (class)

formats.SqlControl (class)

SQL control representation

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, table: Optional[str] = None, prefix: str = , order_by: Optional[str] = None, where: Optional[str] = None, namespace: Optional[str] = None, basepath: Optional[str] = None) -> None

Parameters

  • title (Optional[str])
  • description (Optional[str])
  • table (Optional[str])
  • prefix (str)
  • order_by (Optional[str])
  • where (Optional[str])
  • namespace (Optional[str])
  • basepath (Optional[str])

formats.sqlControl.table (property)

NOTE: add docs

Signature

Optional[str]

formats.sqlControl.prefix (property)

NOTE: add docs

Signature

str

formats.sqlControl.order_by (property)

NOTE: add docs

Signature

Optional[str]

formats.sqlControl.where (property)

NOTE: add docs

Signature

Optional[str]

formats.sqlControl.namespace (property)

NOTE: add docs

Signature

Optional[str]

formats.sqlControl.basepath (property)

NOTE: add docs

Signature

Optional[str]

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.