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

System/Plugin

System Object

The most important undelaying object in the Frictionless Framework is system. It's an singleton object avaialble as frictionless.system. This object can be used to instantiate different kind of lower-level as though Check, Step, or Field. Here is a quick example of using the system object:

from frictionless import Resource, system

# Create

loader = system.create_loader(resource)
parser = system.create_parser(resource)
parser = system.create_manager(source, control=control)

# Detect

system.detect_resource(resource)
field_candidates = system.detect_field_candidates()

# Select

Check = system.selectCheck('type')
Control = system.selectControl('type')
Error = system.selectError('type')
Field = system.selectField('type')
Step = system.selectStep('type')

As an extension author you might use the system object in various cases. For example, take a look at this MultipartLoader excerpts:

def read_line_stream(self):
    for number, path in enumerate(self.__path, start=1):
        resource = Resource(path=path)
        resource.infer(sample=False)
        with system.create_loader(resource) as loader:
            for line_number, line in enumerate(loader.byte_stream, start=1):
                if not self.__headless and number > 1 and line_number == 1:
                    continue
                yield line

It's important to understand that creating low-level objects in general is more corect using the system object than just classes because it will include all the available plugins in the process.

Plugin API

The Plugin API almost fully follows the system object's API. So as a plugin author you need to hook into the same methods. For example, let's take a look at a builtin Csv Plugin:

class CsvPlugin(Plugin):
    """Plugin for CSV"""

    # Hooks

    def create_parser(self, resource: Resource):
        if resource.format in ["csv", "tsv"]:
            return CsvParser(resource)

    def detect_resource(self, resource: Resource):
        if resource.format in ["csv", "tsv"]:
            resource.type = "table"
            resource.mediatype = f"text/{resource.format}"

    def select_Control(self, type: str):
        if type == "csv":
            return CsvControl

Reference

System (class)

Plugin (class)

System (class)

System representation This class provides an ability to make system Frictionless calls. It's available as `frictionless.system` singletone.

Signature

system.supported_hooks (property)

NOTE: add docs

Signature

ClassVar[List[str]]

system.trusted (property)

NOTE: add docs

Signature

bool

system.onerror (property)

NOTE: add docs

Signature

IOnerror

system.standards (property)

NOTE: add docs

Signature

IStandards

system.http_session (property)

Return a HTTP session This method will return a new session or the session from `system.use_http_session` context manager

system.create_loader (method)

Create loader

Signature

(resource: Resource) -> Loader

Parameters

  • resource (Resource): loader resource

system.create_manager (method)

Create manager

Signature

(source: Any, *, control: Optional[Control] = None) -> Optional[Manager]

Parameters

  • source (Any)
  • control (Optional[Control])

system.create_parser (method)

Create parser

Signature

(resource: Resource) -> Parser

Parameters

  • resource (Resource): parser resource

system.create_storage (method)

Create storage

Signature

(name: str, source: Any, **options) -> Storage

Parameters

  • name (str): storage name
  • source (Any)
  • options : storage options

system.deregister (method)

Deregister a plugin

Signature

(name)

Parameters

  • name : plugin name

system.detect_field_candidates (method)

Create candidates

Signature

() -> List[dict]

system.detect_resource (method)

Hook into resource detection

Signature

(resource: Resource) -> None

Parameters

  • resource (Resource): resource

system.register (method)

Register a plugin

Signature

(name, plugin)

Parameters

  • name : plugin name
  • plugin : plugin to register

Plugin (class)

Plugin representation It's an interface for writing Frictionless plugins. You can implement one or more methods to hook into Frictionless system.

plugin.create_loader (method)

Create loader

Signature

(resource: Resource) -> Optional[Loader]

Parameters

  • resource (Resource): loader resource

plugin.create_manager (method)

Create manager

Signature

(source: Any, *, control: Optional[Control] = None) -> Optional[Manager]

Parameters

  • source (Any): source
  • control (Optional[Control]): control

plugin.create_parser (method)

Create parser

Signature

(resource: Resource) -> Optional[Parser]

Parameters

  • resource (Resource): parser resource

plugin.create_storage (method)

Create storage

Signature

(name: str, source: Any, **options) -> Optional[Storage]

Parameters

  • name (str): storage name
  • source (Any)
  • options : storage options

plugin.detect_field_candidates (method)

Detect field candidates

Signature

(candidates: List[dict]) -> Optional[List[dict]]

Parameters

  • candidates (List[dict])

plugin.detect_resource (method)

Hook into resource detection

Signature

(resource: Resource) -> None

Parameters

  • resource (Resource): resource
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.