fauna / faunadb-python Goto Github PK
View Code? Open in Web Editor NEWPython driver for Fauna v4
Home Page: https://docs.fauna.com/fauna/v4/
License: Other
Python driver for Fauna v4
Home Page: https://docs.fauna.com/fauna/v4/
License: Other
It would be great if we could keep up with billing via the response headers in the Python client. I believe the JS driver allows this. The headers are captured in the RequestResult object I believe but it is never exposed in the result. https://github.com/fauna/faunadb-python/blob/v4/faunadb/client.py#L392
https://github.com/fauna/faunadb-python/blob/v4/faunadb/errors.py does not handle 409 errors as a special case. This is a gap, as the client should be able to tell when database conflicts happened, so that app developers can handle them. e.g prompt retries, sending requests to re-try queues, etc.
I use poetry to install packages. And poetry fails to install faunadb:
poetry add faunadb
Using version ^4.1.1 for faunadb
Updating dependencies
Resolving dependencies... (0.0s)
AssertionError
at ~/.poetry/lib/poetry/mixology/incompatibility.py:111 in __str__
107│ )
108│
109│ def __str__(self):
110│ if isinstance(self._cause, DependencyCause):
→ 111│ assert len(self._terms) == 2
112│
113│ depender = self._terms[0]
114│ dependee = self._terms[1]
115│ assert depender.is_positive()
pip install faunadb
works fine.
desc
It looks like this driver uses the hyper
library internally, however it seems to have been deprecated and archived. Any news of a rewrite with a maintained library?
I need help with a reference to the At() method and Event() method specified in the Fauna doc for the temporality feature.
https://docs.fauna.com/fauna/current/tutorials/temporality?lang=shell
Hi there!
The title sums it up pretty much, why is the readthedocs page not working? I'm having a hard time trying to find info about the driver.
When interactively messing around with the faunadb python client, it appears to check if a new version is available. However, the chanelog URL pointed to by the upgrade message is invalid and results in a 404.
Reproduction steps:
Expected result:
A valid changelog link is provided, I.E. https://github.com/fauna/faunadb-python/blob/v4/CHANGELOG.md
Actual result:
An invalid changelog link is provided: https://github.com/fauna/faunadb-python/blob/main/CHANGELOG.md
>>> from faunadb.client import FaunaClient
>>> fauna_client = FaunaClient(secret="super_secret_key", domain="db.us.fauna.com", timeout=5)
+--------------------------------------------------------------------------------+
| New fauna version available 4.2.0 => 4.3.0 |
| Changelog: https://github.com/fauna/faunadb-python/blob/main/CHANGELOG.md |
+--------------------------------------------------------------------------------+
>>>
The website docs use short names like bool
while we've often used longer names like boolean
. Should we be consistently short or consistently long?
In particular, we should consistently name collection parameters coll
or collection
.
But when functions can only take an array we should call it arr
or array
instead.
Right now it's just a blind call to self.session.close()
on Client.__del__
. This should be handled better.
Please could we have some examples of using Lambda() FQL with this library?
I can't seem to find anything in the documentation...
Hi, I've been reading about the Fauna and it looks very promising.
However, I maintain several Django applications and I wonder what would it take to integrate the Fauna clients with Django ORM so that the application does not require massive refactoring?
Thank you.
Being able to readily convert FaunaDB objects to and from JSON is an important feature. Currently that feature is denoted as being a non-public API by naming the module _json
meaning usage of these utilities is not officially supported.
I would like to see the _json
module become officially supported and part of the public API this client provides by renaming it to json
, E.G. from faunadb.json import to_json
.
to make it consistent with the behavior of .quote, of which it is a counterpart
Same as fauna/faunadb-ruby#135
I have the following JSON:
{
"_RAJ2000": 0.00046,
"_DEJ2000": 62.52328000000001,
"CXO": "J000000.1+623123",
"RAJ2000": 0.00046,
"DEJ2000": 62.52328000000001,
"ePos": 2.69,
"SN": 3.04,
"Fb": 4.21e-15,
"b_Fb": 2.77e-15,
"B_Fb": 5.6299999999999996e-15,
"Fw": "None",
"hr2": 0.35600000000000004,
"hr1": 0.09699999999999999,
"fc": 0,
"fe": 0,
"fs": 0,
"Vab": 0.0,
"Vib": "None",
"Vaw": "None",
"Viw": "None"
}
Which is valid JSON.
When calling the Create()
method, the API returns a faunadb.errors.BadRequest: document data is not valid
error:
result = client.query(
q.create(
q.collection(collection_name),
{
"data": valid_json_data
}
)
)
ImportError: cannot import name 'Iterable' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)
options = {"fields": ["document", "diff", "action"]}
stream = client.stream(doc["ref"], options, on_start, on_error, on_version)
stream.start()
Traceback (most recent call last):
File "/workspaces/faunadb/github/faunadb-python/example.py", line 3, in <module>
from faunadb.client import FaunaClient
File "/workspaces/faunadb/github/faunadb-python/faunadb/client.py", line 19, in <module>
from faunadb.streams import Subscription
File "/workspaces/faunadb/github/faunadb-python/faunadb/streams/__init__.py", line 1, in <module>
from .client import Connection
File "/workspaces/faunadb/github/faunadb-python/faunadb/streams/client.py", line 12, in <module>
from hyper import HTTP20Connection
File "/home/vscode/.local/lib/python3.10/site-packages/hyper/__init__.py", line 11, in <module>
from .common.connection import HTTPConnection
File "/home/vscode/.local/lib/python3.10/site-packages/hyper/common/connection.py", line 9, in <module>
from ..http11.connection import HTTP11Connection
File "/home/vscode/.local/lib/python3.10/site-packages/hyper/http11/connection.py", line 13, in <module>
from collections import Iterable, Mapping
ImportError: cannot import name 'Iterable' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)
This is due to hyper
, for stream function (http/2)
faunadb-python/faunadb/streams/client.py
Line 12 in 1e16d79
faunadb-python/faunadb/streams/client.py
Line 48 in 1e16d79
"This project is no longer maintained!
Please use an alternative, such as HTTPX or others.
We will not publish further updates for hyper."
https://github.com/python-hyper/hyper
(faunadb-python works with python 3.9)
Would it be possible for the development team to compile a list of illegal characters when working with FaunaDB?
The doc says that metrics are found in the http headers.
However, this lib does not seam to expose them.
It would be nice.
You can put an array of queries into a query. Its not really well documented ATM (which should probably be a separate issue) but see
https://faunadb.com/documentation/queries#read_functions
under Get, there is a section for multi-gets that shows the syntax.
Is async implementation in the roadmap of this library?
Why raising errors on not found? you need try-catch on every query - very ugly
I'm creating cli application to interact with the db using typer and I've the following code:
# app.py
from typing import Any
from faunadb.client import FaunaClient
from faunadb import query as q
import typer
from .settings import get_settings
settings = get_settings()
client = FaunaClient(secret=settings.DB_ADMIN_PYTHON)
app = typer.Typer()
@app.command()
def create_collection_with_index(name: str) -> Any:
c = client.query(q.collection(name))
if client.query(q.exists(c)) == False:
c = client.query(q.create_collection({"name": name}))
idx_name = f"{name}_index"
ci = client.query(q.index(idx_name))
if client.query(q.exists(ci)) == False:
ci = client.query(
q.create_index(
{
"name": idx_name,
"unique": True,
"serialized": True,
"source": q.collection(name),
}
)
)
return c, ci
@app.command()
def initialize_db() -> None:
typer.echo("Initializing db...")
# app.py
from typing import Any
from faunadb.client import FaunaClient
from faunadb import query as q
import typer
from .settings import get_settings
settings = get_settings()
client = FaunaClient(secret=settings.DB_ADMIN_PYTHON)
app = typer.Typer()
@app.command()
def create_collection_with_index(name: str) -> Any:
c = client.query(q.collection(name))
if client.query(q.exists(c)) == False:
c = client.query(q.create_collection({"name": name}))
idx_name = f"{name}_index"
ci = client.query(q.index(idx_name))
if client.query(q.exists(ci)) == False:
ci = client.query(
q.create_index(
{
"name": idx_name,
"unique": True,
"serialized": True,
"source": q.collection(name),
}
)
)
return c, ci
@app.command()
def initialize_db() -> None:
typer.echo("Initializing db...")
uc, uci = create_collection_with_index(name="users")
bc, bci = create_collection_with_index(name="brokers")
dosc, dosci = create_collection_with_index(name="dos_paramters")
typer.echo("Db initialized...")
if __name__ == "__main__":
app()
typer.echo("Db initialized...")
if __name__ == "__main__":
app()
# settings.py
from pathlib import Path
from pydantic import BaseSettings
class Settings(BaseSettings):
DB_ADMIN_PYTHON: str
class Config:
env_file = ".env"
def get_settings() -> Settings:
try:
env_file: str = "./credentials/faunadb.env"
if Path(env_file).is_file():
envs = Settings(_env_file=env_file)
else:
envs = Settings()
return envs
except Exception as e:
raise e
When I run the application cli as python -m app:app initialize-db
(note the -
not as _
in the function declaration) I get the following errors after successful execution of the command:
(.venv) abbas@MKHM01:~/faunadb_base_exception$ python -m app.app initialize-db
Initializing db...
Db initialized...
Exception ignored in: <function FaunaClient.__del__ at 0x7f22cd3ba8b0>
Traceback (most recent call last):
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/faunadb/client.py", line 282, in __del__
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/requests/sessions.py", line 747, in close
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/requests/adapters.py", line 325, in close
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/poolmanager.py", line 222, in clear
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/_collections.py", line 100, in clear
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/poolmanager.py", line 173, in <lambda>
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 494, in close
TypeError: catching classes that do not inherit from BaseException is not allowed
How can I resolve this issue?
To reproduce the issue clone repository
After cloning use poetry install to get the environment setup.
There should be something in the readme that devs can copy-paste to get started. Like https://github.com/faunadb/sales-engineering/issues/437
Probably can be the same code example we use in a blog post.
Tried converting this code to python didnt work for me
client.query(
q.Map(
q.Paginate(q.Documents(q.Collection("Article"))),
q.Lambda(x => q.Get(x))
)
client.query(q.map_(
q.paginate(q.documents(q.collection("Article))),
q.lambda_("x", q.get(q.var("x"))
)
)
Would love to query this data in python
In the python driver, Select() does not accept the 3rd default parameter.
It would be better if we didn't have to use select_with_default() - as this isn't very intuitive and not according to the Docs.
An optional default
parameter was added to the query.select
function in v4.1.0, making it possible to replace the use of select_with_default
with select
in many situations. However, there is no way to use select
if you intend to use None
as the value of the default parameter.
The two statements below look like they should behave the same, but the second one raises an error if the path cannot be found.
q.select_with_default(2, ["one", "two", "three", "four"], None)
q.select(2, ["one", "two", "three", "four"], default=None)
This can be fixed by using a sentinel value for the default value of the default
parameter.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.