extending and embedding python ctypes the ctypes module provides python with access to functions defined in dlls and shared libraries although you need to know some details about the underlying library (namescalling argumentstypesand so on)you can use ctypes to access code without having to write extension wrapper code or compile anything with compiler ctypes is sizable library module with lot of advanced functionality herewe cover the essential parts of it that are needed to get going loading shared libraries the following classes are used to load shared library and return an instance representing its contentscdll(name [mode [handle [use_errno [use_last_error]]]] class representing standard shared library name is the name of the library such as 'libc so or 'msvcrt dllmode provides flags that determine how the library is loaded and are passed to the underlying dlopen(function on unix it can be set to the bitwise-or of rtld_localrtld_globalor rtld_default (the defaulton windowsmode is ignored handle specifies handle to an already loaded library (if availableby defaultit is none use_errno is boolean flag that adds an extra layer of safety around the handling of the errno variable in the loaded library this layer saves thread-local copy of errno prior to calling any foreign function and restores the value afterwards by defaultuse_errno is false use_last_error is boolean flag that enables pair of functions get_last_error(and set_last_error(that can be used to manipulate the system error code these are more commonly used on windows by defaultuse_last_error is false windll(name [mode [handle [use_errno [use_last_error]]]]the same as cdll(except that the functions in the library are assumed to follow the windows stdcall calling conventions (windowsthe following utility function can be used to locate shared libraries on the system and construct name suitable for use as the name parameter in the previous classes it is defined in the ctypes util submodulefind_library(namedefined in ctypes util returns path name corresponding to the library name name is library name without any file suffix such as 'libc''libm'and so on the string returned by the function is full path name such as '/usr/lib/libc so the behavior of this function is highly system-dependent and depends on the underlying configuration of shared libraries and environment (for examplethe setting of ld_library_path and other parametersreturns none if the library can' be located foreign functions the shared library instances created by the cdll(class operates as proxy to the underlying library to access library contentsyou just use attribute lookup (the operatorfor examplef lib fl ff