Load a shared library (and access a 32-bit library from 64-bit Python)
Project description
Purpose
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 and Linux, however MSL-LoadLib should work properly with any OS (not tested) that Python for .NET supports (and if you do not need to load .NET libraries then MSL-LoadLib is a pure-python package so it is OS independent).
Example
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.
>>> from msl.loadlib import LoadLibrary
>>> cpp = LoadLibrary('./cpp_lib64')
>>> cpp
LoadLibrary object at 0x3e9f750; libtype=CDLL; path=D:/cpp_lib64.dll
>>> cpp.lib
<CDLL 'D:\cpp_lib64.dll', handle af1e0000 at 0x3e92f90>
Call the cpp_lib64.add function that calculates the sum of two integers
>>> cpp.lib.add(1, 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.
Documentation
The documentation for MSL-LoadLib can be found here.
Install
To install MSL-LoadLib run:
pip install msl-loadlib
Alternatively, using the MSL Package Manager run:
msl install loadlib
To install the dependencies on Linux, please follow the instructions on the prerequisites section of the documentation.
Developers Guide
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 the apidoc 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file msl-loadlib-0.3.2.tar.gz
.
File metadata
- Download URL: msl-loadlib-0.3.2.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe01484642f4b47afb344c30637101542a30282f03f9032d15f2caaf92296bc9 |
|
MD5 | c5333c92767a24547eb4f5c37f41491f |
|
BLAKE2b-256 | b718ea3639e47a0c18cfbd0c0f243911060953a2060e83b5a1e9f603c903d96b |
File details
Details for the file msl_loadlib-0.3.2-py2.py3-none-win_amd64.whl
.
File metadata
- Download URL: msl_loadlib-0.3.2-py2.py3-none-win_amd64.whl
- Upload date:
- Size: 8.5 MB
- Tags: Python 2, Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b4307eab2ffa78481116d3989063f25d7b16208b7ee38baaca634da58eb73d5 |
|
MD5 | 5234f22dc30a26102b3fa2db937acb22 |
|
BLAKE2b-256 | 588c42aa8f97f2efe366cccb4fc0451ef63768a5dba3896d565e4bba654c80f7 |
File details
Details for the file msl_loadlib-0.3.2-py2.py3-none-manylinux1_x86_64.whl
.
File metadata
- Download URL: msl_loadlib-0.3.2-py2.py3-none-manylinux1_x86_64.whl
- Upload date:
- Size: 11.3 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a6c897e37fd054c1cfe2af4e7396cb5ba80c070c5b597f0aa83693dbb739ded |
|
MD5 | b0f8bbb7332a7e5c5064f256e70eadb3 |
|
BLAKE2b-256 | 14862b1311f5e049809cb0a65434f20b87c31c480f7b7c8dfdfb37a10ff293a6 |