FaunaClient

class faunadb.client.FaunaClient(secret, domain='db.fauna.com', scheme='https', port=None, timeout=60, observer=None, pool_connections=10, pool_maxsize=10, **kwargs)

Directly communicates with FaunaDB via JSON.

For data sent to the server, the to_fauna_json method will be called on any values. It is encouraged to pass e.g. Ref objects instead of raw JSON data.

All methods return a converted JSON response. This is a dict containing lists, ints, floats, strings, and other dicts. Any Ref, SetRef, FaunaTime, or datetime.date values in it will also be parsed. (So instead of {"@ref": {"id": "frogs", "class": {"@ref": {"id": "classes"}}}}, you will get Ref("frogs", Native.CLASSES).)

__init__(secret, domain='db.fauna.com', scheme='https', port=None, timeout=60, observer=None, pool_connections=10, pool_maxsize=10, **kwargs)
Parameters:
  • secret – Auth token for the FaunaDB server.
  • domain – Base URL for the FaunaDB server.
  • scheme"http" or "https".
  • port – Port of the FaunaDB server.
  • timeout – Read timeout in seconds.
  • observer – Callback that will be passed a RequestResult after every completed request.
  • pool_connections – The number of connection pools to cache.
  • pool_maxsize – The maximum number of connections to save in the pool.
get_last_txn_time()

Get the freshest timestamp reported to this client. :return:

new_session_client(secret, observer=None)

Create a new client from the existing config with a given secret. The returned client share its parent underlying resources.

Parameters:
  • secret – Credentials to use when sending requests.
  • observer – Callback that will be passed a RequestResult after every completed request.
Returns:

ping(scope=None, timeout=None)

Ping FaunaDB.

query(expression)

Use the FaunaDB query API.

Parameters:expression – A query. See Query for information on queries.
Returns:Converted JSON response.
sync_last_txn_time(new_txn_time)

Sync the freshest timestamp seen by this client.

This has no effect if staler than currently stored timestamp. WARNING: This should be used only when coordinating timestamps across

multiple clients. Moving the timestamp arbitrarily forward into the future will cause transactions to stall.
Parameters:new_txn_time – the new seen transaction time.