GithubHelp home page GithubHelp logo

isabella232 / faunadb-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fauna/faunadb-python

0.0 0.0 0.0 442 KB

Python driver for FaunaDB

Home Page: https://fauna.com

License: Other

Python 99.23% Makefile 0.77%

faunadb-python's Introduction

FaunaDB Python

https://img.shields.io/codecov/c/github/fauna/faunadb-python/master.svg?maxAge=21600 https://img.shields.io/pypi/v/faunadb.svg?maxAge=21600 https://img.shields.io/badge/license-MPL_2.0-blue.svg?maxAge=2592000

Python driver for FaunaDB.

Installation

$ pip install faunadb

Compatibility

The following versions of Python are supported:

  • Python 2.7
  • Python 3.3
  • Python 3.4
  • Python 3.5
  • Python 3.6
  • Python 3.7
  • Python 3.8

Documentation

Driver documentation is available at https://faunadb.readthedocs.org/en/latest/.

See the FaunaDB Documentation for a complete API reference, or look in tests for more examples.

Basic Usage

from faunadb import query as q
from faunadb.objects import Ref
from faunadb.client import FaunaClient

client = FaunaClient(secret="your-secret-here")

indexes = client.query(q.paginate(q.indexes()))

print(indexes)

Document Streaming

Fauna supports document streaming, where changes to a streamed document are pushed to all clients subscribing to that document.

The following section provides an example for managing a document stream.

The streaming API is blocking by default, the choice and mechanism for handling concurrent streams is left to the application developer:

from faunadb import query as q
from faunadb.objects import Ref
from faunadb.client import FaunaClient

client = FaunaClient(secret="your-secret-here")

coll = client.query(q.create_collection({"name":"sc"}))
doc  = client.query(q.create(coll["ref"], {"data":{"x": 0}}))

stream = None
def on_start(event):
    print("started stream at %s"%(event.txn))
    client.query(q.update(doc["ref"], {"data": {"x": "updated"}}))

def on_version(event):
    print("on_version event at %s"%(event.txn))
    print("    event: %s"%(event.event))
    stream.close()

def on_error(event):
    print("Received error event %s"%(event))
options = {"fields": ["document", "diff"]}
stream = client.stream(doc["ref"], options, on_start, on_version, on_error)
stream.start()

Building it yourself

Setup

$ virtualenv venv
$ source venv/bin/activate
$ pip install .

Testing

To run the tests you must have a FaunaDB database available. Then set the environment variable FAUNA_ROOT_KEY to your database's root key. If you use FaunaDB cloud, this is the password you log in with.

Tip: Setting the FAUNA_QUERY_TIMEOUT_MS environment variable will set a timeout in milliseconds for all queries.

Then run make test. To test a single test, use e.g. python -m unittest tests.test_client.ClientTest.test_ping.

Tests can also be run via a Docker container with FAUNA_ROOT_KEY="your-cloud-secret" make docker-test (an alternate Alpine-based Python image can be provided via RUNTIME_IMAGE).

Coverage

To run the tests with coverage, install the coverage dependencies with pip install .[coverage], and then run make coverage. A summary will be displayed to the terminal, and a detailed coverage report will be available at htmlcov/index.html.

Contribute

GitHub pull requests are very welcome.

License

Copyright 2020 Fauna, Inc.

Licensed under the Mozilla Public License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at

http://mozilla.org/MPL/2.0/

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

faunadb-python's People

Contributors

alvarofauna avatar andy-faunadb avatar ashfire908 avatar bitbckt avatar dijkstracula avatar erickpintor avatar faunaee avatar freels avatar marrony avatar sprsquish avatar

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.