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
Release history Release notifications | RSS feed
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
Hashes for polywrap_client_config_builder-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2107dd073a66d6fee2747deafe25e416679036cbc904def9be4b6aa03c1c9561 |
|
MD5 | f36b8f2c99427f14d266f4f762aaa4a7 |
|
BLAKE2b-256 | 98a733c1320ae54720aaada71d34a0ca197ce0347645dee08bfca01481e52188 |
Hashes for polywrap_client_config_builder-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ca359a7f5ff39e7daba54cfd948df0797e04942ebaf76a5074c5bddde73d458 |
|
MD5 | 5b974b4544116f4c22506d4388755800 |
|
BLAKE2b-256 | fb512c05869ac606da98b002fe48e6064029fa190ac3c718ae30dc902e8ad2ec |