velocypack icon indicating copy to clipboard operation
velocypack copied to clipboard

Python bindings

Open thedrow opened this issue 6 years ago • 5 comments

Is there a Python binding to this library? If not, can we add one?

thedrow avatar Jan 24 '18 14:01 thedrow

Not yet, feel free to submit a pull request for it

graetzer avatar Jan 24 '18 14:01 graetzer

I've been tinkering with Python bindings for this library. I'm getting an ImportError due to a missing symbol. This missing symbol also seems to be missing from libvelocypack.a

Here's the ImportError I'm getting:

ImportError: dlopen(/Users/.../Library/Caches/pypoetry/virtualenvs/velocypack-IZ9-pmhB-py3.11/lib/python3.11/site-packages/vpack.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace (__ZNK8arangodb10velocypack9SliceBaseINS0_5SliceES2_E15byteSizeDynamicEPKh)

If I run

nm -g build/libvelocypack.a | grep __ZNK8arangodb10velocypack9SliceBaseINS0_5SliceES2_E15byteSizeDynamicEPKh

I get nothing. Is there something obvious that I'm missing?

If it's useful to you, I can fork and open a PR with what I've got so far.

kfreezen avatar Oct 05 '23 19:10 kfreezen

Unfortunately I don't know much about Python bindings and how to create them. So I can't really tell where this ImportError comes from.

I tried creating a small test program and linking it to libvelocypack.a, in order to see if there are any errors related to missing symbols or linking. I have used the current state of the main branch. Here's my test program (test.cpp):

#include <velocypack/Slice.h>
#include <velocypack/Builder.h>

#include <iostream>

int main() {
  using namespace arangodb::velocypack;

  Builder b;
  b.openObject();
  b.add("foo", Value("bar"));
  b.close();

  std::cout << b.slice().toJson() << ", " << b.slice().byteSize() << "\n";
}

I compiled & linked it with g++ (g++-11.4) via

g++ -std=c++20 -Wall -Iinclude -Lbuild test.cpp -lvelocypack

and executed it with ./a.out. All the steps worked fine for me. I also tried building and linking with clang++-14 and it also worked fine.

So at least for me the generated libvelocypack.a seems to be usable from external programs.

As mentioned before, I am not really aware of how Python bindings work, but do they actually supported using static libraries? Just wondering (random guess) if they may require using a dynamic library instead.

jsteemann avatar Oct 06 '23 08:10 jsteemann

My understanding is limited as well, but the bindings file produced in this case is a .so file. There is an extremely simple case that did work without bringing me this ImportError, but once I started expanding my Cython code, I hit this error. Maybe that's the clue to how I should continue. 🤔

kfreezen avatar Oct 10 '23 22:10 kfreezen

Spent some time hacking around on it this morning and discovered that I have to define everything just so-so in Cython, or we are going to have a bad time. So much for remaining ignorant of advanced C++ templating in Cython.

kfreezen avatar Nov 10 '23 18:11 kfreezen