Loaders

Module: polygraphy.backend.common

class BytesFromPath(path)[source]

Bases: BaseLoader

Functor that can load a file in binary mode (‘rb’).

Loads a file in binary mode (‘rb’).

Parameters:

path (str) – The file path.

call_impl()[source]
Returns:

The contents of the file.

Return type:

bytes

__call__(*args, **kwargs)

Invokes the loader by forwarding arguments to call_impl.

Note: call_impl should not be called directly - use this function instead.

bytes_from_path(path)

Immediately evaluated functional variant of BytesFromPath .

Loads a file in binary mode (‘rb’).

Parameters:

path (str) – The file path.

Returns:

The contents of the file.

Return type:

bytes

class SaveBytes(obj, path)[source]

Bases: BaseLoader

Functor that can save bytes to a file.

Saves bytes to a file.

Parameters:
  • obj (Union[bytes, Callable() -> bytes]) – The bytes to save or a callable that returns them.

  • path (str) – The file path.

call_impl()[source]
Returns:

The bytes saved.

Return type:

bytes

__call__(*args, **kwargs)

Invokes the loader by forwarding arguments to call_impl.

Note: call_impl should not be called directly - use this function instead.

save_bytes(obj, path)

Immediately evaluated functional variant of SaveBytes .

Saves bytes to a file.

Parameters:
  • obj (Union[bytes, Callable() -> bytes]) – The bytes to save or a callable that returns them.

  • path (str) – The file path.

Returns:

The bytes saved.

Return type:

bytes

class InvokeFromScript(path, name)[source]

Bases: BaseLoader

Functor that invokes a function from a Python script.

Invokes the specified function from the specified Python script.

If you intend to use the function more than once, you should import the function using polygraphy.mod.import_from_script instead.

Parameters:
  • path (str) – The path to the Python script. The path must include a ‘.py’ extension.

  • name (str) – The name of the function to import and invoke.

call_impl(*args, **kwargs)[source]
Returns:

The return value of the imported function.

Return type:

object

__call__(*args, **kwargs)

Invokes the loader by forwarding arguments to call_impl.

Note: call_impl should not be called directly - use this function instead.

invoke_from_script(path, name, *args, **kwargs)

Immediately evaluated functional variant of InvokeFromScript .

Invokes the specified function from the specified Python script.

If you intend to use the function more than once, you should import the function using polygraphy.mod.import_from_script instead.

Parameters:
  • path (str) – The path to the Python script. The path must include a ‘.py’ extension.

  • name (str) – The name of the function to import and invoke.

Returns:

The return value of the imported function.

Return type:

object