polywrap_client.client module
This module contains the Polywrap client implementation.
- class polywrap_client.client.PolywrapClient(config: ClientConfig)[source]
Bases:
ClientDefines the Polywrap client.
- Parameters:
config (ClientConfig) – The polywrap client config.
- get_config() ClientConfig[source]
Get the client configuration.
- Returns:
The polywrap client configuration.
- Return type:
- get_env_by_uri(uri: Uri) Any | None[source]
Get the environment variables for the given URI.
- Parameters:
uri (Uri) – The URI of the wrapper.
- Returns:
The environment variables.
- Return type:
Union[Any, None]
- get_envs() Dict[Uri, Any][source]
Get the dictionary of environment variables.
- Returns:
The dictionary of environment variables.
- Return type:
Dict[Uri, Any]
- get_file(uri: Uri, path: str, encoding: str | None = 'utf-8') bytes | str[source]
Get the file from the given wrapper URI.
- Parameters:
uri (Uri) – The wrapper URI.
path (str) – The path to the file.
encoding (Optional[str]) – The encoding of the file.
- Returns:
The file contents.
- Return type:
Union[bytes, str]
- get_implementations(uri: Uri, apply_resolution: bool = True, resolution_context: UriResolutionContext | None = None) List[Uri] | None[source]
Get implementations of an interface with its URI.
- Parameters:
uri (Uri) – URI of the interface.
apply_resolution (bool) – If True, apply resolution to the URI and interfaces.
resolution_context (Optional[UriResolutionContext]) – A URI resolution context
- Returns:
List of implementations or None if not found.
- Return type:
Optional[List[Uri]]
- Raises:
WrapGetImplementationsError – If the URI cannot be resolved.
- get_manifest(uri: Uri, options: DeserializeManifestOptions | None = None) WrapManifest[source]
Get the manifest from the given wrapper URI.
- Parameters:
uri (Uri) – The wrapper URI.
options (Optional[DeserializeManifestOptions]) – The manifest options.
- Returns:
The manifest.
- Return type:
AnyWrapManifest
- get_uri_resolver() UriResolver[source]
Get the URI resolver.
- Returns:
The URI resolver.
- Return type:
- invoke(uri: Uri, method: str, args: Any | None = None, env: Any | None = None, resolution_context: UriResolutionContext | None = None, encode_result: bool | None = False) Any[source]
Invoke the given wrapper URI.
- Parameters:
uri (Uri) – The wrapper URI.
method (str) – The method to invoke.
args (Optional[Any]) – The arguments to pass to the method.
env (Optional[Any]) – The environment variables to pass.
resolution_context (Optional[UriResolutionContext]) – The resolution context.
encode_result (Optional[bool]) – If True, encode the result.
- Returns:
The result of the invocation.
- Return type:
Any
- Raises:
MsgpackError – If the data cannot be encoded/decoded.
ManifestError – If the manifest is invalid.
WrapError – If something went wrong during the invocation.
WrapNotFoundError – If the wrap is not found.
UriResolutionError – If the URI cannot be resolved.
- load_wrapper(uri: Uri, resolution_context: UriResolutionContext | None = None) Wrapper[source]
Load the wrapper for the given URI.
- Parameters:
uri (Uri) – The wrapper URI.
resolution_context (Optional[UriResolutionContext]) – The resolution context.
- Returns:
initialized wrapper instance.
- Return type:
- Raises:
UriResolutionError – If the URI cannot be resolved.
WrapNotFoundError – If the wrap is not found.
- try_resolve_uri(uri: Uri, resolution_context: UriResolutionContext | None = None) Uri | UriWrapper | UriPackage[source]
Try to resolve the given URI.
- Parameters:
uri (Uri) – The URI to resolve.
resolution_context (Optional[UriResolutionContext]) – The resolution context.
- Returns:
The resolved URI, package or wrapper.
- Return type:
UriPackageOrWrapper
- Raises:
UriResolutionError – If the URI cannot be resolved.