|
1 | 1 | # Libloader |
2 | 2 |
|
3 | | -Libloader provides a way to quickly and easily load shared libraries on macOS, Windows and Linux. |
| 3 | +Libloader is a cross-platform Python library that simplifies loading shared libraries on macOS, Windows, and Linux. It handles platform-specific differences automatically, making your code more portable. |
4 | 4 |
|
5 | | -It also provides a COM module (libloader.com), making it easier to load COM DLLs on Windows. |
| 5 | +It also provides a COM module (`libloader.com`), making it easier to load COM DLLs on Windows. |
6 | 6 |
|
7 | | -## Functions. |
| 7 | +## Installation |
8 | 8 |
|
9 | | -### com |
| 9 | +```bash |
| 10 | +pip install libloader |
| 11 | +``` |
10 | 12 |
|
11 | | -* prepare_gencache(): Prepare the gencache for COM. Not mandatory to be called by you, because load_com() calls it. |
12 | | -* load_com(*names): Let's you load a COM object. If you pass more than one, if the first fails, it will try the next one, until one works, or it runs out of objects. |
| 13 | +## Usage |
| 14 | + |
| 15 | +### Loading Shared Libraries |
| 16 | + |
| 17 | +```python |
| 18 | +from libloader import load_library |
| 19 | + |
| 20 | +# Load a library with default paths |
| 21 | +my_lib = load_library("mylibrary") |
| 22 | + |
| 23 | +# Load a library with custom paths for 32-bit and 64-bit versions |
| 24 | +my_lib = load_library("mylibrary", x86_path="./lib/x86", x64_path="./lib/x64") |
| 25 | + |
| 26 | +# Call a function from the library |
| 27 | +result = my_lib.some_function(arg1, arg2) |
| 28 | +``` |
| 29 | + |
| 30 | +### Working with COM Objects (Windows) |
| 31 | + |
| 32 | +```python |
| 33 | +from libloader.com import load_com |
| 34 | + |
| 35 | +# Load a COM object |
| 36 | +excel = load_com("Excel.Application") |
| 37 | + |
| 38 | +# Try multiple COM objects until one succeeds |
| 39 | +speech = load_com("SAPI.SpVoice", "SpeechLib.SpVoice") |
| 40 | +``` |
| 41 | + |
| 42 | +## API Reference |
13 | 43 |
|
14 | 44 | ### libloader |
15 | 45 |
|
16 | | -* load_library(library, x86_path=".", x64_path=".", *args, **kwargs): Load a library with the given name. |
17 | | -* _do_load(file, *args, **kwargs): Attempts to actually load the library. Used by load_library, although you can call it yourself. |
18 | | -* find_library_path(libname, x86_path=".", x64_path="."): Finds the path of the given library. |
19 | | -* get_functype(): Returns the ctypes functype of the given platform. |
20 | | -* get_library_extension(): Get the extension of the library for your current platform. |
| 46 | +* `load_library(library, x86_path=".", x64_path=".", *args, **kwargs)`: Load a library with the given name. |
| 47 | +* `find_library_path(libname, x86_path=".", x64_path=".")`: Finds the path of the given library. |
| 48 | +* `get_functype()`: Returns the ctypes functype for the current platform. |
| 49 | +* `get_library_extension()`: Get the extension of the library for your current platform. |
| 50 | +* `_do_load(file, *args, **kwargs)`: Attempts to actually load the library. Used internally by load_library. |
| 51 | + |
| 52 | +### libloader.com |
| 53 | + |
| 54 | +* `load_com(*names)`: Load a COM object. If you pass multiple names, it will try each one until one works. |
| 55 | +* `prepare_gencache()`: Prepare the gencache for COM. Called automatically by load_com(). |
| 56 | + |
| 57 | +## Platform Support |
| 58 | + |
| 59 | +Libloader automatically handles the differences between platforms: |
| 60 | + |
| 61 | +* Windows: `.dll` files |
| 62 | +* macOS: `.dylib` files |
| 63 | +* Linux: `.so` files |
| 64 | + |
| 65 | +## License |
| 66 | + |
| 67 | +See the LICENSE file for details. |
0 commit comments