Load a shared library into Python.
This package is basically just a thin wrapper around ctypes and Python for .NET for loading a shared library into Python. However, the primary advantage is that it is possible to communicate with a 32-bit shared library from 64-bit Python.
Tested in Python 2.7, 3.3 - 3.6. The examples provided are currently only supported in Windows, however MSL-LoadLib should work properly with any OS (not tested) that Python for .NET supports (and if you don't care about loading .NET libraries then MSL-LoadLib is a pure-python package so it is OS independent).
If you are loading a 64-bit library into 64-bit Python, or a 32-bit library into 32-bit Python, then you can directly load the library using msl.loadlib.LoadLibrary
.
Using a 64-bit Python interpreter, load the 64-bit C++ library named cpp_lib64. By default, msl.loadlib.LoadLibrary
loads a library using ctypes.CDLL.
>>> import msl.loadlib
>>> msl.loadlib.IS_PYTHON_64BIT
True
>>> cpp = msl.loadlib.LoadLibrary('./cpp_lib64')
>>> cpp
LoadLibrary object at 0x3e9f750; libtype=ctypes.CDLL; path=D:/examples/cpp_lib64.dll
>>> cpp.lib
<CDLL 'D:/examples/cpp_lib64.dll', handle af1e0000 at 0x3e92f90>
Call the cpp_lib64.add
function that calculates the sum of two integers
>>> import ctypes
>>> cpp.lib.add(ctypes.c_int32(1), ctypes.c_int32(2))
3
Inter-process communication is used to access a 32-bit shared library from a module that is running within a 64-bit Python interpreter. The procedure uses a client-server protocol where the client is a subclass of msl.loadlib.Client64
and the server is a subclass of msl.loadlib.Server32
. See the tutorials for examples on how to implement inter-process communication.
The documentation for MSL-LoadLib can be found here.
Install MSL-LoadLib using pip:
$ pip install https://github.com/MSLNZ/msl-loadlib/archive/master.zip
MSL-LoadLib uses pytest for testing the source code and sphinx for creating the documentation.
Run the tests (a coverage report is generated in the htmlcov/index.html file):
$ python setup.py test
Build the documentation, which can be viewed by opening the docs/_build/html/index.html file:
$ python setup.py docs
Automatically create the API documentation from the docstrings in the source code (uses sphinx-apidoc):
$ python setup.py apidoc
NOTE: By default, the docs/_autosummary folder that is created by running theapidoc* command is automatically generated (it will overwrite existing files). As such, it is excluded from the repository (i.e., this folder is specified in the* .gitignore file). If you want to keep the files located in docs/_autosummary you can rename the folder to be, for example, docs/_api and then the changes made to the files in the docs/_api folder will be kept and will be included in the repository.