Calling routines in Windows DLLs from Python scripts running under Linux, MacOS or BSD
Project description
zugbruecke
Calling routines in Windows DLLs from Python scripts running under Linux, MacOS or BSD
/ˈt͡suːkˌbʁʏkə/ (German, noun, feminine: drawbridge)
Synopsis
zugbruecke is an EXPERIMENTAL Python package (currently in development status 3/alpha). It allows to call routines in Windows DLLs from Python code running on Unices / Unix-like systems such as Linux, MacOS or BSD. zugbruecke
is designed as a drop-in replacement for Python's standard library's ctypes module. zugbruecke
is built on top of Wine. A stand-alone Windows Python interpreter launched in the background is used to execute the called DLL routines. Communication between the Unix-side and the Windows/Wine-side is based on Python's build-in multiprocessing connection capability. zugbruecke
has (limited) support for pointers, struct types and call-back functions. zugbruecke
comes with extensive logging features allowing to debug problems associated with both itself and with Wine. zugbruecke
is written using Python 3 syntax and primarily targets the CPython implementation of Python.
About Wine (from winehq.org): Wine (originally an acronym for "Wine Is Not an Emulator") is a compatibility layer capable of running Windows applications on several POSIX-compliant operating systems, such as Linux, MacOS and BSD. Instead of simulating internal Windows logic like a virtual machine or emulator, Wine translates Windows API calls into POSIX calls on-the-fly, eliminating the performance and memory penalties of other methods and allowing you to cleanly integrate Windows applications into your desktop.
This project is NEITHER associated NOR affiliated in any way or form with the Wine project.
Prerequisites
type | prerequisite | version |
---|---|---|
user | CPython | 3.x (tested with 3.{7,8,9,10,11}) |
user | Wine | >= 6.x (tested with regular & staging) - expected to be in the user's PATH |
developer | mingw cross-compiler | For building DLLs against which examples and tests can be run. Latest stable release. |
Installation
branch | status | installation | documentation |
---|---|---|---|
master (release) | pip install zugbruecke |
||
develop | pip install git+https://github.com/pleiszenburg/zugbruecke.git@develop |
After installing the package with pip
, you may choose to manually initialize the Wine Python environment by running wenv init
. If you choose not to do this, zugbruecke
will take care of it during its first use.
Example
Start an interactive Python session on your favorite Unix(-like) operating system and try the following:
import zugbruecke.ctypes as ctypes
dll_pow = ctypes.cdll.msvcrt.pow
dll_pow.argtypes = (ctypes.c_double, ctypes.c_double)
dll_pow.restype = ctypes.c_double
print(f'You should expect "1024.0" to show up here: "{dll_pow(2.0, 10.0):.1f}".')
You have just witnessed msvcrt.dll
, Microsoft's C standard library (or Wine's implementation of it), in action on Unix.
Interested in more?
- Check the Getting Started section in
zugbruecke
's documentation, - Read ctypes' documentation,
- Beyond
ctypes
syntax, learn about memory synchronization with thememsync
routine attribute (or) - Have a look at
zugbruecke
's test suite showcasing its entire range of capabilities.
A lot of code, which was written with ctypes
' cdll
, windll
or oledll
in mind and which runs under Windows, should run just fine with zugbruecke
on Unix (assuming it does not use Windows features not supported by Wine). For more complex calls, memory synchronization is potentially necessary.
Speed
zugbruecke
performs reasonably well given its complexity with around 0.15 ms overhead per simple call on average on modern hardware. For significantly more complex calls, the overhead can go into several milliseconds. zugbruecke
is not (yet) optimized for speed. Check the latest benchmarks for more details.
Security
zugbruecke
is notoriously insecure. Never, ever, run it with root / super users privileges! Do not use it where security matters! For details, check the section on security in the documentation.
Need help?
See section on Getting Help on zugbruecke
's documentation.
Bugs & Issues
See section on Bugs and Issues on zugbruecke
's documentation.
Miscellaneous
- Full project documentation
- Authors
- Change log (current) (changes in development branch since last release)
- Change log (past) (release history)
- Contributing (Contributions are highly welcomed!)
- FAQ
- License (LGPL v2.1)
- Long-term ideas
- Missing features (for full ctypes compatibility)
- Upstream issues (relevant bugs in dependencies)
For production environments
DO NOT run this code (as-is) in production environments unless you feel that you really know what you are doing (or unless you are absolutely desperate)! Being experimental in nature and of alpha quality, it is prone to fail in a number of unpredictable ways, some of which might not be obvious or might not even show any (intermediately) recognizable symptoms at all! You might end up with plain wrong, nonsensical results without noticing it! Verify and cross-check your results!
zugbruecke
is using semantic versioning. Breaking changes are indicated by increasing the second version number, the minor version. Going for example from 0.0.x to 0.1.y or going from 0.1.x to 0.2.y therefore indicates a breaking change. For as long as zugbruecke
has development status "alpha", please expect more breaking changes to come.
If you are relying on zugbruecke
in one way or another, please consider monitoring the project: its repository on Github, its mailing list and its chatroom.
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 Distribution
File details
Details for the file zugbruecke-0.2.1.tar.gz
.
File metadata
- Download URL: zugbruecke-0.2.1.tar.gz
- Upload date:
- Size: 154.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dc0d779c233076cd42d1ca5bfd358e0798def7e364c3638cff936ee733c2e77 |
|
MD5 | 290313c8868724ec601328f259fa6f1d |
|
BLAKE2b-256 | ed511e294025abbc9fedbfbaa00e996593b9ae72c5b1754c105277181f865ced |
File details
Details for the file zugbruecke-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: zugbruecke-0.2.1-py3-none-any.whl
- Upload date:
- Size: 86.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb18f8db9ba0976973fffc6cb889f5f4382d99b5ccb6d149b613090e6b6b78be |
|
MD5 | 38fc80deaf0118e4959d0e71ad07ad7e |
|
BLAKE2b-256 | a3caf93119a24cf242d9ffe0dbc3b8590556791254d76997e7aa8ee95e089719 |