Library
Module
Module type
Parameter
Class
Class type
val create : ?docstring:Base.string -> Base.string -> t
create ?docstring module_name
creates a new python module with the specified name. This module can directly be imported from python.
val module_name : t -> Base.string
module_name t
returns the name used to create the module.
val create_with_eval : name:Base.string -> py_source:Base.string -> t
create_with_eval ~name ~py_source
creates a new module defined by evaluating py_source
which contains some python code.
val import : Base.string -> t
import module_name
imports an already existing module.
val set_value : t -> Base.string -> Pytypes.pyobject -> Base.unit
set_value t name obj
sets the field name
on module t
to hold value obj
. This can be accessed via t.name
in python.
val pyobject : t -> Pytypes.pyobject
pyobject t
returns the underlying python object for a module.
val set_function :
t ->
?docstring:Base.string ->
Base.string ->
(Pytypes.pyobject Base.array -> Pytypes.pyobject) ->
Base.unit
set_function t ?docstring name fn
adds to module t
a function named name
which evaluates as the fn
closure. This only handles positional arguments.
val set_function_with_keywords :
t ->
?docstring:Base.string ->
Base.string ->
(Pytypes.pyobject Base.array ->
(Base.string, Pytypes.pyobject, Base.String.comparator_witness) Base.Map.t ->
Pytypes.pyobject) ->
Base.unit
set_function_with_keywords t ?docstring name fn
adds to module t
a function named name
which evaluates as the fn
closure. This handles both positional and keyword arguments.
val set :
t ->
?docstring:Base.string ->
Base.string ->
(Base.unit -> Pytypes.pyobject) Defunc.t ->
Base.unit
set t ?docstring name fn
sets a function on module t
named name
. This function is defined by defunc fn
.
val set_unit :
t ->
?docstring:Base.string ->
Base.string ->
(Base.unit -> Base.unit) Defunc.t ->
Base.unit
set_unit
is a specialized version of set
for function that return unit
.
val set_no_arg :
t ->
?docstring:Base.string ->
Base.string ->
(Base.unit -> Pytypes.pyobject) ->
Base.unit
set_no_arg t ?docstring name fn
sets a function on module t
named name
. This function does not take any positional or keyword argument.
val keywords_of_python :
Pytypes.pyobject ->
(Base.string, Pytypes.pyobject, Base.String.comparator_witness) Base.Map.t
Base.Or_error.t
Helper function to get keywords from a python object. When no keyword is present, null is used; otherwise a python dictionary with string key gets used.
val wrap_ocaml_errors : (Base.unit -> 'a) -> 'a
val raise_py_err_with_backtrace :
?unwrap_more:
(Base.exn ->
(Caml.Printexc.raw_backtrace Base.list * Base.exn) Base.option) ->
?backtrace:Caml.Printexc.raw_backtrace ->
Base.exn ->
'a
Raise a Python exception that will include the OCaml backtrace information as part of the Python exception traceback. unwrap_more
can be specified to extract nested exceptions and provide additional backtraces if relevant. Note that unwrap_more exn
returning exn
would result in an infinite loop.
module Raw : sig ... end