Skip to main content

pcypher is a Python library to parse Cypher queries.

Project description

pcypher

License Python

Overview

Pcypher is a Python library to parse Cypher queries.

Table of Contents

Prerequisites

  • Python 3.9 or higher

Installation

pcypher offers two options of use patterns:

  • CLI command to parse Cypher queries
  • Python library to parse Cypher queries

As a CLI command, install pcypher with brew.

brew tap rioriost/pcypher
brew install pcypher

As a Python library, install pcypher with pip / uv.

python venv on macOS, Linux

mkdir your_directory
cd your_directory
python3 -m venv venv
source venv/bin/activate
python3 -m pip install pcypher

uv on macOS, Linux

uv init your_directory
cd your_directory
uv venv
source .venv/bin/activate
uv add pcypher

python venv on Windows

md your_directory
cd your_directory
python -m venv venv
source .\venv\Scripts\activate
python -m pip install pcypher

Usage as CLI command

Execute pcypher command.

pcypher --help
usage: pcypher [-h] query

positional arguments:
  query       Query to parse

optional arguments:
  -h, --help  show this help message and exit
pcypher "CREATE (adam:User {name: 'Adam'}), (pernilla:User {name: 'Pernilla'}), (david:User {name: 'David'}), (adam)-[:FRIEND]->(pernilla), (pernilla)-[:FRIEND]->(david)"
[('CREATE', [('node', 'adam', ['User'], [('name', 'Adam')]), ('node', 'pernilla', ['User'], [('name', 'Pernilla')]), ('node', 'david', ['User'], [('name', 'David')]), ('chain', ('node', 'adam', [], None), [(('directed', ('relationship', [{'variable': None, 'type': 'FRIEND'}], None, None)), ('node', 'pernilla', [], None))]), ('chain', ('node', 'pernilla', [], None), [(('directed', ('relationship', [{'variable': None, 'type': 'FRIEND'}], None, None)), ('node', 'david', [], None))])])]

Usage as Python library

from pcypher import CypherParser

def main():
    query = "CREATE (adam:User {name: 'Adam'}), (pernilla:User {name: 'Pernilla'}), (david:User {name: 'David'}), (adam)-[:FRIEND]->(pernilla), (pernilla)-[:FRIEND]->(david)"
    parser = CypherParser()
    result = parser.parse(query)
    print(f"{str(result)}")

if __name__ == "__main__":
    main()

Release Notes

0.1.0 Release

  • Initial release.

Known Issues

    """MATCH (martin:Person {name: 'Martin Sheen'}), (oliver:Person {name: 'Oliver Stone'}), p = shortestPath((martin)-[*..15]-(oliver)) RETURN p""",  # in page 67
    """MATCH (martin:Person {name: 'Martin Sheen'}), (michael:Person {name: 'Michael Douglas'}), p = allShortestPaths((martin)-[*]-(michael)) RETURN p""",  # in page 67
    """MATCH (n:Member) RETURN org.opencypher.function.example.join(collect(n.name)) AS members""",  # in page 193
    """MATCH (n:Member) RETURN org.opencypher.function.example.longestString(n.name) AS member""",  # in page 193

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcypher-0.1.0.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pcypher-0.1.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file pcypher-0.1.0.tar.gz.

File metadata

  • Download URL: pcypher-0.1.0.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.27

File hashes

Hashes for pcypher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 97c4c418e70931eea5e93a2287b5beb0c55ff88ba2f2c4baaa3118d89c217659
MD5 7afa29c63b1f26777191d965d066023e
BLAKE2b-256 cc434058181d544347a73bd89ee79d9993c97e7a55190fc09c8424471652a188

See more details on using hashes here.

File details

Details for the file pcypher-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pcypher-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.27

File hashes

Hashes for pcypher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4d372328504eaaf2b9f45b0f53f811e1e1b31a87dd73e7cfe29499d6e9522b2
MD5 bdff9d658891567a44788953143fe78d
BLAKE2b-256 7f4ac1d6f0c055b0ed0b559a96aa99408bbb7b591e00903044a6a29533223c71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page