SnakeBridge.Dynamic (SnakeBridge v0.7.4)

View Source

Dynamic dispatch for calling methods on Python objects without generated code.

Use this module when:

  • Python returns an object of a class you did not generate bindings for
  • You need to call methods dynamically at runtime
  • You want a no-codegen escape hatch for refs

Summary

Functions

Calls a method on a Python object reference.

Gets an attribute from a Python object reference.

Checks if a value is a valid Python reference.

Sets an attribute on a Python object reference.

Types

opts()

@type opts() :: keyword()

ref()

@type ref() :: SnakeBridge.Ref.t() | map()

Functions

call(ref, method, args \\ [], opts \\ [])

@spec call(ref(), atom() | String.t(), list(), opts()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Calls a method on a Python object reference.

get_attr(ref, attr, opts \\ [])

@spec get_attr(ref(), atom() | String.t(), opts()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Gets an attribute from a Python object reference.

ref?(value)

@spec ref?(term()) :: boolean()

Checks if a value is a valid Python reference.

set_attr(ref, attr, value, opts \\ [])

@spec set_attr(ref(), atom() | String.t(), term(), opts()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Sets an attribute on a Python object reference.