package pyml

  1. Overview
  2. Docs
OCaml bindings for Python

Install

Dune Dependency

Authors

Maintainers

Sources

pyml-20220325.tar.gz
sha512=462f86478a0131248805cc13d7eb4e5b4259241d9074e5ab00221018b7fe2d023a12ebf7ffcb81211ffca689fb6b065f251bd900e1925c481f98169e652ab6fa

doc/pyml/Py/index.html

Module PySource

OCaml Interface for Python.

Call initialize () first.

Sourceval 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.

Sourceval finalize : unit -> unit

finalize () unloads the library. No other functions except initialize () should be called afterwards.

Sourceval on_finalize : (unit -> unit) -> unit

on_finalize f registers f () to be executed when finalize is executed.

Sourceval is_initialized : unit -> bool

is_initialized () returns true if the library is initialized (initialize () has been called and finalize () has not been called afterwards).

Sourceval is_debug_build : unit -> bool

is_debug_build () returns true if the library is a debug build.

Sourceval 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).

Sourceval version : unit -> string

version () returns the version of the Python library. E.g. "3.5.1".

Sourceval version_major : unit -> int

version_major () returns the major number (the first component) of the version of the Python library, either 2 or 3.

Sourceval version_minor : unit -> int

version_minor () returns the minor number (the second component) of the version of the Python library.

Sourcetype compare = Pytypes.compare =
  1. | LT
  2. | LE
  3. | EQ
  4. | NE
  5. | GT
  6. | GE
Sourcetype 'a file = 'a Pytypes.file =
  1. | Filename of string
  2. | 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).

Sourceval check_error : unit -> unit
Sourcemodule Object : sig ... end

General functions to handle Python values

Sourceexception E of Object.t * Object.t

E (errtype, errvalue) is a Python error. errtype is the type of the exception. errvalue is the value.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval none : Object.t

The value None of Python. This value is guaranteed to be the unique value associated to None.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval get_program_name : unit -> string

Gets the program name (by default, Sys.argv.(0)). The function can be called before initialize ().

Sourceval get_python_home : unit -> string

Gets the path of the Python home. The function can be called before initialize ().

Sourceval get_program_full_path : unit -> string
Sourceval get_prefix : unit -> string

Wrapper for Py_GetPrefix.

Sourceval get_exec_prefix : unit -> string

Wrapper for Py_GetExecPrefix.

Sourceval get_path : unit -> string

Wrapper for Py_GetPath.

Sourceval get_version : unit -> string

Wrapper for Py_GetVersion.

Sourceval get_platform : unit -> string

Wrapper for Py_GetPlatform.

Wrapper for Py_GetCopyright.

Sourceval get_compiler : unit -> string

Wrapper for Py_GetCompiler.

Sourceval get_build_info : unit -> string

Wrapper for Py_GetBuildInfo.

Sourcemodule Bool : sig ... end

Interface for Python values of type Bool.

Sourcemodule Callable : sig ... end

Interface for Python values of type Callable.

Sourcemodule Capsule : sig ... end

Embedding of OCaml values in Python.

Sourcemodule Class : sig ... end

Defining a new class type

Sourcemodule Long : sig ... end

Interface for Python values of type Long.

Sourcemodule Int : sig ... end

Interface for Python values of type Int if Python 2, Long if Python 3.

Sourcemodule Dict : sig ... end

Interface for Python values of type Dict.

Sourcemodule Set : sig ... end

Interface for Python values of type Set.

Sourcemodule Err : sig ... end
Sourcemodule Traceback : sig ... end
Sourceexception Err of Err.t * string

Represents an exception to be set with Err.set_error in a callback.

Sourceexception Err_with_traceback of Err.t * string * Traceback.t

Represents an exception with traceback information to be set with Err.restore.

Sourcemodule Eval : sig ... end
Sourcemodule Float : sig ... end

Interface for Python values of type Float.

Sourcetype optimize =
  1. | Default
  2. | Debug
  3. | Normal
  4. | RemoveDocstrings
Sourceval int_of_optimize : optimize -> int
Sourcemodule Import : sig ... end

Importing Modules

Sourceval import : string -> Object.t

Equivalent to Import.import_module.

Sourceval import_opt : string -> Object.t option
Sourcemodule Iter : sig ... end

Interface for Python values of type Iter.

Sourcemodule List : sig ... end

Interface for Python values of type List.

Sourcemodule Mapping : sig ... end

Interface for Python values with a Mapping interface.

Sourcemodule Method : sig ... end

Interface for Python values of type Method.

Sourcetype input = Pytypes.input =
  1. | Single
  2. | File
  3. | Eval
Sourceval string_of_input : input -> string
Sourcemodule Module : sig ... end

Interface for Python values of type Module.

Sourcemodule Number : sig ... end

Interface for Python values of type Number.

Sourcemodule Run : sig ... end

Interface for Python values of type Run.

Sourcemodule Sequence : sig ... end

Interface for Python values with a Sequence interface.

Sourcetype byteorder =
  1. | LittleEndian
  2. | BigEndian
Sourcemodule String : sig ... end

Interface for Python values of type String, Bytes and Unicode.

Sourcemodule Bytes : sig ... end

Interface for Python values of type Bytes. With Python 2, aliases for String.

Sourcemodule Tuple : sig ... end

Interface for Python values of type Tuple.

Sourcemodule Type : sig ... end

Introspection of Python types

Sourcemodule Marshal : sig ... end
Sourcemodule Array : sig ... end
Sourcemodule Gil : sig ... end
Sourceval set_argv : string array -> unit

set_argv argv set Python's sys.argv.

Sourceval 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 ()) "_".

Sourceval exception_printer : exn -> string option

This printer pretty-prints E (ty, value) exceptions. It is automatically registered to Printexc.register_printer.

Sourceval compile : source:string -> filename:string -> ?dont_inherit:bool -> ?optimize:[ `Default | `Debug | `Normal | `RemoveDocstrings ] -> [ `Exec | `Eval | `Single ] -> Object.t

Old interface for Py.Module.compile.

OCaml

Innovation. Community. Security.