Skip to main content

GitHub

dlsym – A cross-platform symbol locator

dlsym allows Python C extension modules to use symbols present in already loaded C libraries, without having to actually link these libraries. As a simple example, using pybind11:

double (* my_atan2)(double, double);
my_atan2 = reinterpret_cast<decltype(my_atan2)>(
    py::module::import("dlsym").attr("dlsym")("atan2").cast<uintptr_t>());

Obviously, linking against libm to get access to atan2 is not particularly difficult, but this approach also allows one to use e.g. numpy-provided BLAS/LAPACK functions which are available after importing numpy (regardless of whether the underlying implementation is OpenBLAS, MKL, or something else), fftw functions after importing pyfftw, or Tcl/Tk functions after importing tkinter (see tests for examples).

The main goal here is to simplify the compilation of such extension modules on machines where the C libraries may not be present by default, but where they can be “requested” by declaring an install_requires on the corresponding Python package.

Note that the path to the shared library is not actually passed as an argument to dlsym (unlike the POSIX dlsym(3). This is because the symbol search on Windows has to enumerate all loaded modules anyways, as one cannot just pass a module that transitively loads the symbol. On POSIX, we thus follow the same strategy for consistency (but enumerating all extension modules in sys.modules instead).

The path of the library where the symbol is actually defined is logged at the INFO level.

I learned this trick from Matthew Brett’s original implementation for loading tkinter into matplotlib.

Metadata

Release files for dlsym 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dlsym 0.1
File Size Uploaded Provenance Actions
dlsym-0.1.tar.gz 6.9 kB Without provenance Details for dlsym-0.1.tar.gz

Release files / dlsym-0.1.tar.gz

Download URL dlsym-0.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
48a22c6a2318321b414130e86554c96728fc40a9bbd2bb9a6561e3a0d9a494e8
BLAKE2b-256 checksum
How to use checksums
cb4e32be84f272ab2e58c8fd12d0cc80bc329fb39e304144a5a7af51da2f26fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Security for dlsym 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page