faunadb


Namefaunadb JSON
Version 4.5.1 PyPI version JSON
download
home_pagehttps://github.com/fauna/faunadb-python
SummaryFaunaDB Python driver
upload_time2023-08-21 15:30:56
maintainer
docs_urlhttps://pythonhosted.org/faunadb/
authorFauna, Inc
requires_python
licenseMPL 2.0
keywords faunadb fauna
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            The Official Python driver for v4 API of Fauna
==============================================

.. image:: https://img.shields.io/codecov/c/github/fauna/faunadb-python/master.svg?maxAge=21600
 :target: https://codecov.io/gh/fauna/faunadb-python
.. image:: https://img.shields.io/pypi/v/faunadb.svg?maxAge=21600
 :target: https://pypi.python.org/pypi/faunadb
.. image:: https://img.shields.io/badge/license-MPL_2.0-blue.svg?maxAge=2592000
 :target: https://raw.githubusercontent.com/fauna/faunadb-python/main/LICENSE

Python driver for `FaunaDB <https://fauna.com>`_.

Note: This driver supports an older version of the Fauna API. The latest version of the official
Fauna Python Driver is located [here](https://pypi.org/project/faunadb/) (we encourage all new
development to use this new version where possible).

Installation
------------

.. code-block:: bash

    $ pip install faunadb


Compatibility
-------------

The following versions of Python are supported:

* Python 3.6
* Python 3.7
* Python 3.8
* Python 3.9
* Python 3.10

Documentation
-------------

Driver documentation is available at https://fauna.github.io/faunadb-python/4.5.0/api/.

See the `FaunaDB Documentation <https://docs.fauna.com/fauna/v4/api/fql/>`__ for a complete API reference, or look in `tests`_
for more examples.


Basic Usage
-----------

.. code-block:: python

    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:

.. code-block:: python

    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_error, on_version)
    stream.start()

Observing Metrics
-----------------

Its possible to observe each query's metrics by providing an "observer" callback.

More information on query metrics is available in the `FaunaDB Documentation <https://docs.fauna.com/fauna/v4/learn/understanding/plan_billing/billing#perquery>`__.

Here is a simple example:

.. code-block:: python

    from faunadb import query as q
    from faunadb.client import FaunaClient
    from faunadb.errors import FaunaError

    # The observer callback, which takes the HTTP response for a query
    def observe(response):
        h = response.response_headers
        print('bytesOut:', h["x-compute-ops"])
        print('queryTime:', h["x-query-time"])
        print('readOps:', h["x-byte-read-ops"])
        print('writeOps:', h["x-byte-write-ops"])
        print('retries:', h["x-txn-retries"])

    # Connect to a local Fauna Dev instance
    client = FaunaClient(
        secret="secret",
        domain="localhost",
        scheme="http",
        port=8443,
        observer=observe
    )

    try:
        result = client.query(
            q.paginate(q.collections())
        )
    except FaunaError as err:
        print("err: ", err)
    else:
        print(result)

Building it yourself
--------------------


Setup
~~~~~

.. code-block:: bash

    $ 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. <https://fauna.com>`_

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/ <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.


