Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
OCaml Interface for Python.
Call initialize ()
first.
val initialize :
?library_name:string ->
?interpreter:string ->
?version:int ->
?minor:int ->
?verbose:bool ->
?debug_build:bool ->
unit ->
unit
initialize ~interpreter ~version ~minor ~verbose ~debug_build ()
finds and loads the Python library. This function should be called before any other functions, except if explicitely mentioned. If library_name
is given, it is used as the path for the library to be loaded: in this case, version parameters are ignored. If library_name
is not given, the library is searched as described below. version
should specify the major version number of Python (2 or 3). minor
should specify the minor version number. If no version number is given, the version of Python is determined by the output of the shell command python --version
. If an interpreter
executable name is given, this executable is used in place of python
in the previous command line. The library is searched by using pkg-config
if available, by considering system paths, and in the directory ../lib
relatively to the directory where the python
executable is. If the library has been statically linked with the executable, it will be used. When verbose
is true (default: false), library filenames that are tried to be loaded are printed on standard error. debug_build
specifies whether the Python library is a debug build: if the argument is left unspecified, debug build is detected automatically.
finalize ()
unloads the library. No other functions except initialize ()
should be called afterwards.
on_finalize f
registers f ()
to be executed when finalize
is executed.
is_initialized ()
returns true
if the library is initialized (initialize ()
has been called and finalize ()
has not been called afterwards).
get_library_filename ()
returns Some filename
where filename
is the path to the Python library that has been loaded, or None
if no Python library has been loaded (for example, if the library has been statically linked with the executable).
version_major ()
returns the major number (the first component) of the version of the Python library, either 2
or 3
.
version_minor ()
returns the minor number (the second component) of the version of the Python library.
Either a filename or a channel. Channels suppose that the same C runtime has been used to compile both the Python library and the OCaml runtime. Warning: using channels is unsafe if runtimes differ (can lead to segmentation fault).
module Object : sig ... end
General functions to handle Python values
E (errtype, errvalue)
is a Python error. errtype
is the type of the exception. errvalue
is the value.
val null : Object.t
The value NULL
of the C Python API. null
is useful for calling directly the functions of Pywrappers
module. The value should not appear when using the functions of the Py
module. This value is guaranteed to be the unique value associated to NULL
.
val is_null : Object.t -> bool
Py.is_null v
is true if and only if v
is NULL
. Since Py.none
is guaranteed to be the unique value associated to NULL
, Py.is_null v
is equivalent to v == Py.null
.
check_not_null v
checks that v
is not null
and returns v
. Raises the current Python error as exception otherwise.
val none : Object.t
The value None
of Python. This value is guaranteed to be the unique value associated to None
.
val is_none : Object.t -> bool
Py.is_none v
is true if and only if v
is None
. Since Py.none
is guaranteed to be the unique value associated to None
, Py.is_none v
is equivalent to v == Py.none
.
Sets the program name (by default, Sys.argv.(0)
). The function can be called before initialize ()
and the value is preserved from one initialization to the other.
Sets the path of the Python home. The function can be called before initialize ()
and the value is preserved from one initialization to the other.
Adds a path to Python search path. The function can be called before initialize ()
and the value is preserved from one initialization to the other.
Gets the program name (by default, Sys.argv.(0)
). The function can be called before initialize ()
.
Gets the path of the Python home. The function can be called before initialize ()
.
Wrapper for Py_GetProgramFullPath.
Wrapper for Py_GetPrefix.
Wrapper for Py_GetExecPrefix.
Wrapper for Py_GetPath.
Wrapper for Py_GetVersion.
Wrapper for Py_GetPlatform.
Wrapper for Py_GetCopyright.
Wrapper for Py_GetCompiler.
Wrapper for Py_GetBuildInfo.
module Bool : sig ... end
Interface for Python values of type Bool
.
module Callable : sig ... end
Interface for Python values of type Callable
.
module Capsule : sig ... end
Embedding of OCaml values in Python.
module Class : sig ... end
Defining a new class type
module Long : sig ... end
Interface for Python values of type Long
.
module Int : sig ... end
Interface for Python values of type Int
if Python 2, Long
if Python 3.
module Dict : sig ... end
Interface for Python values of type Dict
.
module Set : sig ... end
Interface for Python values of type Set
.
module Err : sig ... end
module Traceback : sig ... end
exception Err of Err.t * string
Represents an exception to be set with Err.set_error
in a callback.
exception Err_with_traceback of Err.t * string * Traceback.t
Represents an exception with traceback information to be set with Err.restore
.
module Eval : sig ... end
module Float : sig ... end
Interface for Python values of type Float
.
val int_of_optimize : optimize -> int
module Import : sig ... end
Importing Modules
val import : string -> Object.t
Equivalent to Import.import_module
.
val import_opt : string -> Object.t option
Equivalent to Import.import_module_opt
.
module Iter : sig ... end
Interface for Python values of type Iter
.
module List : sig ... end
Interface for Python values of type List
.
module Mapping : sig ... end
Interface for Python values with a Mapping
interface.
module Method : sig ... end
Interface for Python values of type Method
.
val string_of_input : input -> string
module Module : sig ... end
Interface for Python values of type Module
.
module Number : sig ... end
Interface for Python values of type Number
.
module Run : sig ... end
Interface for Python values of type Run
.
module Sequence : sig ... end
Interface for Python values with a Sequence
interface.
module String : sig ... end
Interface for Python values of type String
, Bytes
and Unicode
.
module Bytes : sig ... end
Interface for Python values of type Bytes
. With Python 2, aliases for String
.
module Tuple : sig ... end
Interface for Python values of type Tuple
.
module Type : sig ... end
Introspection of Python types
module Marshal : sig ... end
module Array : sig ... end
module Gil : sig ... end
val last_value : unit -> Object.t
last_value ()
returns the last value that was computed in the toplevel. We have Py.last_value = Py.Module.find (Py.Module.builtins ()) "_"
.
This printer pretty-prints E (ty, value)
exceptions. It is automatically registered to Printexc.register_printer
.
val compile :
source:string ->
filename:string ->
?dont_inherit:bool ->
?optimize:[ `Default | `Debug | `Normal | `RemoveDocstrings ] ->
[ `Exec | `Eval | `Single ] ->
Object.t
Old interface for Py.Module.compile
.