PyModule (Java-Python Bridge 0.9-SNAPSHOT Java API)
Date: 2017-05-04

org.jpy

## Class PyModule

- java.lang.Object
- - org.jpy.PyObject
  - - org.jpy.PyModule

- All Implemented Interfaces:
    Serializable

      public class PyModule
      extends PyObject

  Represents a Python module.
  Since:
    0.7
  See Also:
    Serialized Form

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `createProxy(Class<T> type)` Create a Java proxy instance of this Python module which contains compatible functions to the ones provided in the interface given by the `type` parameter.
    `static PyObject` | `extendSysPath(String modulePath, boolean prepend)` Extends Python's 'sys.path' variable by the given module path.
    `static PyModule` | `getBuiltins()` Get the Python interpreter's buildins module and returns its Java representation.
    `static PyModule` | `getMain()` Get the Python interpreter's main module and return its Java representation.
    `String` | `getName()`
    `static PyModule` | `importModule(String name)` Import a Python module into the Python interpreter and return its Java representation.

    - ### Methods inherited from class org.jpy.PyObject

      `call, callMethod, createProxy, equals, executeCode, executeCode, finalize, getAttribute, getAttribute, getDoubleValue, getIntValue, getObjectArrayValue, getObjectValue, getPointer, getStringValue, hashCode, setAttribute, setAttribute, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, getClass, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### getName

          public String getName()

      Returns:
        The Python module's name.

    - #### getMain

          public static PyModule getMain()

      Get the Python interpreter's main module and return its Java representation. It can be used to access global scope variables and functions. For example:

                PyLib.execScript("def incByOne(x): return x + 1");
                PyModule mainModule = PyModule.getMain();
                PyObject eleven = mainModule.call("incByOne", 10);

      Returns:
        The Python main module's Java representation.
      Since:
        0.8

    - #### getBuiltins

          public static PyModule getBuiltins()

      Get the Python interpreter's buildins module and returns its Java representation. It can be used to call functions such as `len()`, `type()`, `list()`, etc. For example:

                builtins = PyModule.getBuiltins();
                PyObject size = builtins.call("len", pyList);

      Returns:
        Java representation of Python's builtin module.
      Since:
        0.8
      See Also:
        `PyObject.call(String, Object...)`

    - #### importModule

          public static PyModule importModule(String name)

      Import a Python module into the Python interpreter and return its Java representation.
      Parameters:
        `name` - The Python module's name.
      Returns:
        The Python module's Java representation.

    - #### extendSysPath

          public static PyObject extendSysPath(String modulePath,
                                               boolean prepend)

      Extends Python's 'sys.path' variable by the given module path.
      Parameters:
        `modulePath` - The new module path. Should be an absolute pathname.
        `prepend` - If true, the new path will be the new first element of 'sys.path', otherwise it will be the last.
      Returns:
        The altered 'sys.path' list.
      Since:
        0.8

    - #### createProxy

          public <T> T createProxy(Class<T> type)

      Create a Java proxy instance of this Python module which contains compatible functions to the ones provided in the interface given by the `type` parameter.
      Overrides:
        `createProxy` in class `PyObject`
      Type Parameters:
        `T` - The interface name.
      Parameters:
        `type` - The interface's type.
      Returns:
        A (proxy) instance implementing the given interface.

Copyright © 2014–2017 Brockmann Consult GmbH. All rights reserved.