Giter Club home page Giter Club logo

couchbase-lite-python's Introduction

EXPERIMENTAL Python Bindings For Couchbase Lite

September 2021

This directory contains a Python API binding of Couchbase Lite, an embedded NoSQL document database engine with sync. It consists of Python classes that call glue generated by CFFI, which calls into Couchbase Lite's C API.

Here's a snippet of code to show what the Python API looks like:

from CouchbaseLite.Database import Database, DatabaseConfiguration
from CouchbaseLite.Document import MutableDocument

# Open a database:
db = Database("python_db", DatabaseConfiguration("/tmp"));

# Create a document:
doc = MutableDocument("foo")
doc["greeting"] = "Howdy!"
db.saveDocument(doc)

# Read it back:
readDoc = db.getDocument("foo")
props = readDoc.properties
greeting = props["greeting"]

Disclaimer

This library is NOT SUPPORTED BY COUCHBASE. Even if you are a Couchbase customer, our otherwise awesome support team cannot help you with using this library.

As of September 2021, this library is still incomplete and has been tested only partially and informally, mostly on one platform (macOS). Due to the dynamic nature of Python, there are probably glaring mistakes that won't show up until we get more code coverage.

That said, we would like to maintain and improve this library as time permits. We welcome bug reports, fixes and improvements!

Building

"Some assembly required..."

1. Python and CFFI

You'll need Python 3. Currently we've only tested with 3.9.

Make sure you have the CFFI package:

$ pip3 install cffi

2. Couchbase Lite For C

Next you need the Couchbase Lite For C shared library and headers. You can download them from Couchbase, or build them yourself from the Git repo.

3. Building CBL-Python

Now you can build the Python binding library. If Couchbase Lite has been installed into ``/usr/local`, you can just type:

$ cd couchbase-lite-python
$ ./build.sh

Otherwise, you'll need to tell the script where to find the native headers and library file:

$ cd couchbase-lite-python
$ ./build.sh --include /path/to/include/ --library /path/to/libcblite.dylib

/path/to/include/ must have a subdirectory named cbl containing the CBL headers.

(If this doesn't work, adding the --verbose flag may reveal more information from CFFI.)

4. Try it out

Now try the (rudimentary) tests:

$ test/test.sh

Hopefully this prints a bunch of stuff and exits normally without any exceptions.

You can look at the test code in test/test.py for examples of how to use the API.

The main thing you need to do is add the CouchbaseLite package directory to your Python path, for example by setting the PYTHONPATH environment variable to its parent directory, as the shell script does. Then import the packages CouchbaseLite.Database, CouchbaseLite.Document, etc.

Learning

If you're not already familiar with Couchbase Lite, you'll want to start by reading through its official documentation. Our goal is for the Python API to be compatible with the languages documented there.

couchbase-lite-python's People

Contributors

borrrden avatar snej avatar sspivak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

couchbase-lite-python's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.