Module Py

module Py: sig .. end
OCaml Interface for Python.


Call initialize () first.
val initialize : ?interpreter:string ->
?version:int -> ?minor:int -> ?verbose:bool -> unit -> unit
initialize ~interpreter ~version ~minor ~verbose () finds and loads the Python library. This function should be called before any other functions, except if explicitely mentioned. 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.
val finalize : unit -> unit
finalize () unloads the library. No other functions except initialize () should be called afterwards.
val on_finalize : (unit -> unit) -> unit
on_finalize f registers f () to be executed when finalize is executed.
val is_initialized : unit -> bool
is_initialized () returns true if the library is initialized (initialize () has been called and finalize () has not been called afterwards).
val get_library_filename : unit -> string option
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).
val version : unit -> string
version () returns the version of the Python library. E.g. "3.5.1".
val version_major : unit -> int
version_major () returns the major number (the first component) of the version of the Python library, either 2 or 3.
val version_minor : unit -> int
version_minor () returns the minor number (the second component) of the version of the Python library.
type compare = Pytypes.compare = 
| LT
| LE
| EQ
| NE
| GT
| GE
type 'a file = 'a Pytypes.file = 
| Filename of string
| Channel of 'a
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).
val check_error : unit -> unit
module Object: sig .. end
General functions to handle Python values
exception E of Object.t * Object.t
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.
val none : Object.t
The value None of Python.
val check_not_null : Object.t -> Object.t
check_not_null v checks that v is not null and returns v. Raises the current Python error as exception otherwise.
val set_program_name : string -> unit
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.
val set_python_home : string -> unit
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.
val add_python_path : string -> unit
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.
val get_program_name : unit -> string
Gets the program name (by default, Sys.argv.(0)). The function can be called before initialize ().
val get_python_home : unit -> string
Gets the path of the Python home. The function can be called before initialize ().
val get_program_full_path : unit -> string
Wrapper for Py_GetProgramFullPath.
val get_prefix : unit -> string
Wrapper for Py_GetPrefix.
val get_exec_prefix : unit -> string
Wrapper for Py_GetExecPrefix.
val get_path : unit -> string
Wrapper for Py_GetPath.
val get_version : unit -> string
Wrapper for Py_GetVersion.
val get_platform : unit -> string
Wrapper for Py_GetPlatform.
val get_copyright : unit -> string
Wrapper for Py_GetCopyright.
val get_compiler : unit -> string
Wrapper for Py_GetCompiler.
val get_build_info : unit -> string
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 Err: sig .. end
exception Err of Err.t * string
Represents an exception to be set with Py.Err.set_error in a callback.
module Eval: sig .. end
module Float: sig .. end
Interface for Python values of type Float.
module Import: sig .. end
Importing Modules
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.
module Module: sig .. end
Interface for Python values of type Module.
module Number: sig .. end
Interface for Python values of type Number.
type input = Pytypes.input = 
| Single
| File
| Eval
module Run: sig .. end
Interface for Python values of type Run.
module Sequence: sig .. end
Interface for Python values with a Sequence interface.
type byteorder = 
| LittleEndian
| BigEndian
module String: sig .. end
Interface for Python values of type String, Bytes and Unicode.
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
val set_argv : string array -> unit
set_argv argv set Python's sys.argv.
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 ()) "_".
val exception_printer : exn -> string option
This printer pretty-prints E (ty, value) exceptions. It is automatically registered to Printexc.register_printer.