Skip to main content

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

Metadata

Release files for cypher-query-loader 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cypher-query-loader 0.1.2
File Size Uploaded Provenance Actions
cypher_query_loader-0.1.2.tar.gz 3.0 kB Without provenance Details for cypher_query_loader-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cypher-query-loader 0.1.2
File Interpreter ABI Platform Actions
cypher_query_loader-0.1.2-py3-none-any.whl Python 3 none any Details for cypher_query_loader-0.1.2-py3-none-any.whl

Total release size: 6.8 kB

Release files / cypher_query_loader-0.1.2.tar.gz

Download URL cypher_query_loader-0.1.2.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
406edb21e3e2a7ca0f7c8c511b0d5f56757c0b97ee5a4ab24d7dd7d83af60d71
BLAKE2b-256 checksum
How to use checksums
8fbcce0d1fb003d3cf16bda8eb118ce48ebbd38afe6819c34d23d59878b55bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release files / cypher_query_loader-0.1.2-py3-none-any.whl

Download URL cypher_query_loader-0.1.2-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4ed8ec8fa0813f6d0d1be88ef07df69971db26f5996b03aec374c9fc4392b2d
BLAKE2b-256 checksum
How to use checksums
de5092f980cedd4731450862e9b9569620bb77b035f4455c42f837a4f0c8e513
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Security for cypher-query-loader 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page