I am looking at using the Windows CryptoAPI from Python, but I can't find any existing modules for it - the win32crypt module that comes as part of the win32all suite only exposes a couple of high level functions that are of no use to me.
Are there any existing modules that wrap the CryptoAPI? Searching PyPi has come up with zip. Failing that example code on calling the API from ctypes, cython etc would be useful.
This :
How can I use a DLL file from Python?
+ Getting the addresses of the functions you need from Crypt32.dll should work.
Related
I want to write golang bindings for an existing (third party) Python module.
The purpose is that I want to use the API that the Python module provides in Golang.
I already found golang bindings for Python's C API (go-python3 for py3 and go-python for py2), but I still haven't figured out how to translate a relatively complex Python module into Golang (i.e. how to deal with type safety in go for unsafe inputs and returns in python, etc).
What would be a good approach? Are there any pre-existing tools in that space? Are there any good examples for Golang bindings for Python code? (I couldn't find many tbh).
I want to use the API that the Python module provides in Golang.
Calling Python from Go is detailed recently in "Python and Go : Part I - gRPC" by Miki Tebeka.
You can see an example in ardanlabs/python-go/grpc
But, as shown in their next two articles, you can also:
compiled Go code to a shared library and used it from the Python interactive shell.
use a Python module that hides the low level details of working with a shared library and then package this code as a Python package.
Full example: ardanlabs/python-go/pyext.
I'm writing some sort of Python C extension. It uses my own *.so library and headers from another project (let's say they're in /usr/local/lib/otherproject.so and /usr/local/include/otherproject.h).
I don't know which strategy to follow. I came up with two:
As a pure Python extension
Write a Python C extension just as described in the official docs. The problem here is that I don't know how to link with my own library and headers; to compile, I write a setup.py file and run python3.4 setup.py build. I don't know if I can include some option to the former command, or if I can write something in setup.py to include my headers and binaries (if so, I will also have to worry about making this distributable?).
With ctypes
Write a C library (with my other project's build system). Include Python by passing '/usr/include/python2.7' to find headers and the python2.7 binary. Then use ctypes to wrap around that library and get the functions, types, objects, etc. The inconvenience here is that I need to manually wrap around every single function/type/variable from ctypes; I don't think I can use PyModule_AddObject since I'm not creating the module in C but in the Python wrapper (with ctypes).
Also, I tried the second approach, but I could not successfully get my custom PyTypeObject from ctypes. If the second approach sounds good to any more expert brain here on SO, I would post the code to get any help =).
The second approach also yields problems with distribution. And if you create a Python object in C you should do it in the context of a module. For scenarios where distribution is problematic, you could link this module statically instead.
For your issue with linking you'll find more information about Library options in the documentation. Since your library resides in a directory which should be in the standard library search path, you'd only need to define your library with the libraries option of the Extension class:
mymodule_ext = Extension('mymodule', ['mymodule.c'], libraries=['otherproject'])
If you're not using the standard lib* prefix you'd need to use libraries=[':otherproject.so'] instead.
I'm writing a Python-based [web] application that needs to be able to read and write EXIF data.
libexif seems to have all the right ingredients, but I can't work out how (or if) I could access it access it by using Python's ctypes library? I'm new to C, suppose I need see a .so for this to work?
You need to be running on an os that you can obtain the required library, to download the .h files, (usually the -dev package gives you these).
Then you need to work your way through the ctypes tutorial found here which explains all the steps you need to take.
Is there a python module that has the functionality for computing rdiff signatures and delta differencing?
I need to perform these operations on a cross-platform application so I'll need something that will bundle into py2exe, py2app etc.
I've done a bunch of searching but I can't seem to get anything working. Pysync, rdiff-backup, librsync all come up but I've not been able to get anything working inside of python.
rdiff-backup is written in Python. It appears to be using librsync under the covers and has a Python wrapper for it (look for _librsyncmodule.c in the source tree).
The following page may help to figure out how to build librsync on OS X and Windows: link.
Is there a documentation for Python 'gnomekeyring' lib somewhere in the Web?
There is the reference for the C library which the Python package uses. Most function names are identical (except for the "gnome_keyring_" prefix). The Bending Gnome Keyring with Python blog series should give you a good start as well.
And as the keyring package was already mentioned: If I remember correctly, that package supports gnome-keyring as a backend, so you can look at its source code to find out how to use gnome-keyring.
Apparently not. But this one is documented, maybe that's an option?
http://pypi.python.org/pypi/keyring
If not, maybe you can figure out how to use gnomekeyring from reading the source of keyring. :)