Polywrap Fs Plugin

The Filesystem plugin enables wraps running within the Polywrap client to interact with the local filesystem.

Interface

The FileSystem plugin implements an existing wrap interface at wrapscan.io/polywrap/file-system@1.0.

Quickstart

Imports

>>> import os
>>> from polywrap_core import Uri
>>> from polywrap_client import PolywrapClient
>>> from polywrap_client_config_builder import PolywrapClientConfigBuilder
>>> from polywrap_fs_plugin import file_system_plugin

Create a Polywrap client

>>> fs_interface_uri = Uri.from_str("wrapscan.io/polywrap/file-system@1.0")
>>> fs_plugin_uri = Uri.from_str("plugin/file-system")
>>> config = (
...     PolywrapClientConfigBuilder()
...     .set_package(fs_plugin_uri, file_system_plugin())
...     .add_interface_implementations(fs_interface_uri, [fs_plugin_uri])
...     .set_redirect(fs_interface_uri, fs_plugin_uri)
...     .build()
... )
>>> client = PolywrapClient(config)

Invoke the plugin

>>> path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml")
>>> result = client.invoke(
...     uri=Uri.from_str("wrapscan.io/polywrap/file-system@1.0"),
...     method="readFile",
...     args={
...         "path": path,
...     }
... )
>>> assert result.startswith(b"[build-system]")
class polywrap_fs_plugin.FileSystemPlugin(*args, **kwargs)[source]

Bases: Module[None]

Defines the Filesystem plugin.

exists(args: ArgsExists, client: InvokerClient, env: None) bool[source]

Check if a file or directory exists.

mkdir(args: ArgsMkdir, client: InvokerClient, env: None)[source]

Create directories on the filesystem.

read_file(args: ArgsReadFile, client: InvokerClient, env: None) bytes[source]

Read a file from the filesystem and return its contents as bytes.

read_file_as_string(args: ArgsReadFileAsString, client: InvokerClient, env: None) str[source]

Read a file from the filesystem, decode it using provided encoding and return its contents as a string.

rm(args: ArgsRm, client: InvokerClient, env: None) bool[source]

Remove a file or directory from the filesystem.

rmdir(args: ArgsRmdir, client: InvokerClient, env: None) bool[source]

Remove an empty directory from the filesystem.

write_file(args: ArgsWriteFile, client: InvokerClient, env: None) bool[source]

Write data to a file on the filesystem.

polywrap_fs_plugin.file_system_plugin() PluginPackage[None][source]

Create a Polywrap plugin instance for interacting with EVM networks.

API References