Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass parameters to connection.execute as dict instead of list of tuples #1959

Closed
prrao87 opened this issue Aug 25, 2023 · 2 comments
Closed

Comments

@prrao87
Copy link
Member

prrao87 commented Aug 25, 2023

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 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:

>>> params = {"age": 42}
>>> list(params.items())
[('age', 42)]

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!

@mewim
Copy link
Collaborator

mewim commented Aug 28, 2023

Hi @prrao87,

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.

mewim added a commit that referenced this issue Aug 29, 2023
mewim added a commit that referenced this issue Aug 29, 2023
@mewim
Copy link
Collaborator

mewim commented Aug 29, 2023

Resolved in #1974

@mewim mewim closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants