Skip to main content

PolywrapClientConfigBuilder - A utility class for building the PolywrapClient config.

Project description

This package contains modules related to ClientConfigBuilder - A utility class for building the PolywrapClient config.

PolywrapClientConfigBuilder Supports building configs using method chaining or imperatively.

Quickstart

Import

Import necessary modules

>>> from typing import cast
>>> from polywrap_client_config_builder import (
...     PolywrapClientConfigBuilder,
...     BuilderConfig,
...     BuildOptions,
... )
>>> from polywrap_core import WrapPackage, Uri, ClientConfig
>>> from polywrap_uri_resolvers import (
...     RedirectResolver,
...     InMemoryResolutionResultCache,
...     RecursiveResolver,
... )
>>> from polywrap_sys_config_bundle import sys_bundle
>>> from polywrap_web3_config_bundle import web3_bundle

Initialize

Initialize a PolywrapClientConfigBuilder using the constructor

>>> # start with a blank slate (typical usage)
>>> builder = PolywrapClientConfigBuilder()

Configure

Add client configuration with add, or flexibly mix and match builder configuration methods to add and remove configuration items.

Add multiple items to the configuration using the catch-all add method

>>> builder = builder.add(
...     BuilderConfig(
...         envs={},
...         interfaces={},
...         redirects={},
...         wrappers={},
...         packages={},
...         resolvers=[]
...     )
... )

Add or remove items by chaining method calls

>>> builder = (
...     builder
...     .set_package(Uri.from_str("wrap://plugin/package"), cast(WrapPackage, NotImplemented))
...     .remove_package(Uri.from_str("wrap://plugin/package"))
...     .set_packages(
...         {
...             Uri.from_str("wrap://plugin/http"): cast(WrapPackage, NotImplemented),
...             Uri.from_str("wrap://plugin/filesystem"): cast(WrapPackage, NotImplemented),
...         }
...     )
... )
>>> Uri.from_str("wrap://plugin/http") in builder.config.packages
True
>>> Uri.from_str("wrap://plugin/filesystem") in builder.config.packages
True
>>> Uri.from_str("wrap://plugin/package") in builder.config.packages
False

Configure using sys config bundle to fetch wraps from file-system, ipfs, wrapscan, or http server

>>> from polywrap_sys_config_bundle import sys_bundle
>>> builder = builder.add_bundle(sys_bundle)

Configure using web3 config bundle to fetch wraps from ens and any system URI

>>> from polywrap_web3_config_bundle import web3_bundle
>>> builder = builder.add_bundle(web3_bundle)

Build

Finally, build a ClientConfig to pass to the PolywrapClient constructor.

Accepted by the PolywrapClient

>>> config = builder.build()
>>> assert isinstance(config, ClientConfig)
>>> assert isinstance(config.resolver, RecursiveResolver)

Build with a custom cache

>>> config = builder.build(
...     BuildOptions(
...         resolution_result_cache=InMemoryResolutionResultCache()
...     )
... )
>>> assert isinstance(config, ClientConfig)
>>> assert isinstance(config.resolver, RecursiveResolver)

Or build with a custom resolver

>>> config = builder.build(
...     BuildOptions(
...         resolver=RedirectResolver(
...             from_uri=Uri.from_str("wrap://test/from"),
...             to_uri=Uri.from_str("wrap://test/to")
...         )
...     )
... )
>>> assert isinstance(config, ClientConfig)
>>> assert isinstance(config.resolver, RedirectResolver)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file polywrap_client_config_builder-0.1.0b7.tar.gz.

File metadata

File hashes

Hashes for polywrap_client_config_builder-0.1.0b7.tar.gz
Algorithm Hash digest
SHA256 1a139456dabd0f87fa82eca20ee5ab07c4b67f3264dee3fbeb9ebff27576351c
MD5 9479aae37370564c126d7da76b669095
BLAKE2b-256 ab76017eba83ef7ce6e1df35166feb3016417a7db76e725630211d97a822ed16

See more details on using hashes here.

Provenance

File details

Details for the file polywrap_client_config_builder-0.1.0b7-py3-none-any.whl.

File metadata

File hashes

Hashes for polywrap_client_config_builder-0.1.0b7-py3-none-any.whl
Algorithm Hash digest
SHA256 52025207756689f213e64d674143febd1b98f7ad537a949b35075e5190709743
MD5 e3845974d2642afc3602ba07dc71af3f
BLAKE2b-256 e544f5e1df39904d34abc52d7cfe15ec64973eb61d772110c40b88f3b513e8cb

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page