Load cypher queries from a directory as python string objects.
Project description
Cypher Query Loader
A small package that handles loading strings from *.cypher files into python strings. I use this code in packages that query a database and need saved queries. It lets me keep the code in .cypher format and use syntax highlighing in my IDE.
Important safety note:This code does not check cypher files for safety or security. End users should only point their QueryLoader objects at file systems they trust and control.
Use
To use the CypherQueries object create an instance pointed at a directory of *.cypher files. The CypherQueries object will add the *.cypher file names as attributes, so <MY_FILE_PATH>/cypher/fetch_k_nodes.cypher will become queries.fetch_k_nodes in the CypherQueries instance queries.
To return the query text you simply call the queries.fetch_k_nodes attribute.
The CypherLoader object automatically detects parameters in the query. To see the parameters of a query use the params attribute, eg queries.fetch_k_nodes.params.
import cypher_query_loader
# The example is the packages tests
# Replace the example with a file to your packages cypher queries.
queries = cypher_query_loader.CypherQueries('./tests/cypher')
# return the query text
queries.fetch_k_nodes
# MATCH (n) RETURN n LIMIT $limit;
# return parameters of the query
queries.fetch_k_nodes.params
# {'limit': None}
# set parameters of the query
queries.fetch_k_nodes.params['limit'] = 5
queries.fetch_k_nodes.params
# {'limit': 5}
Using the CypherQueries object with the neo4j package.
The queries can be fed directly to the GraphDatabase.driver.execute_query() function.
from neo4j import GraphDatabase
URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "password")
driver = GraphDatabase.driver(uri, auth=AUTH)
result = driver.execute_query(
queries.fetch_k_nodes,
**query.fetch_k_nodes.params
)
driver.close
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cypher_query_loader-0.1.2.tar.gz.
File metadata
- Download URL: cypher_query_loader-0.1.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
406edb21e3e2a7ca0f7c8c511b0d5f56757c0b97ee5a4ab24d7dd7d83af60d71
|
|
| MD5 |
7894fc651922436fe75ac929f4710c1a
|
|
| BLAKE2b-256 |
8fbcce0d1fb003d3cf16bda8eb118ce48ebbd38afe6819c34d23d59878b55bff
|
File details
Details for the file cypher_query_loader-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cypher_query_loader-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4ed8ec8fa0813f6d0d1be88ef07df69971db26f5996b03aec374c9fc4392b2d
|
|
| MD5 |
6284fb5a8d52c5b42c8ca52990926005
|
|
| BLAKE2b-256 |
de5092f980cedd4731450862e9b9569620bb77b035f4455c42f837a4f0c8e513
|