-
-
Notifications
You must be signed in to change notification settings - Fork 111
Python binding #147
Comments
PR is welcome! |
Please use the new C++ API as a basis/template. |
I started work using pybind11. |
But, please, take look to the morern С++ API. |
I'm doing that. |
I need some help with writing the Type Caster from mdbx::slice to byte[] and other Python types. The idea is to convert to Python types early, because Python provides native methods for slicing arrays and anything that mdbx::slice provides. At the moment, writing the type caster still goes over my head. I uploaded the code in my repo in an own branch. Any help with writing it is greatly appreciated! EDIT: |
As a traditional key-value store libmdbx handles a keys and values in terms of byte sequences, which in some cases treated as a In most cases, simple byte-by-byte copying of field values from stored data structures is used for serialization. This is not a problem for C / C++, where data is very often handled in this way, and therefore Python has a built-in universal serialization, and it is definitely worth using. However, this is sure not enough, since we could only write / read data from the python environment, and in all other cases it will be extremely difficult. |
Alright, I got that problem fixed. |
I made the design decision to provide a pythonized API in the main package and the underlying libmdbx API using pybind11 so internals are accessible to users wishing to use those instead. It also makes it much easier to implement the pythonized API because I can maintain large parts of the code in Python instead of in C++. |
I had to do it using the C API and that worked thus far. Here's the code: https://github.com/Thermi/libmdbx/tree/python-bindings. The directory will change at some point. This is done so I can locally distinguish the code easily between the different implementation tries. |
Thanks to @Thermi, this feature is 80% done. I will continue review the code (so the TODO-list will be updated) and will try to find some time to work on these TODO items. |
I have some comments on the items in the TODO list.
It makes it easy to deal with and keep module specific files seperate from, like example, your TODO list. :P
Yes. It follows the Python convention to use CamelCase for class names and snake case for function names. (PEP 8,
I think that's kind of a premium item in that the libmdbx API is supposed to be stable and thus also the documentation should be fine once manually checked once.
I did that because that way it's consistent with what's in GNUmakefile
It's broken right now when built from amalgated sources?
Shouldn't matter much because only the DLL is relevant for the bindings, and it evidently has to be compatible with python. That's then a python ctypes problem, not an mdbx problem.
Same as for 4. Python problem.
The existing python unittest should be OS agnostic, so execution should work OOTB. Do we have CI integration with Windows and bsd yet?
Shouldn't matter unless the DLL and python path are not adjusted (because then the DLL is in a different architecture from the python binaries)
Pure python topic again, because Python itself should be OS agnostic on that layer.
What would be the advantage? It should be easy for devs to write code to catch the different error codes, but if we introduce OS specific error codes that might not be defined on all platforms, the devs will need to check for their existence/declaration using hasattr() and/or using try-catch blocks for the code dealing with them. That's not really useful. The posix error codes won't change ever, so them being statically defined right now should be fine,. Adding the NT error codes as alternative values for their posix correspondents should be feasible.
That will just require some more distro specific code dealing with yum and the package names there |
Using
In these and many other cases we should verify the building script/process itself, not the functionality of library nor bindings.
There two major points:
CentOS6 is actually a nickname (or a free pack) of RHEL6, the EOL of which was scheduled to 2025 (and may be prolonged). |
About CentOS 6: It's EOL since November 30th https://wiki.centos.org/About/Product |
For clarification: I mean we should provide support for RHEL6, but may use CentOS6 for this. |
Just in case, there is a simple, generally accepted solution for an system-aware error codes:
|
I just found the errno module. It exports all errors. I'll make a PR for using it and change all the currently hardcoded OS specific errors. |
OK, but note that the above solution avoids copy&paste some boilerplate "magic". |
The above solution is not maintainable because ctypes has no C code parser. If that was the case, I wouldn't have needed to declare all the functions. :P |
See #213 for the declaration using errno instead of explicite values |
No description provided.
The text was updated successfully, but these errors were encountered: