All Projects → memgraph → gqlalchemy

memgraph / gqlalchemy

Licence: Apache-2.0 License
GQLAlchemy is a library developed with the purpose of assisting in writing and running queries on Memgraph. GQLAlchemy supports high-level connection to Memgraph as well as modular query builder.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to gqlalchemy

Osmnx
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.
Stars: ✭ 3,357 (+8507.69%)
Mutual labels:  graphs, networkx
nxontology
NetworkX-based Python library for representing ontologies
Stars: ✭ 45 (+15.38%)
Mutual labels:  graphs, networkx
Stellargraph
StellarGraph - Machine Learning on Graphs
Stars: ✭ 2,235 (+5630.77%)
Mutual labels:  graphs, networkx
Algorithms
Free hands-on course with the implementation (in Python) and description of several computational, mathematical and statistical algorithms.
Stars: ✭ 117 (+200%)
Mutual labels:  graphs, networkx
football-graphs
Graphs and passing networks in football.
Stars: ✭ 81 (+107.69%)
Mutual labels:  graphs, networkx
disparity filter
Implements a disparity filter in Python, based on graphs in NetworkX, to extract the multiscale backbone of a complex weighted network (Serrano, et al., 2009)
Stars: ✭ 17 (-56.41%)
Mutual labels:  graphs, networkx
Java-Questions-and-Solutions
This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
Stars: ✭ 34 (-12.82%)
Mutual labels:  graphs
fludget
Learn Flutter on Flutter! A widget directory with implementation samples!
Stars: ✭ 26 (-33.33%)
Mutual labels:  hacktoberfest2021
php-cron-expr
Ultra lightweight, Dependency free and Super Fast Cron Expression parser for PHP
Stars: ✭ 42 (+7.69%)
Mutual labels:  hacktoberfest2021
Daily-Coding-DS-ALGO-Practice
A open source project🚀 for bringing all interview💥💥 and competative📘 programming💥💥 question under one repo📐📐
Stars: ✭ 255 (+553.85%)
Mutual labels:  hacktoberfest2021
designtodevelopment
This repository is all about converting design inspirations into code.
Stars: ✭ 135 (+246.15%)
Mutual labels:  hacktoberfest2021
Automatic-attendance-management-system
ROLLCALL an automatic and smart attendance marking and management system which uses Microsoft Azure’s Cognitive service at its core to create a system that could make sure that no human intervention is required and provides government the ability to monitor the attendance of the schools and helps the government officials in mark fake schools.
Stars: ✭ 44 (+12.82%)
Mutual labels:  hacktoberfest2021
rails-starter-template
Opinionated Rails starter template using esbuild, tailwindcss, postgresql and hotwired.
Stars: ✭ 21 (-46.15%)
Mutual labels:  hacktoberfest2021
football-team-flags
Flags from national teams made with css 🏳
Stars: ✭ 19 (-51.28%)
Mutual labels:  hacktoberfest2021
markdown-tweet-scheduler
Schedule daily tweets from markdown files in your repo, posted via github actions.
Stars: ✭ 49 (+25.64%)
Mutual labels:  hacktoberfest2021
Tauros
Um bot para Discord com diversas funções e dashboard para configuração!
Stars: ✭ 27 (-30.77%)
Mutual labels:  hacktoberfest2021
awesome-hacktoberfest-plant-a-tree
Will you choose the ✨ Hacktoberfest t-shirt ✨ but don't want to stop contributing to the environment and a sustainable future? Find an organization here so you can plant a tree! 🌱
Stars: ✭ 30 (-23.08%)
Mutual labels:  hacktoberfest2021
HACKTOBERFEST2021 INSPIRATION
😎A Hacktoberfest-2021 Contribution Repository For Beginners😎...Simplest Repo for Beginners👨‍💻👨‍💻👨‍💻...Add your Profile Details, Photo and Inspirational Quote 🙌🙌🙌& There you go to do your first PR❤❤❤
Stars: ✭ 30 (-23.08%)
Mutual labels:  hacktoberfest2021
Hacktoberfest2021
This is repo to create some pull requests and completing hacktoberfest2021 easily. All request will be accepted. Genuine Pull Request will promoted also. #hacktobefest #hacktobefest2021 #hacktobefest-accepted
Stars: ✭ 22 (-43.59%)
Mutual labels:  hacktoberfest2021
LNTopology
A tool to analyze the topology of Bitcoin's Lightning Network
Stars: ✭ 19 (-51.28%)
Mutual labels:  networkx

GQLAlchemy

Code style: black

GQLAlchemy is a fully open-source Python library and Object Graph Mapper (OGM) - a link between graph database objects and Python objects.

An Object Graph Mapper or OGM provides a developer-friendly workflow that allows for writing object-oriented notation to communicate with graph databases. Instead of writing Cypher queries, you will be able to write object-oriented code, which the OGM will automatically translate into Cypher queries.

GQLAlchemy is built on top of Memgraph's low-level Python client pymgclient (PyPI / Documentation / GitHub).

Installation

Before you install gqlalchemy, make sure that you have cmake installed by running:

cmake --version

You can install cmake by following the official instructions.

To install gqlalchemy, simply run the following command:

pip install gqlalchemy

Build & Test

The project uses Poetry to build the GQLAlchemy Python library. To build and run tests, execute the following command: poetry install

Before starting the tests, make sure you have an active Memgraph instance running. Execute the following command: poetry run pytest .

GQLAlchemy example

When working with the gqlalchemy, a Python developer can connect to the database and execute a MATCH Cypher query using the following syntax:

from gqlalchemy import Memgraph

memgraph = Memgraph("127.0.0.1", 7687)
memgraph.execute("CREATE (:Node)-[:Connection]->(:Node)")
results = memgraph.execute_and_fetch("""
    MATCH (from:Node)-[:Connection]->(to:Node)
    RETURN from, to;
""")

for result in results:
    print(result['from'])
    print(result['to'])

Query builder example

As we can see, the example above can be error-prone, because we do not have abstractions for creating a database connection and MATCH query.

Now, rewrite the exact same query by using the functionality of GQLAlchemy's query builder:

from gqlalchemy import match, Memgraph

memgraph = Memgraph()

results = (
    match()
    .node("Node", variable="from")
    .to("Connection")
    .node("Node", variable="to")
    .return_()
    .execute()
)

for result in results:
    print(result["from"])
    print(result["to"])

An example using the Node and Relationship classes:

from gqlalchemy import Memgraph, Node, Relationship, match, Field

memgraph = Memgraph("127.0.0.1", 7687)


class User(Node):
    id: int = Field(index=True, exist=True, unique=True, db=memgraph)


class Follows(Relationship, type="FOLLOWS"):
    pass


u1 = User(id=1).save(memgraph)
u2 = User(id=2).save(memgraph)
r = Follows(_start_node_id=u1._id, _end_node_id=u2._id).save(memgraph)

result = list(
    match(memgraph.new_connection())
    .node(variable="a")
    .to(variable="r")
    .node(variable="b")
    .where("a.id", "=", u1.id)
    .or_where("b.id", "=", u2.id)
    .return_()
    .execute()
)[0]

print(result["a"])
print(result["b"])
print(result["r"])

Development (how to build)

poetry run flake8 .
poetry run black .
poetry run pytest . -k "not slow"

Documentation

The GQLAlchemy documentation is available on memgraph.com/docs/gqlalchemy.

The documentation can be generated by executing:

pip3 install python-markdown
python-markdown

License

Copyright (c) 2016-2022 Memgraph Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].