Python 3 and Python wheels

Starting with Release 8.2 (build 1801) eXtremeDB supports Python versions 2.7, 3.5, 3.6, 3.7, 3.8 on Linux and Windows, as well as versions 2.7, 3.7 and 3.8 on MacOS.

eXtremeDB's Python support consists of a wrapper (Python database API) and the UDF adapter (allowing execution of user defined procedures/functions written in Python from within SQL statements and queries). It is implemented as the Python module exdb which is distributed as a Python wheel that can be installed via the standard means (PIP).

Each eXtremeDB package includes several wheels (one for each supported version of Python). They are located in the package subdirectory target/python/dist.

A wheel with the exdb module can be installed into Python itself as well as into Python's virtual environment created with virtualenv or venv.

In order for the Python module to be able to find and load eXtremeDB libraries, you must set the environment variable MCO_ROOT to the location of eXtremeDB directory before launching the Python process. Note: for eXtremeDB samples written in Python, this environment variable is set automatically.

Python tools for installation of a wheel with exdb module and UDF

PIP

PIP is a standalone utility (pip or pip3 for Python 3).

PIP needs to be installed once (when pip/pip3 utility is absent in the system), here is the detailed description.

Briefly speaking, get-pip.py should be downloaded via

    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

and run with the desired version of Python:

    python get-pip.py

or

    python get-pip.py

 

virtualenv

virtualenv (consists of an utility and a module) needs to be installed once (if absent) via

    pip install virtualenv

or

    pip3 install virtualenv

How to create a Python virtual environment and work with it

A virtual environment is a special directory created with the virtualenv utility (or a Python module with the same name). This directory can be named and located arbitrarily. A virtual environment can be created once and reused after allows creating isolated environments with specific settings and sets of installed Python modules.

Example:

    virtualenv ./pyenv27

will create a virtual environment in the ./pyenv27 directory.

A virtual environment should be activated prior to use.

For Linux and MacOS it can be done as follows

     . ./pyenv27/bin/activate

for Windows

    pyenv27\Scripts\activate.bat

The deactivate command deactivates the current virtual environment.

venv

Starting with Python 3.3, the standard library includes the venv module, which provides a built-in alternative to virtualenv. Unlike virtualenv, venv does not require separate installation—it is available out of the box with standard Python distributions.

To create a virtual environment using venv, run:

    python -m venv myenv

or (depending on your system):

    python3 -m venv myenv

Here, myenv is the name of the directory that will contain the virtual environment. To activate it:

Linux and MacOS:

    source myenv/bin/activate

Windows (Command Prompt):

    myenv\Scripts\activate.bat

Windows (PowerShell):

    myenv\Scripts\Activate.ps1

Once activated, your shell prompt will usually change to show the environment name. Any packages installed via pip will now be placed in this isolated environment, leaving your global Python installation untouched.

To deactivate the environment, simply run:

    deactivate

The venv module is recommended for new projects, especially when using Python 3.3 or newer, as it is officially maintained and requires no external dependencies.

exdb module installation

exdb module can be installed as follows

    pip install ./target/python/dist/exdb_mcobject-0.1.1-cp27-cp27m-linux_x86_64.whl

(for Python 2.7 on Linux x64)

This is applicable both to system Python and to virtual environments.

Note: for system Python on Linux and MacOS, root privileges or privileges for sudo may be required.

eXtremeDB Python wheels are generally named as

exdb_mcobject-0.1.1-cpVV-cpVVm-OS_PLATFORM.whl

where VV corresponds to the version number of Python.

For Linux two wheels are available for Python 2.7 :

exdb_mcobject-0.1.1-cp27-cp27m-linux_x86_64.whl and exdb_mcobject-0.1.1-cp27-cp27mu-linux_x86_64.whl .

The former is used when Python uses encoding UCS2, while the latter is used when Python uses encoding UCS4. Encoding can be discovered as follows:

When built with --enable-unicode=ucs4:

    >>> import sys
    >>> print sys.maxunicode
    1114111

When built with --enable-unicode=ucs2:

    >>> import sys
    >>> print sys.maxunicode
    65535

Note: invocation of pip/pip3/virtualenv utilities is equal to invocation of python for modules pip/virtualenv. For example:

    python -m pip install virtualenv
    python -m virtualenv ./pyenv27
    python -m pip install ./target/python/dist/exdb_mcobject-0.1.1-cp27-cp27m-linux_x86_64.whl

Note:

eXtremeDB's Python wheel should be installed once. After that, the module exdb will become available for use with the Python programming language.