You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current approach of passing parameters to a Cypher query in Kùzu via Python is a bit tedious, as the user has to type out a list of tuples that makes the code a bit ugly, and on many counts, is not "pythonic".
The Neo4j Python client allows the specification of parameters as dict[str, Any], which is much easier to use and type for Python users. In recent versions of Python, we also have TypedDict, which we can use to more carefully check types on parameters prior to passing them to the query.
Proposed solution
Instead of specifying that the user pass list[tuple[str, Any]], the docstring could instead say to pass dict[str, Any], in a similar way to Neo4j's Python client.
To avoid breaking anything for the C++ bindings, the dict could easily be converted to list[tuple[str, Any]] within the code (invisible to the user) as follows:
This effortless transformation could be added at the start of the execute statement src_py/connection.py, and the docstring could be updated to inform the user to passs params as dict[str, Any] accordingly.
I don't think this would break any existing tests, not require any changes to C++ query preparation code, and also maintain a more similar API to Neo4j's client. Hope this makes sense!
The text was updated successfully, but these errors were encountered:
Thanks for your suggestion. I agree that passing args as dict is more user-friendly than list of tuples and this is how we implmented our Node.js API. We will change our Python API to also use dict soon.
Observation
The current approach of passing parameters to a Cypher query in Kùzu via Python is a bit tedious, as the user has to type out a list of tuples that makes the code a bit ugly, and on many counts, is not "pythonic".
The Neo4j Python client allows the specification of parameters as
dict[str, Any]
, which is much easier to use and type for Python users. In recent versions of Python, we also haveTypedDict
, which we can use to more carefully check types on parameters prior to passing them to the query.Proposed solution
Instead of specifying that the user pass
list[tuple[str, Any]]
, the docstring could instead say to passdict[str, Any]
, in a similar way to Neo4j's Python client.To avoid breaking anything for the C++ bindings, the dict could easily be converted to
list[tuple[str, Any]]
within the code (invisible to the user) as follows:This effortless transformation could be added at the start of the
execute
statementsrc_py/connection.py
, and the docstring could be updated to inform the user to passs params asdict[str, Any]
accordingly.I don't think this would break any existing tests, not require any changes to C++ query preparation code, and also maintain a more similar API to Neo4j's client. Hope this makes sense!
The text was updated successfully, but these errors were encountered: