Skip to main content

Load a library (and access a 32-bit library from 64-bit Python)

Project description

MSL-LoadLib

CI Status Docs Status PyPI - Version PyPI - Python Versions

This package loads a library in Python. It is basically just a thin wrapper around ctypes (for libraries that use the __cdecl or __stdcall calling convention), Python.NET (for libraries that use Microsoft .NET, CLR), Py4J (for Java .jar or .class files) and comtypes (for libraries that use the Component Object Model or ActiveX).

However, the primary advantage is that it is possible to communicate with a 32-bit library from 64-bit Python.

msl-loadlib is a pure-python package, but Python.NET depends on the .NET Common Language Runtime (CLR) on Windows and Mono Runtime on Linux/macOS, and Py4J depends on having a Java Virtual Machine installed.

Install

msl-loadlib is available for installation via the Python Package Index

pip install msl-loadlib

Optional dependencies:

To set up your environment on Linux, please follow the instructions on the prerequisites section of the documentation.

Examples

If you are loading a 64-bit library in 64-bit Python (or a 32-bit library in 32-bit Python), then you can directly load the library using LoadLibrary.

The following examples load a 64-bit library in a 64-bit Python interpreter. If you are using a 32-bit Python interpreter replace 64 with 32 in the filename.

Import the LoadLibrary class and the directory where the example libraries are located

>>> from msl.loadlib import LoadLibrary
>>> from msl.examples.loadlib import EXAMPLES_DIR

If the file extension is not included then a default extension, .dll (Windows), .so (Linux) or .dylib (macOS), is used.

Load the example C++ library and call the add function

>>> cpp = LoadLibrary(EXAMPLES_DIR / "cpp_lib64")
>>> cpp.lib.add(1, 2)
3

Load the example FORTRAN library and call the factorial function

>>> fortran = LoadLibrary(EXAMPLES_DIR / "fortran_lib64")

With a FORTRAN library you must pass values by reference using ctypes, and, since the returned value is not of type c_int we must configure ctypes for a value of type c_double to be returned

>>> from ctypes import byref, c_int, c_double
>>> fortran.lib.factorial.restype = c_double
>>> fortran.lib.factorial(byref(c_int(37)))
1.3763753091226343e+43

Load the example Java byte code and call the cos function

>>> java = LoadLibrary(EXAMPLES_DIR / "Trig.class")
>>> java.lib.Trig.cos(1.234)
0.33046510807172985

Python interacts with the Java Virtual Machine via a local network socket and therefore the connection must be closed when you are done using the Java library

>>> java.gateway.shutdown()

Load the example .NET library and call the reverse_string function, we must specify that the library type is a .NET library by including the "net" argument

>>> net = LoadLibrary(EXAMPLES_DIR / "dotnet_lib64.dll", "net")
>>> net.lib.StringManipulation().reverse_string("abcdefghijklmnopqrstuvwxyz")
'zyxwvutsrqponmlkjihgfedcba'

To load a Component Object Model (COM) library pass in the library's Program ID. NOTE: This example will only work on Windows.

Here we load the FileSystemObject library and include the "com" argument to indicate that it is a COM library.

>>> com = LoadLibrary("Scripting.FileSystemObject", "com")

We then use the library to create, edit and close a text file

>>> f = com.lib.CreateTextFile("a_new_file.txt")
>>> f.WriteLine("This is a test")
0
>>> f.Close()
0

Inter-process communication is used to access a 32-bit 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 examples for examples on how to implement Inter-process communication.

Documentation

