wrapyfi package

Subpackages

Submodules

wrapyfi.encoders module

wrapyfi.utils module

wrapyfi.utils.deepcopy(obj: Any, exclude_keys: list | tuple | None = None, shallow_keys: list | tuple | None = None)[source]

Deep copy an object, excluding specified keys.

Parameters:
  • obj – Any: The object to deep copy

  • exclude_keys – Union[list, tuple]: A list of keys to exclude from the deep copy

  • shallow_keys – Union[list, tuple]: A list of keys to shallow copy

wrapyfi.utils.get_default_args(fnc: Callable[[...], Any])[source]

Get the default arguments for a function.

Parameters:

fnc – Callable[…, Any]: The function to get the default arguments for

wrapyfi.utils.match_args(args: list | tuple, kwargs: dict, src_args: list | tuple, src_kwargs: dict)[source]

Match and Substitute Arguments and Keyword Arguments using Specified Source Values.

Navigate through the provided args and kwargs, identifying entries prefixed with “$” and substituting them with values from src_args and src_kwargs respectively, to dynamically modify the function call parameters using the source values.

Parameters:
  • args

    Union[list, tuple]: A list of arguments, potentially containing strings that indicate substitutable entries. Substitutable entries are prefixed with “$” and followed by either:

    • A digit (indicating an index to reference a value from src_args), or

    • Non-digit characters (indicating a key to reference a value from src_kwargs).

  • kwargs – dict: A dictionary of keyword arguments, where values might be strings indicating substitutable entries, similar to the entries in args.

  • src_args – Union[list, tuple]: A list of source arguments, intended to be referenced by substitutable entries within args.

  • src_kwargs – dict: A dictionary of source keyword arguments, intended to be referenced by substitutable entries within args and kwargs.

Returns:

Tuple[list, dict]: A tuple containing: - list: The new arguments, formed by substituting specified entries from args using src_args and src_kwargs. - dict: The new keyword arguments, formed by substituting specified entries from kwargs using src_args and src_kwargs.

wrapyfi.utils.dynamic_module_import(modules: List[str], globals: dict)[source]

Dynamically import modules.

Parameters:
  • modules – List[str]: A list of module names to import

  • globals – dict: The globals dictionary to update

class wrapyfi.utils.SingletonOptimized[source]

Bases: type

A singleton metaclass that is thread-safe and optimized for speed.

Source: https://stackoverflow.com/a/6798042

class wrapyfi.utils.Plugin[source]

Bases: object

Base class for encoding and decoding plugins.

encode(*args, **kwargs)[source]

Encode data into a base64 string.

Parameters:
  • args – tuple: Additional arguments

  • kwargs – dict: Additional keyword arguments

Returns:

Tuple[bool, dict]: A tuple containing: - bool: True if the encoding was successful, False otherwise - dict: A dictionary containing:

  • ’__wrapyfi__’: A tuple containing the class name and encoded data string

decode(*args, **kwargs)[source]

Decode a base64 string back into data.

Parameters:
  • args – tuple: Additional arguments

  • kwargs – dict: Additional keyword arguments

Returns:

Tuple[bool, object]: A tuple containing: - bool: True if the decoding was successful, False otherwise - object: The decoded data

class wrapyfi.utils.PluginRegistrar[source]

Bases: object

Class for registering encoding and decoding plugins.

encoder_registry = {}
decoder_registry = {'AstropyData': <class 'examples.encoders.plugins.astropy_tables.AstropyData'>}
static register(types=None)[source]

Register a plugin for encoding and decoding a specific type.

Parameters:

types – tuple: The type(s) to register the plugin for

static scan()[source]

Scan the plugins directory (Wrapyfi builtin and external) for plugins to register. This method is called automatically when the module is imported.

Module contents

unknown_url

wrapyfi.get_project_info_from_setup()[source]