4. Building Python auxiliary libraries

eProsima Fast DDS-Gen can generate the required source files and CMake project to build the Python modules that allow the use of the IDL defined data types within a Fast DDS Python-based application. Each IDL file will result in a new Python module that will contain all the data types defined in the file. The Python binding is generated building the provided solution using SWIG.

Calling eProsima Fast DDS-Gen with the option -python will generate these files. eProsima Fast DDS-Gen will generate a .i file which will be processed by SWIG and a CMake project to call SWIG first generating C++ files (for connecting C++ and Python) and Python files (Python module for your type) and then compiling the C++ sources.

Note

The Python bindings does not support the use of namespaces.

Before calling CMake, the Building process needs several Dependencies to be met.

4.1. Dependencies

4.1.1. SWIG

SWIG is a development tool that allows connecting programs written in C/C++ with a variety of other programming languages, among them Python. SWIG version lower than 4.2 is required to build Fast DDS Python bindings.

Note

More recent SWIG releases are not yet supported. Please, ensure to be using SWIG 4.0.

SWIG can be installed directly from the package manager of the appropriate Linux distribution. For Ubuntu, please run:

sudo apt install swig

Warning

For Ubuntu 24.04, SWIG must be installed using the following command:

sudo apt install swig4.1

4.1.2. Header files and static library for Python

Python static libraries and header files are needed to compile C++ source code generated by SWIG. They can be installed directly from the package manager of the appropriate Linux distribution. For Ubuntu, please run:

sudo apt install libpython3-dev

4.2. Building

Call CMake:

mkdir build
cd build
cmake ..
cmake --build .

This will create the Python files (.py) with the modules (one per each IDL file) that have to be imported within the Python script.

Note

The python bindings does not support using different modules in the same idl file. Split them in different files for expected behavior.