The documentation for msl-loadlib can be found here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msl_loadlib-1.1.0.tar.gz (45.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

msl_loadlib-1.1.0-py3-none-win_amd64.whl (15.3 MB view details)

Uploaded Python 3Windows x86-64

msl_loadlib-1.1.0-py3-none-win32.whl (15.3 MB view details)

Uploaded Python 3Windows x86

msl_loadlib-1.1.0-py3-none-musllinux_1_1_x86_64.whl (77.0 kB view details)

Uploaded Python 3musllinux: musl 1.1+ x86-64

msl_loadlib-1.1.0-py3-none-musllinux_1_1_aarch64.whl (77.0 kB view details)

Uploaded Python 3musllinux: musl 1.1+ ARM64

msl_loadlib-1.1.0-py3-none-manylinux2014_armv7l.manylinux_2_17_armv7l.whl (77.1 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

msl_loadlib-1.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (90.6 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

msl_loadlib-1.1.0-py3-none-manylinux1_x86_64.whl (29.8 MB view details)

Uploaded Python 3

msl_loadlib-1.1.0-py3-none-manylinux1_i686.whl (29.8 MB view details)

Uploaded Python 3

msl_loadlib-1.1.0-py3-none-macosx_11_0_arm64.whl (82.4 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

msl_loadlib-1.1.0-py3-none-macosx_10_6_x86_64.whl (273.9 kB view details)

Uploaded Python 3macOS 10.6+ x86-64

File details

Details for the file msl_loadlib-1.1.0.tar.gz.

File metadata

  • Download URL: msl_loadlib-1.1.0.tar.gz
  • Upload date:
  • Size: 45.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for msl_loadlib-1.1.0.tar.gz
Algorithm Hash digest
SHA256 bf3f2afc7feb799c1230ebc6dae489a19e3142a21ec7e65be1c71426cba6174d
MD5 3f4c5c6e4e6b9b90961f86b23bca57a3
BLAKE2b-256 a1b53bab891ab3f4fe139bbb9644bd29f8e166b014ed5ac32a347c35d5f5d0c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0.tar.gz:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: msl_loadlib-1.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 15.3 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 122d4c7439260f5aa2b014ff6dfedf1eebedf1d4e8e40237cd383fefcd5e1e05
MD5 27db136a4bb562cf0250a43e5de62f90
BLAKE2b-256 b1c297ab904f648cfe418a293c93f0cb9ff6942e6d9cb63d35710b62005cd576

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-win_amd64.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-win32.whl.

File metadata

  • Download URL: msl_loadlib-1.1.0-py3-none-win32.whl
  • Upload date:
  • Size: 15.3 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 1646032f560ff91e1b0b76c53ec3b2cebad784b320a6beffa47d67d2640dfb0d
MD5 5c603bb61c1e24b8d7fedefeffebaa13
BLAKE2b-256 6f595fdd390ef4174e8d983bdecf7296d6ec9825c108df8b07a7fe58ac64c911

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-win32.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 366416fd84d4065ab96e88ae3c9bb1125592eed9f7da30166507df289d6ffbae
MD5 7600592a3b090d084ad3b06012cc255e
BLAKE2b-256 c294c840c77384e41abc31007c99a9e9ae8b31af2a00957042510b9ac9e3df96

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-musllinux_1_1_x86_64.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 957fc44889454201559c56b44490f4d4d539fa6dd0ef99cd29bf01ef77e6c407
MD5 fe572658c51ccaf79035e65a13715840
BLAKE2b-256 884cf10088e0970e2f1043bfcf42be2e58f48608e3da7a4823fce45cb5ae7874

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-musllinux_1_1_aarch64.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-manylinux2014_armv7l.manylinux_2_17_armv7l.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-manylinux2014_armv7l.manylinux_2_17_armv7l.whl
Algorithm Hash digest
SHA256 7d3049f902d95e38a475532031c42c512a91d7a397d11c6c5001c7b9956b925b
MD5 2c8900ae5379d3aa3013ea16089f064f
BLAKE2b-256 370ec9a06da220900a0e26a2988acca9db9e153aff3bf999e3a5d9cd7fa8f95c

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-manylinux2014_armv7l.manylinux_2_17_armv7l.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 86413d568ed43f97688f7bd59a1fe70b44061588ce318398cf01e0d410d178fd
MD5 095f6bb262f96f2483ade7fe93bcffd7
BLAKE2b-256 da8431b3f96f26c00b8b3b7629817fdd3163b1aadb4688bf2298156e826c6853

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c058194e86b463023be24d749e7773e68b5e724f224081d195a096fc59659d6e
MD5 1177dee5090be908bfe0261b74e029f5
BLAKE2b-256 f385e81df8bf6aadc59940584273ec9b5076fc37c8bd894d2c4ac90b5ff3c564

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-manylinux1_x86_64.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-manylinux1_i686.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-manylinux1_i686.whl
Algorithm Hash digest
SHA256 6c4042ac1706157a14ff0ba85771fb43cc8c21f7eac6ff3b2f291b1b5a921445
MD5 b930deeb6a0b01e2710354fc9cebf101
BLAKE2b-256 ba188d750e82fd6788014c03e5864c95e8cf54ff3b4e89e2cc9b5b46f5837d14

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-manylinux1_i686.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d87b095b2046b11de119968cb63679d6396ede76ceeff469b31556b80f0afd6
MD5 ee06e4903bfb5101a8ee61226324d516
BLAKE2b-256 c71da718e93cd197b4158bc949ca904190e0699a72ed06d380bb4314534a6a56

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-macosx_11_0_arm64.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msl_loadlib-1.1.0-py3-none-macosx_10_6_x86_64.whl.

File metadata

File hashes

Hashes for msl_loadlib-1.1.0-py3-none-macosx_10_6_x86_64.whl
Algorithm Hash digest
SHA256 f04f5a17101ea6487a4b98b856566b64404424c9979d21c78d0c32e8ab023151
MD5 09acfb0032cdb1b56b53073502619b8a
BLAKE2b-256 539c53d93c6fe407a1d3059b729c9ce9a3d9631625c9c687b0827788a2dea6c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for msl_loadlib-1.1.0-py3-none-macosx_10_6_x86_64.whl:

Publisher: pypi-publish.yml on MSLNZ/msl-loadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page