Python

The default way is to replace the pre-installed SQLite library with the one we compiled containing the litesync.


Linux

The Python's sqlite3 module interfaces with the installed libsqlite3.so.0

We can check it using the command bellow:

ldd /usr/lib/python2.7/lib-dynload/_sqlite3.so


We have 3 options to make it work with the modified SQLite library containing litesync:


1. Use the LD_LIBRARY_PATH when opening python

LD_LIBRARY_PATH=/usr/lib python app.py

2. Overwrite the pre-installed library

cd /usr/lib/arm-linux-gnueabihf  (or x86_64-linux-gnu, it depends on the architecture)

ln -sf /usr/lib/libsqlite3.so.0 libsqlite3.so.0

3. Set the rpath in the wrapper library

For this we need patchelf:

git clone https://github.com/NixOS/patchelf

cd patchelf

./bootstrap.sh

./configure

make

sudo make install

To set the rpath in the wrapper library:

patchelf --set-rpath /usr/lib /usr/lib/python2.7/lib-dynload/_sqlite3.so

To check if it was successful:

objdump -p /usr/lib/python2.7/lib-dynload/_sqlite3.so | grep RPATH


Windows

Replace the file sqlite3.dll in the folder \Python\DLLs with the one containing litesync.


Usage

Then we can use the sqlite3 module normally, passing a URI in the place of the filename.

Note that this works even in Python 2.7 because the litesync has the URI enabled by default.

Example code:

import sqlite3

conn = sqlite3.connect('file:data.db?node=secondary&connect=tcp://server:port')