.. _`tests`: https://github.com/fauna/faunadb-python/blob/main/tests/



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fauna/faunadb-python",
    "name": "faunadb",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/faunadb/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "faunadb fauna",
    "author": "Fauna, Inc",
    "author_email": "priority@fauna.com",
    "download_url": "",
    "platform": null,
    "description": "The Official Python driver for v4 API of Fauna\n==============================================\n\n.. image:: https://img.shields.io/codecov/c/github/fauna/faunadb-python/master.svg?maxAge=21600\n :target: https://codecov.io/gh/fauna/faunadb-python\n.. image:: https://img.shields.io/pypi/v/faunadb.svg?maxAge=21600\n :target: https://pypi.python.org/pypi/faunadb\n.. image:: https://img.shields.io/badge/license-MPL_2.0-blue.svg?maxAge=2592000\n :target: https://raw.githubusercontent.com/fauna/faunadb-python/main/LICENSE\n\nPython driver for `FaunaDB <https://fauna.com>`_.\n\nNote: This driver supports an older version of the Fauna API. The latest version of the official\nFauna Python Driver is located [here](https://pypi.org/project/faunadb/) (we encourage all new\ndevelopment to use this new version where possible).\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    $ pip install faunadb\n\n\nCompatibility\n-------------\n\nThe following versions of Python are supported:\n\n* Python 3.6\n* Python 3.7\n* Python 3.8\n* Python 3.9\n* Python 3.10\n\nDocumentation\n-------------\n\nDriver documentation is available at https://fauna.github.io/faunadb-python/4.5.0/api/.\n\nSee the `FaunaDB Documentation <https://docs.fauna.com/fauna/v4/api/fql/>`__ for a complete API reference, or look in `tests`_\nfor more examples.\n\n\nBasic Usage\n-----------\n\n.. code-block:: python\n\n    from faunadb import query as q\n    from faunadb.objects import Ref\n    from faunadb.client import FaunaClient\n\n    client = FaunaClient(secret=\"your-secret-here\")\n\n    indexes = client.query(q.paginate(q.indexes()))\n\n    print(indexes)\n\nDocument Streaming\n------------------\nFauna supports document streaming, where changes to a streamed document are pushed to all clients subscribing to that document.\n\nThe following section provides an example for managing a document stream.\n\nThe streaming API is blocking by default, the choice and mechanism for handling concurrent streams is left to the application developer:\n\n.. code-block:: python\n\n    from faunadb import query as q\n    from faunadb.objects import Ref\n    from faunadb.client import FaunaClient\n\n    client = FaunaClient(secret=\"your-secret-here\")\n\n    coll = client.query(q.create_collection({\"name\":\"sc\"}))\n    doc  = client.query(q.create(coll[\"ref\"], {\"data\":{\"x\": 0}}))\n\n    stream = None\n    def on_start(event):\n        print(\"started stream at %s\"%(event.txn))\n        client.query(q.update(doc[\"ref\"], {\"data\": {\"x\": \"updated\"}}))\n\n    def on_version(event):\n        print(\"on_version event at %s\"%(event.txn))\n        print(\"    event: %s\"%(event.event))\n        stream.close()\n\n    def on_error(event):\n        print(\"Received error event %s\"%(event))\n    options = {\"fields\": [\"document\", \"diff\"]}\n    stream = client.stream(doc[\"ref\"], options, on_start, on_error, on_version)\n    stream.start()\n\nObserving Metrics\n-----------------\n\nIts possible to observe each query's metrics by providing an \"observer\" callback.\n\nMore information on query metrics is available in the `FaunaDB Documentation <https://docs.fauna.com/fauna/v4/learn/understanding/plan_billing/billing#perquery>`__.\n\nHere is a simple example:\n\n.. code-block:: python\n\n    from faunadb import query as q\n    from faunadb.client import FaunaClient\n    from faunadb.errors import FaunaError\n\n    # The observer callback, which takes the HTTP response for a query\n    def observe(response):\n        h = response.response_headers\n        print('bytesOut:', h[\"x-compute-ops\"])\n        print('queryTime:', h[\"x-query-time\"])\n        print('readOps:', h[\"x-byte-read-ops\"])\n        print('writeOps:', h[\"x-byte-write-ops\"])\n        print('retries:', h[\"x-txn-retries\"])\n\n    # Connect to a local Fauna Dev instance\n    client = FaunaClient(\n        secret=\"secret\",\n        domain=\"localhost\",\n        scheme=\"http\",\n        port=8443,\n        observer=observe\n    )\n\n    try:\n        result = client.query(\n            q.paginate(q.collections())\n        )\n    except FaunaError as err:\n        print(\"err: \", err)\n    else:\n        print(result)\n\nBuilding it yourself\n--------------------\n\n\nSetup\n~~~~~\n\n.. code-block:: bash\n\n    $ virtualenv venv\n    $ source venv/bin/activate\n    $ pip install .\n\n\nTesting\n~~~~~~~\n\nTo run the tests you must have a FaunaDB database available.\nThen set the environment variable ``FAUNA_ROOT_KEY`` to your database's root key.\nIf you use FaunaDB cloud, this is the password you log in with.\n\nTip: Setting the ``FAUNA_QUERY_TIMEOUT_MS`` environment variable will\nset a timeout in milliseconds for all queries.\n\nThen run ``make test``.\nTo test a single test, use e.g. ``python -m unittest tests.test_client.ClientTest.test_ping``.\n\nTests can also be run via a Docker container with ``FAUNA_ROOT_KEY=\"your-cloud-secret\" make docker-test``\n(an alternate Alpine-based Python image can be provided via `RUNTIME_IMAGE`).\n\n\nCoverage\n~~~~~~~~\n\nTo run the tests with coverage, install the coverage dependencies with ``pip install .[coverage]``,\nand then run ``make coverage``. A summary will be displayed to the terminal, and a detailed coverage report\nwill be available at ``htmlcov/index.html``.\n\n\nContribute\n----------\n\nGitHub pull requests are very welcome.\n\n\nLicense\n-------\n\nCopyright 2020 `Fauna, Inc. <https://fauna.com>`_\n\nLicensed under the Mozilla Public License, Version 2.0 (the\n\"License\"); you may not use this software except in compliance with\nthe License. You may obtain a copy of the License at\n\n`http://mozilla.org/MPL/2.0/ <http://mozilla.org/MPL/2.0/>`_\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\nimplied. See the License for the specific language governing\npermissions and limitations under the License.\n\n\n.. _`tests`: https://github.com/fauna/faunadb-python/blob/main/tests/\n\n\n",
    "bugtrack_url": null,
    "license": "MPL 2.0",
    "summary": "FaunaDB Python driver",
    "version": "4.5.1",
    "project_urls": {
        "Homepage": "https://github.com/fauna/faunadb-python"
    },
    "split_keywords": [
        "faunadb",
        "fauna"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d339e25a7a3d34151b9f3799becf15345d5132290eb0f0bbbaac65ff26334130",
                "md5": "b5e671810213704924b15638b593d3b6",
                "sha256": "57689ed41e52043ee3149dfbb47bff0bd811e1a484fc3ee17003ae3e2d8ddc7c"
            },
            "downloads": -1,
            "filename": "faunadb-4.5.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b5e671810213704924b15638b593d3b6",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 27917,
            "upload_time": "2023-08-21T15:30:56",
            "upload_time_iso_8601": "2023-08-21T15:30:56.714749Z",
            "url": "https://files.pythonhosted.org/packages/d3/39/e25a7a3d34151b9f3799becf15345d5132290eb0f0bbbaac65ff26334130/faunadb-4.5.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-21 15:30:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fauna",
    "github_project": "faunadb-python",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": true,
    "circle": true,
    "requirements": [],
    "lcname": "faunadb"
}
        
Elapsed time: 0.10923s