PyLib (Java-Python Bridge 0.8 Java API)
Date: 2015-11-20

org.jpy

## Class PyLib

- java.lang.Object
- - org.jpy.PyLib

-     public class PyLib
      extends Object

  Represents the library that provides the Python interpreter (CPython).

  When the `PyLib` class is loaded, it reads its configuration from a Java properties file called `.jpy` which must exist in the current user's home directory. The configuration file has been written to this location by installing the Python jpy module using `python3 setup.py install --user` on Unix and `python setup.py install`) on Windows.

  Currently, the following properties are recognised in the `.jpy` file:

  - `python.lib` - the Python shared library (usually required on Unix only)
  - `jpy.lib` - the jpy shared library path for Python (Unix: `jpy*.so`, Windows: `jpy*.pyd`)

  jpy API clients should first call `isPythonRunning()` in order to check if a Python interpreter is already available. If not, `startPython(String...)` must be called before any other jpy API is used.

  Important note for developers: If you change the signature of any of the native `PyLib` methods, you must first run `javah` on the compiled class, and then adapt `src/main/c/jni/org_jpy_PyLib.c`.

  Since:
    0.7

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `PyLib.CallableKind` The kind of callable Python objects.
    `static class` | `PyLib.Diag` Controls output of diagnostic information for debugging.

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `assertPythonRuns()` Throws a runtime exception if Python interpreter is not running.
    `static int` | `execScript(String script)` Deprecated.
    `static String` | `getDllFilePath()`
    `static String` | `getPythonVersion()`
    `static boolean` | `isPythonRunning()`
    `static void` | `startPython(String... extraPaths)` Starts the Python interpreter.
    `static void` | `stopPython()` Stops the Python interpreter.

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getDllFilePath

          public static String getDllFilePath()

    - #### assertPythonRuns

          public static void assertPythonRuns()

      Throws a runtime exception if Python interpreter is not running. Possible reasons for this are
      - You have not called `startPython(String...)` yet.
      - The Python shared library code for the Python interpreter could not be found or could not be be loaded.
      - The Python shared library code for the Python 'jpy' module could not be found or could not be be loaded.
      - The Python interpreter could not be initialised.

    - #### isPythonRunning

          public static boolean isPythonRunning()

      Returns:
        `true` if the Python interpreter is running and the the 'jpy' module has been loaded.

    - #### startPython

          public static void startPython(String... extraPaths)

      Starts the Python interpreter. It does the following:
      1. Initializes the Python interpreter, if not already running.
      2. Prepends any given extra paths to Python's 'sys.path' (e.g. so that 'jpy' can be loaded from isolated directories).
      3. Imports the 'jpy' extension module, if not already done.
      Parameters:
        `extraPaths` - List of paths that will be prepended to Python's 'sys.path'.
      Throws:
        `RuntimeException` - if Python could not be started or if the 'jpy' extension module could not be loaded.

    - #### getPythonVersion

          public static String getPythonVersion()

      Returns:
        The Python interpreter version string.

    - #### stopPython

          public static void stopPython()

      Stops the Python interpreter.

    - #### execScript

          @Deprecated
          public static int execScript(String script)

      Deprecated.

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