<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Katarina Supe</title>
    <description>The latest articles on Forem by Katarina Supe (@katelatte).</description>
    <link>https://forem.com/katelatte</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F719155%2F71e6c229-a266-425c-9174-9e9b5c1cd888.jpeg</url>
      <title>Forem: Katarina Supe</title>
      <link>https://forem.com/katelatte</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/katelatte"/>
    <language>en</language>
    <item>
      <title>When to Use a NoSQL Database</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Fri, 21 Jul 2023 13:44:05 +0000</pubDate>
      <link>https://forem.com/memgraph/when-to-use-a-nosql-database-201k</link>
      <guid>https://forem.com/memgraph/when-to-use-a-nosql-database-201k</guid>
      <description>&lt;p&gt;How we manage and process data changes rapidly over the years, and staying on track with the newest technology trends is important. Traditional relational database management systems, such as MySQL, Oracle, and SQL Server, have always been the first choice to maintain data integrity and for fast querying, but with the rise of big data, NoSQL (Not Only SQL) databases emerged and became more popular due to their speed, flexibility, and scalability. Now, the question that pops up naturally is when is the right time to use a NoSQL database?&lt;/p&gt;

&lt;p&gt;This blog post will explore NoSQL databases and how they differ from traditional databases. Besides, you will learn when and why to utilize NoSQL databases. Whether you’re a developer, data engineer, or decision maker, this blog post will provide insights into modern databases that will come in handy to boost your projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding NoSQL databases
&lt;/h2&gt;

&lt;p&gt;NoSQL databases are non-relational databases with flexible schema designed for high performance at a massive scale. Unlike traditional relational databases, which use tables and predefined schemas, NoSQL databases use a variety of data models. There are 4 main types of NoSQL databases - document, graph, key-value, and column-oriented databases. NoSQL databases generally are well-suited for unstructured data, large-scale applications, and agile development processes. The most popular examples of NoSQL databases are &lt;a href="https://www.mongodb.com/" rel="noopener noreferrer"&gt;MongoDB&lt;/a&gt; (document), &lt;a href="https://memgraph.com/" rel="noopener noreferrer"&gt;Memgraph&lt;/a&gt; (graph),  &lt;a href="https://redis.io/" rel="noopener noreferrer"&gt;Redis&lt;/a&gt; (key-value store) and &lt;a href="https://hbase.apache.org/" rel="noopener noreferrer"&gt;Apache HBase&lt;/a&gt; (column-oriented).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fnosql-databases.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fnosql-databases.png" alt="nosql databases"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These &lt;a href="https://memgraph.com/blog/types-of-nosql-databases-deep-dive" rel="noopener noreferrer"&gt;types of NoSQL databases&lt;/a&gt; store data in their own unique ways offering pros and cons, which are presented below:&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility&lt;/strong&gt;: If you’ve used an SQL database before, you are probably familiar with its strict schema. That can be a hassle with data rapidly changing. NoSQL databases, with their dynamic and flexible schemas, have a huge advantage in handling unstructured and semi-structured data, making an excellent choice for diverse data types.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Data volumes can grow exponentially, and scalability becomes crucial, especially with the rise of big data. Many NoSQL databases offer horizontal scalability, allowing you to add more servers to increase the capacity. On the other hand, SQL databases usually scale only vertically. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Many NoSQL databases are optimized to deliver high performance, even when dealing with large data volumes or data streams. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Maturity&lt;/strong&gt;: SQL (standing for Structured Query Language) databases have been popular in the database world for a long time, and because of that, they offer robustness, tools and community that NoSQL databases have not managed to match yet. That does not mean that NoSQL will not overtake over the years, just like it happens often with modern technologies. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complexity&lt;/strong&gt;: The learning curve with NoSQL databases is steeper than with SQL databases, especially because there is no standard query language. This follows from the maturity and the fact that NoSQL databases are more complex to design, implement and manage. But, the results you gain by storing your data in a proper database might be worth it. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ACID compliance&lt;/strong&gt;: Opposite to NoSQL databases, many SQL databases are usually ACID-compliant. However, as an exception, Memgraph is a NoSQL graph database that is ACID compliant. If you’re unsure what that means for your application, you are invited to check out our recent blog on &lt;a href="https://memgraph.com/blog/acid-transactions-meaning-of-isolation-levels" rel="noopener noreferrer"&gt;ACID transactions and isolation levels&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5 reasons to choose a NoSQL database
&lt;/h2&gt;

&lt;p&gt;Based on the above-mentioned advantages and disadvantages of NoSQL databases, there are various scenarios where NoSQL databases are the optimal solution for your project. Let’s take a look at 5 scenarios where NoSQL databases are great:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Handling large volumes of data at scale seamlessly
&lt;/h3&gt;

&lt;p&gt;NoSQL databases can handle large amounts of data by spreading it across multiple servers. Hence, the NoSQL database is a perfect solution if you have large amounts of growing data. You don’t have to worry that you don’t have enough resources to scale vertically; instead, you should design your database system properly to get the most insights from your data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fvertical-vs-horizontal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fvertical-vs-horizontal.png" alt="vertical vs horizontal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Working easily with unstructured or semi-structured data
&lt;/h3&gt;

&lt;p&gt;Predefined schemas can be good sometimes, but if you’ve always found that a hassle for your unstructured or semi-structured data which is often changing, NoSQL databases are the correct approach. They are built with flexible data schema, which speeds up the development process and lowers the efforts on database management. Problems with data types like XML, JSON and others have become issues of the past with NoSQL databases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fstructured-semi-structured-unstructured-data.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fstructured-semi-structured-unstructured-data.png" alt="structured and unstructured data"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Enabling rapid development
&lt;/h3&gt;

&lt;p&gt;Again, because of the NoSQL flexibility, your data model can rapidly change, meaning you can update your application on the fly without schema updates. Nowadays, development is fast, and iterations are quick, so removing the task of updating schemas constantly saves you valuable time that can be spent on even faster development.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. High read/write speed
&lt;/h3&gt;

&lt;p&gt;If you’re working on applications that require real-time data processing, you might be stuck with traditional databases that don’t offer the required speed. NoSQL databases are optimized for high-speed read and write operations and are ideal for chat, IoT, gaming, fraud detection, and similar applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Managing complex relationships
&lt;/h3&gt;

&lt;p&gt;Complex data relationships, such as parent-child or many-to-many relationships, arise in relational databases when data from different tables is related or somehow interconnected. Querying it requires hopping from one table to another and joining it with slow and resource-intensive join operations. A graph database is a type of NoSQL database that handles highly-connected data especially well and is a good choice for social networks, recommendation engines, fraud detection, or any application where you need to traverse through interconnected data points.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fdata-pouring.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fwhen-to-use-nosql-database%2Fdata-pouring.png" alt="data pouring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Concluding thoughts
&lt;/h2&gt;

&lt;p&gt;If you still don’t know whether you need an NoSQL or a relational database management system, we prepared &lt;a href="https://memgraph.com/blog/how-to-choose-a-database-for-your-needs" rel="noopener noreferrer"&gt;another article&lt;/a&gt; on that topic that may speed up your decision process. Keep in mind that it doesn’t always have to be a fight, SQL vs NoSQL, you can surely consider a hybrid approach and get the best out of both SQL and NoSQL databases. But if you did find that your use case fits the description above, then NoSQL is a database for you! We are always open to discussions on this and other topics in the database scene, so &lt;a href="https://www.discord.gg/memgraph" rel="noopener noreferrer"&gt;join the conversation&lt;/a&gt; on our Discord server to be a part of the community.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Memgraph Community Call: Querying Memgraph through an LLM</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Fri, 30 Jun 2023 16:27:53 +0000</pubDate>
      <link>https://forem.com/memgraph/memgraph-community-call-querying-memgraph-through-an-llm-1b1m</link>
      <guid>https://forem.com/memgraph/memgraph-community-call-querying-memgraph-through-an-llm-1b1m</guid>
      <description>&lt;p&gt;Memgraph has organized its fair share of community calls to bring its community closer together and spread knowledge about important topics related to the graph database world. Attendees had the opportunity to meet the Memgraph team and talk with them about new features or their day-to-day responsibilities. They also had the chance to take over the stage and talk about the projects they worked on.&lt;/p&gt;

&lt;p&gt;We are looking forward to many calls like this, and it proved to be great to have an open channel of communication directly with the Memgraph community to hear the most honest feedback about the product and experiences with building their products using graph databases. &lt;/p&gt;

&lt;p&gt;In case you missed our community calls and want to catch up before the next one, head over to &lt;a href="https://www.youtube.com/watch?v=QYFU5d_xLIs&amp;amp;list=PL7Eotag2rRhZssS4f11PKAHuCykMCljg3"&gt;Memgraph’s YouTube channel&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memgraph entering the world of LLMs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;On July 7th, at 6 PM CEST&lt;/strong&gt;, Memgraph is organizing the next community call on &lt;strong&gt;Querying Memgraph through an &lt;a href="https://en.wikipedia.org/wiki/Large_language_model"&gt;LLM&lt;/a&gt;&lt;/strong&gt;. Our guest speaker is &lt;a href="https://www.linkedin.com/in/brett-brewer-967182/"&gt;Brett Brewer&lt;/a&gt;, who has broad experience as a chemical engineer in industrial process automation and who has been a VP at Microsoft throughout his 25-year long career there. Now retired, he found a new way to have fun - he jumped into the AI rabbit hole to expand his knowledge and contribute where he can. That’s how he connected with Memgraph and gave us an idea to integrate with &lt;a href="https://langchain.com/"&gt;LangChain&lt;/a&gt;. That was not an easy task, but not to spoil too much, &lt;a href="https://us02web.zoom.us/j/84734174129?pwd=aGtkc0UwVm10L3Qva2VveU01U1ozdz09"&gt;join our community call&lt;/a&gt; to hear and talk all about that journey!&lt;/p&gt;

&lt;h2&gt;
  
  
  Hang out with the community
&lt;/h2&gt;

&lt;p&gt;To wrap it up, if you want to stay in touch with the Memgraph community, set up a reminder for this and similar events – &lt;a href="https://www.discord.gg/memgraph"&gt;join our Discord server&lt;/a&gt;! We try our best to keep the community engaged, questions answered, and every community member listened to. &lt;/p&gt;

&lt;p&gt;Once again, here are the community call event details:&lt;/p&gt;

&lt;p&gt;Topic: Querying Memgraph through an LLM &lt;br&gt;&lt;br&gt;
Speaker: Brett Brewer &lt;br&gt;&lt;br&gt;
Date and time: Friday, July 7th, 6 PM CEST &lt;br&gt;&lt;br&gt;
Zoom link: &lt;a href="https://us02web.zoom.us/j/84734174129?pwd=aGtkc0UwVm10L3Qva2VveU01U1ozdz09"&gt;https://us02web.zoom.us/j/84734174129?pwd=aGtkc0UwVm10L3Qva2VveU01U1ozdz09&lt;/a&gt; &lt;br&gt;&lt;br&gt;
Hope to see you there 👋😀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Cosine Similarity in Python with Scikit-Learn</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Mon, 12 Jun 2023 14:47:48 +0000</pubDate>
      <link>https://forem.com/memgraph/understanding-cosine-similarity-in-python-with-scikit-learn-12ha</link>
      <guid>https://forem.com/memgraph/understanding-cosine-similarity-in-python-with-scikit-learn-12ha</guid>
      <description>&lt;p&gt;Cosine similarity proved useful in many different areas, such as in machine learning applications, natural language processing, and information retrieval. After reading this article, you will know precisely what cosine similarity is, how to run it with Python using the scikit-learn library (also known as sklearn), and when to use it. You’ll also learn how cosine similarity is related to graph databases, exploring the quickest way to utilize it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cosine similarity algorithm: Deep dive
&lt;/h2&gt;

&lt;p&gt;Cosine similarity is a measure of similarity between two non-zero vectors of an inner product space based on the cosine of the angle between them, resulting in a value between -1 and 1. The value -1 means that the vectors are opposite, 0 represents orthogonal vectors, and value 1 signifies similar vectors. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l6beXJ83--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/cosine-similarity.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l6beXJ83--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/cosine-similarity.png" alt="cosine similarity" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The cosine similarity formula
&lt;/h3&gt;

&lt;p&gt;To compute the cosine similarity between vectors A and B, you can use the following formula:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GjNMwiXM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/similarity-formula.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GjNMwiXM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/similarity-formula.png" alt="cosine similarity formula" width="370" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here  is the angle between the vectors,  AB is the dot product between A and B, while A and B are the magnitudes, or lengths, of vectors A and B, respectively. The dot product can be expressed as a sum of the product of all vector dimensions and magnitudes as: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3-RUinYW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/sum-of-the-product-all-vector.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3-RUinYW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/sum-of-the-product-all-vector.png" alt="sum of the product" width="636" height="89"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So the cosine similarity formula is equivalent to:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GGNMAsmW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/cosine-similarity-formula-equivalent.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GGNMAsmW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/cosine-similarity-formula-equivalent.png" alt="cosine similarity equivalent" width="511" height="128"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The cosine similarity is often used in text analytics to compare documents and determine if they’re similar and how much. In that case, documents must be represented as a vector, where a unique word is a dimension and the frequency or weight of that unique word in the document represents the value of that specific dimension. After the transformation of documents to vectors is done, comparison using cosine similarity is relatively straightforward — we measure the cosine of the angle between their vectors. If the angle between vectors (documents) is small, then the cosine of the angle is high, and hence, documents are similar. Opposite to that, if the angle between vectors (documents) is large, then the cosine of the angle is low, resulting in opposite documents (not similar). Cosine similarity considers the orientation of the vectors, but it does not take their magnitudes into account. In the previous example, this means that even documents of totally different lengths can be considered similar if they are related to the same topic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exploring Python libraries for cosine similarity
&lt;/h2&gt;

&lt;p&gt;As explained in the previous chapter, cosine similarity can be easily calculated using the mathematical formula. But what if the data you have becomes too large and you want to calculate the similarities fast? The most popular programming language used for such tasks is definitely Python and its flexibility is partly due to its extensive range of libraries. For calculating cosine similarity, the most popular ones are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://numpy.org/doc/stable/#"&gt;NumPy&lt;/a&gt;: the fundamental package for scientific computing in Python, which has functions for dot product and vector magnitude, both necessary for the cosine similarity formula.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scipy.org/"&gt;SciPy&lt;/a&gt;: a library used for scientific and technical computing. It has a function that can calculate the cosine distance, which equals 1 minus the cosine similarity.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scikit-learn.org/stable/"&gt;Scikit-learn&lt;/a&gt;: offers simple and efficient tools for predictive data analysis and has a function to directly and efficiently compute cosine similarity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the above-mentioned libraries, only scikit-learn directly calculates the cosine similarity between two vectors or matrices, making it an excellent tool for data analysts and machine learning enthusiasts. It provides &lt;code&gt;sklearn.metrics.pairwise.cosine_similarity function&lt;/code&gt; to do that, and we will show how it works on an example&lt;/p&gt;

&lt;h2&gt;
  
  
  How to calculate cosine similarity
&lt;/h2&gt;

&lt;p&gt;To demonstrate how to calculate cosine similarity in a simple example, let’s take the descriptions of the most popular social networks from &lt;a href="https://en.wikipedia.org/wiki/Main_Page"&gt;Wikipedia&lt;/a&gt; and compare them. The library used for calculating cosine similarity is scikit-learn, as mentioned in the previous section since it calculates cosine similarity directly with the help of sklearn.metrics.pairwise.cosine_similarity function. Besides that function, CountVectorizer from scikit-learn is used to convert the collection of text documents into a matrix of token counts. CountVectorizer has attribute stop_words which can be used to avoid counting most common words in English text, such as “and,” “the,” and “him,” which are presumed to be uninformative in representing the content of the text and which should be removed to avoid them being used in measuring similarity between two texts. Sometimes, these words are good to have to compare someone’s writing style or personality. Here is the code used to calculate the similarity between Twitter, Facebook, TikTok, and Instagram:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;sklearn.feature_extraction.text&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;CountVectorizer&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;sklearn.metrics.pairwise&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cosine_similarity&lt;/span&gt;


&lt;span class="n"&gt;twitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""
Twitter is an online social media and social networking service owned and operated by American company X Corp.,
the legal successor of Twitter, Inc. Twitter users outside the United States are legally served by the Ireland-based
Twitter International Unlimited Company, which makes these users subject to Irish and European Union data protection laws.
On Twitter users post texts, photos and videos known as 'tweets'. Registered users can tweet, like, 'retweet' tweets,
and direct message (DM) other registered users, while unregistered users only have the ability to view public tweets.
Users interact with Twitter through browser or mobile frontend software, or programmatically via its APIs.
"""&lt;/span&gt;
&lt;span class="n"&gt;facebook&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""
Facebook is an online social media and social networking service owned by American technology giant Meta Platforms.
Created in 2004 by Mark Zuckerberg with fellow Harvard College students and roommates Eduardo Saverin, Andrew McCollum,
Dustin Moskovitz, and Chris Hughes, its name derives from the face book directories often given to American university students.
Membership was initially limited to only Harvard students, gradually expanding to other North American universities and,
since 2006, anyone over 13 years old. As of December 2022, Facebook claimed 2.96 billion monthly active users, and ranked third
worldwide among the most visited websites. It was the most downloaded mobile app of the 2010s. Facebook can be accessed from devices
with Internet connectivity, such as personal computers, tablets and smartphones. After registering, users can create a profile
revealing information about themselves. They can post text, photos and multimedia which are shared with any other users who have
agreed to be their friend' or, with different privacy settings, publicly. Users can also communicate directly with each other with
Messenger, join common-interest groups, and receive notifications on the activities of their Facebook friends and the pages they follow.
"""&lt;/span&gt;
&lt;span class="n"&gt;tiktok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""
TikTok, and its Chinese counterpart Douyin (Chinese: 抖音; pinyin: Dǒuyīn), is a short-form video hosting service owned by ByteDance.
It hosts user-submitted videos, which can range in duration from 3 seconds to 10 minutes. Since their launches, TikTok and Douyin have
gained global popularity.[6][7] In October 2020, TikTok surpassed 2 billion mobile downloads worldwide. Morning Consult named TikTok the
third-fastest growing brand of 2020, after Zoom and Peacock. Cloudflare ranked TikTok the most popular website of 2021,
surpassing google.com.
"""&lt;/span&gt;
&lt;span class="n"&gt;instagram&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""
Instagram is a photo and video sharing social networking service owned by American company Meta Platforms. The app allows users to
upload media that can be edited with filters and organized by hashtags and geographical tagging. Posts can be shared publicly or
with preapproved followers. Users can browse other users' content by tag and location, view trending content, like photos, and follow
other users to add their content to a personal feed. Instagram was originally distinguished by allowing content to be framed only in a
square (1:1) aspect ratio of 640 pixels to match the display width of the iPhone at the time. In 2015, this restriction was eased with
an increase to 1080 pixels. It also added messaging features, the ability to include multiple images or videos in a single post, and a
Stories feature—similar to its main competitor Snapchat—which allowed users to post their content to a sequential feed, with each post
accessible to others for 24 hours. As of January 2019, Stories is used by 500 million people daily.
"""&lt;/span&gt;




&lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;twitter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;facebook&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tiktok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instagram&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;count_vectorizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CountVectorizer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stop_words&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"english"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;count_vectorizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CountVectorizer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;sparse_matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;count_vectorizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fit_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;doc_term_matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sparse_matrix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;todense&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="n"&gt;doc_term_matrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;count_vectorizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_feature_names_out&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
   &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"twitter"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"facebook"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"tiktok"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"instagram"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cosine_similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before getting to results, it’s good to think about the expected outcomes. Since the same company owns Facebook and Instagram and they’re mostly used to share photos and videos, we can suppose that they are more similar to each other than to other social networks. Twitter might be more similar to Facebook and Instagram than to TikTok, just because of the format of posting, which is quite specific to TikTok. But enough guessing, let’s take a look:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G6yUMSt_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/terminal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G6yUMSt_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/terminal.png" alt="terminal" width="800" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, there is a matrix of word frequency in all four texts. Cosine similarity is calculated based on that matrix, and, in the end, is also turned into a matrix. Here is how to read the results:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first column represents the description of the first social network — Twitter. Every row in the first column represents cosine similarity to all four other social networks. In this case, it means that the cosine similarity of Twitter itself is 1 and that is true since those two texts are the same. That is also the reason why the whole diagonal equals 1 — it represents the cosine similarity of every social network between themselves. The next row in the first column is the cosine similarity of Twitter and Facebook vectors, while the third row is that of Twitter and TikTok vectors. In the end, we have a similarity between Twitter and Instagram vectors. Notice how the similarities of Twitter to Instagram and Facebook are quite close, leading us to the conclusion that Instagram and Facebook descriptions are similar. To check that, see the second column which shows the similarities to the Facebook vector. It goes from Twitter, across Facebook, and TikTok up to the Instagram description. Also notice how the similarity between Facebook and Instagram is quite high, 0.6, while the similarity between Facebook and TikTok is a bit smaller, 0.3.&lt;/li&gt;
&lt;li&gt;Once all columns are read and well interpreted, we can conclude that Facebook and Instagram descriptions (and hence potentially social networks) are the most similar ones. Also, Twitter is more similar to Facebook and Instagram than to TikTok. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Practical use cases of cosine similarity
&lt;/h2&gt;

&lt;p&gt;Cosine similarity is used in various applications, mostly by data scientists, to perform tasks for machine learning, natural language processing, or similar projects. Their applications include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text analysis, which is applied to measure the similarity between documents and offers crucial functionality for search engines and information retrieval systems, as shown in the example.&lt;/li&gt;
&lt;li&gt;Recommendation systems, to recommend similar items based on user preferences or to suggest similar users in social network applications. An example is to recommend the next page on product documentation based on the text similarity found. &lt;/li&gt;
&lt;li&gt;Data clustering, which in machine learning acts as a metric to classify or cluster similar data points, and in that way, it helps make data-driven decisions.&lt;/li&gt;
&lt;li&gt;Semantic similarity, which, when paired with word embedding techniques like Word2Vec, is used to determine the semantic similarity between words or documents.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cosine similarity in graph databases
&lt;/h2&gt;

&lt;p&gt;Graph databases are popular for how they represent the relationships between different entities, that is, nodes. These relationships are essential in obtaining information about the similarity between nodes in the database. Nodes can hold multi-dimensional data, like feature vectors or descriptions, and cosine similarity can provide an understanding of node relationships beyond mere structural connections.&lt;/p&gt;

&lt;p&gt;Whether it's about identifying similar user profiles in a social network, detecting similar patterns in a communication network, or classifying nodes in a semantic network, cosine similarity contributes valuable insights. Combined with a powerful graph database system, such as &lt;a href="https://memgraph.com/"&gt;Memgraph&lt;/a&gt;, it gives a better understanding of complex networks. Memgraph is an open-source in-memory graph database built to handle real-time use cases at an enterprise scale. Memgraph supports strongly-consistent ACID transactions and uses the standardized Cypher query language for structuring, manipulating, and exploring data.&lt;/p&gt;

&lt;p&gt;To run cosine similarity in Memgraph, you need to &lt;a href="https://memgraph.com/docs/mage/installation/docker-hub"&gt;install Memgraph with MAGE&lt;/a&gt;, Memgraph Advanced Graph Extensions, an open-source repository that contains graph algorithms and modules written by the team behind Memgraph and its users in the form of query modules. One of the query modules implemented is &lt;a href="https://memgraph.com/docs/mage/query-modules/cpp/node-similarity"&gt;node_similarity&lt;/a&gt;. Within that module, procedures to calculate cosine similarity between two vectors and two sets of vectors can be found. Besides that, there are procedures to calculate the Jaccard and overlap similarity. &lt;/p&gt;

&lt;p&gt;For example, let’s run the cosine_pairwise procedure from the node_similarity module on a simple example. First, run Memgraph with MAGE using the following Docker command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -it -p 7687:7687 -p 7444:7444 memgraph/memgraph-platform&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;The Docker image is called Memgraph Platform since it includes the visual user interface of Memgraph Lab, Memgraph database, and MAGE. Exploring data with Memgraph Lab within Docker container will be easier, rather than just using the command line tool or installing Memgraph Lab separately as a Desktop application. Next, load the dataset by running the following queries in the Memgraph Lab Query Execution tab:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;cypher&lt;br&gt;
CREATE (b:Node {id: 0, score: [1.0, 1.0, 1.0]});&lt;br&gt;
CREATE (b:Node {id: 1, score: [1.0, 1.0, 1.0]});&lt;br&gt;
CREATE (b:Node {id: 2, score: [1.0, 1.0, 1.0]});&lt;br&gt;
CREATE (b:Node {id: 3, score: [1.0, 1.0, 0.0]});&lt;br&gt;
CREATE (b:Node {id: 4, score: [0.0, 1.0, 0.0]});&lt;br&gt;
CREATE (b:Node {id: 5, score: [1.0, 0.0, 1.0]});&lt;br&gt;
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 3}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 4}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 5}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 0}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 1}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 1}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 4}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 5}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 4}) MERGE (b:Node {id: 0}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 4}) MERGE (b:Node {id: 1}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 5}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
MERGE (a:Node {id: 5}) MERGE (b:Node {id: 3}) CREATE (a)-[:RELATION]-&amp;gt;(b);&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you’re not sure how to do that, refer to the &lt;a href="https://memgraph.com/docs/memgraph-lab/user-manual#query-execution"&gt;Memgraph Lab user manual&lt;/a&gt;.&lt;br&gt;
Every node has a score property, a vector of zeros and ones. Execute the following query to run the &lt;code&gt;cosine_pairwise&lt;/code&gt; procedure:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;cypher&lt;br&gt;
MATCH (m)&lt;br&gt;
WHERE m.id &amp;lt; 3&lt;br&gt;
WITH COLLECT(m) AS nodes1&lt;br&gt;
MATCH (n)&lt;br&gt;
WHERE n.id &amp;gt; 2&lt;br&gt;
WITH COLLECT(n) AS nodes2, nodes1&lt;br&gt;
CALL node_similarity.cosine_pairwise("score", nodes1, nodes2) YIELD node1, node2, similarity AS cosine_similarity&lt;br&gt;
RETURN node1, node2, cosine_similarity;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;`&lt;/p&gt;

&lt;p&gt;The above query split all nodes into two lists of equal size and used them as arguments of the &lt;code&gt;cosine_pairwise&lt;/code&gt; procedure. Here is the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fpO9MIKc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/node-result.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fpO9MIKc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/node-result.png" alt="node result" width="754" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The obtained result calculated cosine similarity based on score properties on nodes. We can see that node 0 is as similar to node 3 as node 2 is similar to node 5. Still similar, but a bit less, is node 1 to node 4. &lt;br&gt;
One of the beauties of graph databases is that there are other popular methods to calculate similarities and, in that way, create recommendation systems. One example of using popular node2vec and link prediction algorithms can be found in our blog post on &lt;a href="https://memgraph.com/blog/lost-in-documentation-let-our-docs-recommendation-system-guide-you-along"&gt;how to create a docs recommendation system&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p2a9QRF7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/how-to-create-a-docs-recommendation-system.jpeg" alt="ow to create docs recommendation system" width="800" height="400"&gt;&lt;br&gt;
&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Another interesting example of link prediction with node2vec can be found in how to perform &lt;a href="https://memgraph.com/blog/link-prediction-with-node2vec-in-physics-collaboration-network"&gt;paper recommendations in a physics collaboration network.&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Og9xxNP---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/understanding-cosine-similarity-in-python-with-scikit-learn/paper-recommendations-in-a-physics-collaboration-network1.png" alt="paper recommendations" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Important takeaways
&lt;/h2&gt;

&lt;p&gt;Intuitive interpretation and versatility of the cosine similarity algorithm have found their way into various applications, spanning from text analysis and recommendation systems to complex graph databases. The algorithm's ability to capture the orientation of vectors makes it a robust measure of similarity, especially in high-dimensional spaces.&lt;/p&gt;

&lt;p&gt;Python, being a programming language with an abundant set of libraries like scikit-learn, provides data analysts and machine learning enthusiasts with the tools they need to compute cosine similarity with ease. As we increasingly move towards data-driven decision-making, the ability to measure and interpret similarity becomes more crucial than ever. Undoubtedly, cosine similarity will continue to be a valuable tool in data science.&lt;/p&gt;

&lt;p&gt;If you want to dive into the world of graph analytics to discover even more about data analysis, sign up for Memgraph’s &lt;a href="https://memgraph.com/blog/learn-graph-analytics-with-python"&gt;Graph analytics with Python webinar&lt;/a&gt;. For any questions or just a chat about Python, data science, and graphs, &lt;a href="https://www.discord.gg/memgraph"&gt;join the conversation&lt;/a&gt; on our Discord server.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Use GQLAlchemy Query Builder?</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Wed, 24 May 2023 13:59:18 +0000</pubDate>
      <link>https://forem.com/memgraph/how-to-use-gqlalchemy-query-builder-239g</link>
      <guid>https://forem.com/memgraph/how-to-use-gqlalchemy-query-builder-239g</guid>
      <description>&lt;p&gt;&lt;strong&gt;GQLAlchemy query builder&lt;/strong&gt; will help you build Cypher queries in no time! With&lt;br&gt;
this blog post, you will learn how to use different query builder methods to&lt;br&gt;
create, change, get, set, and remove data from Memgraph.&lt;/p&gt;

&lt;p&gt;You can find the original Jupyter Notebook in our open-source &lt;a href="https://github.com/memgraph/jupyter-memgraph-tutorials"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Set everything up
&lt;/h2&gt;

&lt;p&gt;If you want to try the code from this blog post, make sure to install&lt;br&gt;
&lt;a href="https://docs.docker.com/get-docker/"&gt;Docker&lt;/a&gt; and&lt;br&gt;
&lt;a href="https://pypi.org/project/gqlalchemy/"&gt;GQLAlchemy&lt;/a&gt;. Docker is used because&lt;br&gt;
&lt;strong&gt;Memgraph&lt;/strong&gt; is a native Linux application and can't be installed on Windows and&lt;br&gt;
macOS. After you install Docker, you can set up Memgraph by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 memgraph/memgraph-platform:2.2.6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will start the download and after it finishes, run the Memgraph&lt;br&gt;
container.&lt;/p&gt;

&lt;p&gt;We will be using the &lt;strong&gt;GQLAlchemy&lt;/strong&gt; object graph mapper (OGM) to connect to&lt;br&gt;
Memgraph and execute &lt;strong&gt;Cypher&lt;/strong&gt; queries easily. GQLAlchemy also serves as a&lt;br&gt;
Python driver/client for Memgraph. You can install it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install gqlalchemy==1.2.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;: You may need to install &lt;a href="https://cmake.org/download/"&gt;CMake&lt;/a&gt; before&lt;br&gt;
installing GQLAlchemy.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;gqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Memgraph&lt;/span&gt;

&lt;span class="n"&gt;memgraph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Memgraph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7687&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that Memgraph is empty before starting with anything else. Also, you&lt;br&gt;
should drop all indexes, if there are any, since you'll be creating new ones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drop_database&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drop_indexes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Define graph schema
&lt;/h2&gt;

&lt;p&gt;You will create &lt;strong&gt;Python classes&lt;/strong&gt; that will represent the graph schema. This&lt;br&gt;
way, all the objects that are returned from Memgraph will be of the correct type&lt;br&gt;
if the class definition can be found. That is not a part of the query builder,&lt;br&gt;
but it will help you work with the nodes and relationships.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;gqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Relationship&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Movie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Rated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Relationship&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create nodes and relationships
&lt;/h2&gt;

&lt;p&gt;To return all the variables from a query, just use the &lt;code&gt;return_()&lt;/code&gt; method at the&lt;br&gt;
end of your query. Don't forget to &lt;code&gt;execute()&lt;/code&gt; each query. First, you can create&lt;br&gt;
some users in the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;gqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt;


&lt;span class="n"&gt;ron&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Ron"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ron"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;john&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"john"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;maria&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"maria"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;jenny&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Jenny"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"jenny"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;ian&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Ian"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ian"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ron&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;john&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jenny&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ian&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'ron': &amp;lt;User id=0 labels={'User'} properties={'id': 0, 'name': 'Ron'}&amp;gt;}
{'john': &amp;lt;User id=1 labels={'User'} properties={'id': 1, 'name': 'John'}&amp;gt;}
{'maria': &amp;lt;User id=2 labels={'User'} properties={'id': 2, 'name': 'Maria'}&amp;gt;}
{'jenny': &amp;lt;User id=3 labels={'User'} properties={'id': 3, 'name': 'Jenny'}&amp;gt;}
{'ian': &amp;lt;User id=4 labels={'User'} properties={'id': 4, 'name': 'Ian'}&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a couple of movies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;lotr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"LOTR"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"lotr"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;home_alone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Home Alone"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"home_alone"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;star_wars&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Star Wars"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"star_wars"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;hobbit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Hobbit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hobbit"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Matrix"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"matrix"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="n"&gt;movies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;lotr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;home_alone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;star_wars&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hobbit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;movie&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'lotr': &amp;lt;Movie id=5 labels={'Movie'} properties={'id': 0, 'title': 'LOTR'}&amp;gt;}
{'home_alone': &amp;lt;Movie id=6 labels={'Movie'} properties={'id': 1, 'title': 'Home Alone'}&amp;gt;}
{'star_wars': &amp;lt;Movie id=7 labels={'Movie'} properties={'id': 2, 'title': 'Star Wars'}&amp;gt;}
{'hobbit': &amp;lt;Movie id=8 labels={'Movie'} properties={'id': 3, 'title': 'Hobbit'}&amp;gt;}
{'matrix': &amp;lt;Movie id=9 labels={'Movie'} properties={'id': 4, 'title': 'Matrix'}&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you need to connect users and movies with the &lt;code&gt;RATED&lt;/code&gt; relationship:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;gqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt;

&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;5.0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;3.2&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;4.3&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;5.0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;4.9&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;2.3&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;4.8&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;4.0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check whether the data is correctly imported into Memgraph, you can open&lt;br&gt;
&lt;a href="https://memgraph.com/docs/memgraph-lab/"&gt;&lt;strong&gt;Memgraph Lab&lt;/strong&gt;&lt;/a&gt; on &lt;code&gt;localhost:3000&lt;/code&gt;.&lt;br&gt;
In the query editor, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MATCH (u)-[r]-&amp;gt;(m)
RETURN u, r, m;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll see the imported data visualized as a graph below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S70ALZcJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/memgraph/jupyter-memgraph-tutorials/main/gqlalchemy/query-builder/memgraph-lab-visualization.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S70ALZcJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/memgraph/jupyter-memgraph-tutorials/main/gqlalchemy/query-builder/memgraph-lab-visualization.png" alt="memgraph-lab-visualization" width="800" height="728"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Filter results
&lt;/h2&gt;

&lt;p&gt;You can &lt;strong&gt;filter data by comparing the property of a graph object to a value&lt;/strong&gt;&lt;br&gt;
(a literal). To return only a subset of variables from a query, specify them in&lt;br&gt;
the &lt;code&gt;return()&lt;/code&gt; method. Below you can see how to compare &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;title&lt;/code&gt;&lt;br&gt;
properties of nodes to a string value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u.name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;literal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;and_where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m.title"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;literal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"LOTR"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"u.id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"user_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"m.id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"movie_id"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Maria's id:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"user_id"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"LOTR id:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"movie_id"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Maria's id: 2
LOTR id: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You filtered the data by finding a user with &lt;code&gt;name&lt;/code&gt; Maria, who rated the movie&lt;br&gt;
with &lt;code&gt;title&lt;/code&gt; LOTR.&lt;/p&gt;

&lt;p&gt;You can also negate the expression in &lt;code&gt;WHERE&lt;/code&gt; clause, using the &lt;code&gt;where_not()&lt;/code&gt;&lt;br&gt;
method. Similarly, you have &lt;code&gt;and_not_where()&lt;/code&gt;, &lt;code&gt;or_not_where()&lt;/code&gt; and&lt;br&gt;
&lt;code&gt;xor_not_where()&lt;/code&gt; methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;where_not&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u.name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;literal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;and_where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"m.title"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;literal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"LOTR"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"u.name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"user_name"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"user_name"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ron
John
Ian
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happened above? You filtered the data by finding the names of all users who&lt;br&gt;
are not Maria and who rated the movie LOTR.&lt;/p&gt;

&lt;p&gt;You can also &lt;strong&gt;filter data by comparing properties&lt;/strong&gt; of graph objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"v"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u.name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"!="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"v.name"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"v.name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"user_name"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"user_name"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ron
John
Jenny
Ian
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You found all the users that don't have the property &lt;code&gt;name&lt;/code&gt; set to &lt;code&gt;Maria&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Nodes can also be &lt;strong&gt;filtered by their label&lt;/strong&gt; using the &lt;code&gt;where()&lt;/code&gt; method instead&lt;br&gt;
of specifying it directly in the &lt;code&gt;node()&lt;/code&gt; method of the query builder. You have&lt;br&gt;
to use &lt;code&gt;expression&lt;/code&gt; as the third keyword argument since you want to escape the&lt;br&gt;
quotes surrounding the label in the Cypher clause.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;":"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'u': &amp;lt;Movie id=5 labels={'Movie'} properties={'id': 0, 'title': 'LOTR'}&amp;gt;}
{'u': &amp;lt;Movie id=6 labels={'Movie'} properties={'id': 1, 'title': 'Home Alone'}&amp;gt;}
{'u': &amp;lt;Movie id=7 labels={'Movie'} properties={'id': 2, 'title': 'Star Wars'}&amp;gt;}
{'u': &amp;lt;Movie id=8 labels={'Movie'} properties={'id': 3, 'title': 'Hobbit'}&amp;gt;}
{'u': &amp;lt;Movie id=9 labels={'Movie'} properties={'id': 4, 'title': 'Matrix'}&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above you filtered all nodes in the database by the &lt;code&gt;Movie&lt;/code&gt; label.&lt;/p&gt;

&lt;h2&gt;
  
  
  Call procedures
&lt;/h2&gt;

&lt;p&gt;Let's see which movie is the most important in the network. You can suppose that&lt;br&gt;
the most important movie will be the one that the largest number of users rated.&lt;br&gt;
To order the returned results, use the &lt;code&gt;order_by()&lt;/code&gt; method after the &lt;code&gt;return_()&lt;/code&gt;&lt;br&gt;
method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;gqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;gqlalchemy.query_builder&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt;

&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"pagerank.get"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;yield_&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;with_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"rank"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"rank"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;":"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"node.title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"movie_title"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"rank"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"rank"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"rank"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"movie_title"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"rank"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOTR 0.26900584795321636
Hobbit 0.1
Matrix 0.1
Home Alone 0.09005847953216374
Star Wars 0.09005847953216374
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Delete and remove objects
&lt;/h2&gt;

&lt;p&gt;To &lt;strong&gt;delete a node&lt;/strong&gt; from the database, use the &lt;code&gt;delete()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable_expressions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;detach&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You deleted Ian from the database and the relationships he was connected with.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;delete a relationship&lt;/strong&gt; from the database, again use the &lt;code&gt;delete()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edge_label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"RATED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"r"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Movie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;variable_expressions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"r"&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above you deleted the relationship between Ron and LOTR, that is, it seems like&lt;br&gt;
Ron hasn't rated LOTR.&lt;/p&gt;

&lt;p&gt;To remove a property from the database, use the &lt;code&gt;remove()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"u"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"u.name"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'u': &amp;lt;User id=2 labels={'User'} properties={'id': 2, 'name': None}&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Maria's &lt;code&gt;name&lt;/code&gt; is set to &lt;code&gt;None&lt;/code&gt;, so you can only recognize her by the &lt;code&gt;id&lt;/code&gt;&lt;br&gt;
in the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;Now it's time for you to use Memgraph on a graph problem!&lt;/p&gt;

&lt;p&gt;You can always check out &lt;a href="https://playground.memgraph.com/"&gt;Memgraph Playground&lt;/a&gt;&lt;br&gt;
for some cool use cases and examples. If you need some help with GQLAlchemy,&lt;br&gt;
join our &lt;a href="https://www.discord.gg/memgraph"&gt;Discord&lt;/a&gt; server and have a chat with&lt;br&gt;
us.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://memgraph.com/blog?topics=Python&amp;amp;utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=blog_repost&amp;amp;utm_content=banner#list"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ggEl866K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/external/memgraph-read-more-gradient-1200.png" alt="Read more about Python on memgraph.com" width="800" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Graph Database vs Relational Database</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Mon, 15 May 2023 07:09:51 +0000</pubDate>
      <link>https://forem.com/memgraph/graph-database-vs-relational-database-4cg8</link>
      <guid>https://forem.com/memgraph/graph-database-vs-relational-database-4cg8</guid>
      <description>&lt;p&gt;Choosing the right type of database to store data in is a crucial decision that can impact the success of your personal or company project. Whether you need to decide between using a graph database or a relational database or want to learn about the differences between those two, you've come to the right place.&lt;/p&gt;

&lt;p&gt;In the process of making the best database choice, developers are typically asking themselves several key questions: &lt;em&gt;"Should I choose an open source over a commercial database? How easy is it to integrate the database with my application or manage and maintain the database? Or which database offers the best performance for my particular use case?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To answer these questions, you first need to know what kind of data you are working with, what kind of queries you need to run, how much data you will be storing, how important performance is, and, after all, what your team's expertise is. This blog post will provide answers to those key questions along with discussing valuable examples to make your decision-making around graph database vs relational as easy as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  How is a graph database different from a relational database?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;graph database&lt;/strong&gt; sees the world as we do! It is a type of database that stores data in the form of nodes connected with relationships. &lt;/p&gt;

&lt;p&gt;Graph databases that are based on a labeled-property &lt;strong&gt;graph data model&lt;/strong&gt; consist of four components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Nodes&lt;/strong&gt; - the main entities in a graph. They are also sometimes referred to as vertices or points.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relationships&lt;/strong&gt; - the connections between those entities. Sometimes they are referred to as edges or links. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Labels&lt;/strong&gt; - attributes that group similar nodes together. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Properties&lt;/strong&gt; - key/value pairs stored within nodes or relationships.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nodes and relationships are fundamental components that are used. Labels and properties are often included because of the added functionalities they offer. &lt;/p&gt;

&lt;p&gt;Graph databases mostly use &lt;a href="https://memgraph.com/docs/cypher-manual/cypher-query-language#:~:text=Cypher%20is%20a%20declarative%20query,of%20worrying%20about%20the%20syntax."&gt;Cypher query language&lt;/a&gt; since it is widely adopted, fully specified, and is an open query language for property graph databases. There are other graph query languages out there, but Cypher is the most popular one as it provides an intuitive way of working with property graphs. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relational databases&lt;/strong&gt; store data in tables consisting of rows and columns. Every row is a record, and every column is an attribute of that record. Relational databases are based on a &lt;strong&gt;relational data model&lt;/strong&gt; that requires a predefined and carefully modeled set of tables. Multiple data tables can be related to each other using &lt;strong&gt;primary&lt;/strong&gt; and &lt;strong&gt;foreign keys&lt;/strong&gt;. Primary keys uniquely identify each row in a table, while foreign keys link rows in one table to rows in another table. Relational databases use &lt;strong&gt;Structured Query Language (SQL)&lt;/strong&gt; to query, manage and manipulate data. Relational databases are widely used in applications such as e-commerce, banking, and inventory management systems. &lt;/p&gt;

&lt;p&gt;The image below shows the difference between the graph model and the relational model for the order management dataset. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ILFet0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-graph-database-vs-relational-database.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ILFet0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-graph-database-vs-relational-database.png" alt="graph database vs relational database" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image below, there is another example, a social network graph data model, where the nodes represent people in different social groups and their connections. Every person is represented with a node that’s labeled as Person. These nodes contain the property name, gender, location, and email. The relationships between people in this network are of the type &lt;code&gt;FRIENDS_WITH&lt;/code&gt; and contain a yearsOfFriendship property to specify the duration of the friendship connection. Each person is assigned a location through &lt;code&gt;LIVES_IN&lt;/code&gt; relationships with nodes labeled Location.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nrmhlkrk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-graph-schema.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nrmhlkrk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-graph-schema.png" alt="graph schema" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each person is connected to other people through friendships, and to model this relationship in a relational database, a table needs to be created. If there were different kinds of connections schema would have to be changed accordingly. A relational database isn’t suited for this specific use case because the focus isn’t on the data but on the relationships within it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_5CbAqUb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-relational-schema.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_5CbAqUb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-relational-schema.png" alt="relational schema" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While this is a straightforward example, it concisely demonstrates the power and benefits of using a graph database. In relational databases, a new column must be added for each additional attribute, while with the &lt;strong&gt;flexible graph database schema&lt;/strong&gt;, new properties can be added on the fly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cypher vs SQL query language
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cypher&lt;/strong&gt; is a powerful and flexible query language specifically designed for working with graph databases. Its syntax and functionality make it well-suited for complex queries involving highly connected data - deep hierarchical relationships between data, such as parent-child relationships or many-to-many relationships between different tables. You can think of Cypher as mapping English language sentence structure to patterns in a graph. In most cases, the nouns are nodes of the graph, the verbs are the relationships in the graph, and the adjectives and adverbs are the properties.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MjWqE6aL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-graph-relationships.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MjWqE6aL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-graph-relationships.png" alt="graph relationships" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL&lt;/strong&gt; is a programming language used to manage and manipulate relational databases. It is used to create, modify, and query databases and their tables, as well as to insert, update, and delete data in the tables. It is a standard language used by most relational database management systems, including  &lt;a href="https://www.mysql.com/"&gt;MySQL&lt;/a&gt;, &lt;a href="https://www.oracle.com/database/"&gt;Oracle&lt;/a&gt;, &lt;a href="https://www.microsoft.com/en-us/sql-server?rtc=1"&gt;Microsoft SQL Server&lt;/a&gt;, &lt;a href="https://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt;, and &lt;a href="https://www.sqlite.org/index.html"&gt;SQLite&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The difference between Cypher and SQL can be shown through an example dataset containing the genealogy of some ancient French kings around the 8th century AD from the &lt;a href="https://dev.mysql.com/blog-archive/mysql-8-0-1-recursive-common-table-expressions-in-mysql-ctes-part-four-depth-first-or-breadth-first-traversal-transitive-closure-cycle-avoidance/"&gt;MySQL Blog Archive&lt;/a&gt;. The easiest way to represent the dataset is with a graph:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aKTItSr5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-geneology-of-french-kings.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aKTItSr5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-geneology-of-french-kings.png" alt="geneology of french kings" width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With breadth-first search and depth-first search, it is possible to obtain the descendants in a specific order. Here are the SQL and Cypher queries to find all descendants of Thurimbert:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YLxO3Wd5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-sql-and-cypher-for-thurimbert-descendants.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YLxO3Wd5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/memgraph-sql-and-cypher-for-thurimbert-descendants.png" alt="sql and cypher for thurimbert descendants" width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To run the breadth-first search, that is, find all children, direct descendants first, grouped, use the following queries:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yy16dSTu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/bfs-for-thurimbert-descendants.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yy16dSTu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/bfs-for-thurimbert-descendants.png" alt="image alt" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the other hand, for the depth-first search, use the following queries:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MfunuEYA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/dfs-for-thurimbert-descendants.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MfunuEYA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/graph-vs-relational-database/dfs-for-thurimbert-descendants.png" alt="image alt" width="800" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above dataset is naturally stored as hierarchical or graph data. The great thing about Cypher queries is that they tend to focus on the relationships between nodes in the graph, while SQL queries tend to focus on the columns and rows in tables. Also, path traversals such as breadth-first search and depth-first search are basic queries in Cypher. That’s why these kinds of queries are easier for developers to understand and write in Cypher. Besides that, on a larger scale of data, Cypher queries are more performant than SQL recursive calls for these kinds of use cases. &lt;/p&gt;

&lt;p&gt;Overall, the main differences between Cypher and SQL stem from the different data modeling approaches and optimizations of the graph and relational databases. Cypher is designed to work with graph data and is optimized for queries that involve complex relationships. In contrast, SQL is designed to work with tabular data and is optimized for simpler queries. Compared to SQL, which can have a steep learning curve, Cypher is often easier for developers who are new to graph databases. And it provides an expressive syntax for working with graph data, allowing developers to create complex queries with fewer lines of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use a graph database?
&lt;/h2&gt;

&lt;p&gt;There are always two sides to every story and graph databases aren’t a perfect solution for every problem. Of course, for a bunch of use cases, you should stick with relational databases or maybe search for alternatives other than graph databases.&lt;/p&gt;

&lt;p&gt;To break it down for you, here are three simple questions you can ask yourself to decide if using a graph database has any benefits for your particular use case.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Is my data highly connected?
&lt;/h3&gt;

&lt;p&gt;Graph solutions are focused on highly connected data with an intrinsic need for relationship analysis. In relational databases, complex data relationships arise when data from different tables is related or somehow interconnected. Because data is spread across multiple tables, querying it requires hopping from one table to another and joining it with slow and resource-intensive join operations. The complexity of join operations can increase exponentially as the number of tables increases and as the links between various tables are no longer neatly structured following a clearly set pattern. It is no longer sufficient to join just two or three tables: rather hop through more than seven tables to find the correct link between the data and gain valuable analytics. In that case, graph databases are the solution to go with.&lt;/p&gt;

&lt;p&gt;If the connections within the data are not the primary focus and the data is transactional, then a graph database is probably not the best fit. Sometimes it’s just important to store data and complex analysis isn’t needed.&lt;/p&gt;

&lt;p&gt;In the social network example, without the relationships between people stored, you get a sparsely connected graph. Yes, a number of simpler graphs would remain because of the connections between nodes Person and Location, but this degree of connectedness and the consistency of the data structure is better suited for a relational database.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Is retrieving the data more important to me than storing it?
&lt;/h3&gt;

&lt;p&gt;Graph databases are optimized to retrieve data and they offer the power of &lt;a href="https://memgraph.com/blog/real-time-graph-analytics"&gt;graph analytics&lt;/a&gt; that can help discover hidden patterns in the data that were previously unseen with relational databases.&lt;/p&gt;

&lt;p&gt;In the social network example, if the data is stored only for the sake of logging interactions without analyzing them later on, then a graph database isn’t particularly helpful. However, if there are numerous connections within the data being stored, then a graph might be worth considering. In the mentioned example, you can discover the most important or similar users, predict new connections, and group similar users into communities using &lt;a href="https://memgraph.com/blog/pagerank-algorithm-for-graph-databases"&gt;PageRank&lt;/a&gt;, betweenness centrality, node2vec, or similar graph algorithms.  &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Does my data model change often?
&lt;/h3&gt;

&lt;p&gt;Graph databases are best suited for data models that are inconsistent and demand frequent changes. Because graph databases are more about the data itself than the schema structure, they allow a degree of flexibility.&lt;/p&gt;

&lt;p&gt;On the other hand, there are benefits to having a predefined and consistent table that’s easy to understand. Developers are comfortable and used to relational databases and that fact cannot be downplayed. For example, to store personal information such as names, dates of birth, and locations, without often creating new fields or changing data types, relational databases are the go-to solution.&lt;/p&gt;

&lt;p&gt;A graph database could be useful if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Additional attributes will be added at some point&lt;/li&gt;
&lt;li&gt;Not all entities will have all the attributes in the table&lt;/li&gt;
&lt;li&gt;The attribute types are not strictly defined&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To better understand the &lt;strong&gt;use cases best suited for graph databases&lt;/strong&gt;, here are a couple of examples:&lt;/p&gt;

&lt;h4&gt;
  
  
  Insurance fraud detection
&lt;/h4&gt;

&lt;p&gt;Graph databases help detect anomalies and make the information system more responsive. They allow for unexpected changes in the data structure and enable insurance companies to successfully expand their business as they tap into the insights provided by the recommendations engines (built on top of the data). A graph database is much better in this use case compared to a relational database because graphs perform faster with highly interconnected data. The graph model is flexible. Tight connections and patterns between entities can help design recommendation and &lt;a href="https://memgraph.com/fraud-detection-insurance"&gt;fraud detection systems in insurance&lt;/a&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  Network resource optimization
&lt;/h4&gt;

&lt;p&gt;With a graph database, you can &lt;a href="https://memgraph.com/network-resource-optimization"&gt;manage networks&lt;/a&gt; in the supply chain, chemical engineering, cloud computing, energy systems, and many more industries. Additionally, you can do quantitative analysis, and discover dependencies and critical points in your network so you can prevent obstructions and increase the network's efficiency. With relational databases, visualizing the topology takes around a third of the processing time, while in graph databases, data is automatically joined when it’s being stored, making sure graph traversing is performed in constant time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Identity and access management
&lt;/h4&gt;

&lt;p&gt;Graph databases have dynamic algorithms that analyze only a subset of the graph where changes happen and, in that way, avoid security crises. Besides that, graphs offer fast traversals with BFS or DFS hops due to index-free adjacency. Graphs represent relationships in a semantically rich way, allowing &lt;a href="https://memgraph.com/identity-access-management"&gt;accurate views of access rights&lt;/a&gt; and simplifying their management, which is impossible with a hierarchical structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  When not to use a graph database?
&lt;/h2&gt;

&lt;p&gt;A graph database is only sometimes the perfect solution since it is not well-suited for traversing the whole graph often. While it’s possible to run such queries, other storage solutions may be more optimized for bulk scans. If the majority of the queries in the social network example included searches by property values over the entire network, then a graph database wouldn’t be the right fit.&lt;/p&gt;

&lt;p&gt;Databases are often used to look up information stored in key/value pairs. For example, if the sole purpose of the database is storing the user’s personal information and retrieving it by name or ID, then refrain from using a graph. But if other entities were involved (visited locations for example), and a large number of connections is required to map them to users, then a graph database could bring performance benefits. If most queries return a single node via a simple identifier (key), then skip graph databases. If the entities in the model have very large attributes like BLOBs, CLOBs, and long texts — graph databases aren’t the best solution.&lt;/p&gt;

&lt;p&gt;While those objects can be stored as nodes and linked to other nodes to utilize the power of traversing relationships, sometimes storing them directly with the entities they are connected to makes more sense.&lt;/p&gt;

&lt;p&gt;Again, back to our favorite social network example, if each person had a long biography that needed to be included in the same database, a graph wouldn’t be the answer. However, if you needed to connect these biographies to other entities in the database (for example, people that are mentioned in them), then the strengths of a graph database would outweigh the limitations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;To conclude, both relational and graph databases are powerful tools. Graph databases handle fast-changing interconnected data well, while relational databases shine in managing structured data efficiently and effectively. &lt;/p&gt;

&lt;p&gt;If you are still unsure if a graph database is the right choice for your project, drop us a message in our &lt;a href="https://www.discord.gg/memgraph"&gt;Discord community&lt;/a&gt;. We’ll be happy to address any doubts! Besides that, you can explore the &lt;a href="https://memgraph.com/use-cases"&gt;most common graph use cases&lt;/a&gt; and maybe find the solution for your project on our site. If you are considering different graph database stores, check &lt;a href="https://memgraph.com/memgraph-for-neo4j-developers"&gt;Memgraph’s latest benchmarks&lt;/a&gt; to see how it compares to the other graph solutions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://memgraph.com/blog?topics=Graph+Database+101&amp;amp;utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=blog_repost&amp;amp;utm_content=banner#list"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ggEl866K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-assets.memgraph.com/external/memgraph-read-more-gradient-1200.png" alt="Read more about graph databases on memgraph.com" width="800" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learn Graph Analytics With Python</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Tue, 13 Dec 2022 14:07:24 +0000</pubDate>
      <link>https://forem.com/memgraph/learn-graph-analytics-with-python-2jl1</link>
      <guid>https://forem.com/memgraph/learn-graph-analytics-with-python-2jl1</guid>
      <description>&lt;p&gt;Graphs are a way to represent a network or a collection of interconnected objects formally. There are many powerful tools out there to explore that kind of network by applying graph algorithms. But sometimes it’s hard to keep track of them!&lt;/p&gt;

&lt;p&gt;We have created a brand &lt;strong&gt;new course&lt;/strong&gt; to get you familiar with the graph world. The course is designed for Python developers who want to explore tools for network analysis and see how it’s done hands-on. You will learn what graph algorithms are and hear more about the most popular ones. &lt;/p&gt;

&lt;p&gt;If you are not an experienced Python developer, don’t worry - this course will teach you the basics of graph analytics, and you’ll be able to apply that knowledge whenever you become more familiar with Python. &lt;/p&gt;

&lt;p&gt;The tools which we explored in detail are &lt;strong&gt;NetworkX&lt;/strong&gt;, a Python package for the creation, manipulation and study of the structure dynamics and functions of complex networks. Another tool is called &lt;strong&gt;Memgraph&lt;/strong&gt;, a graph database, through which we’ll explain the benefits of using graph storage. If all of the above sounds intriguing and you don’t want any spoilers, skip this blog and &lt;strong&gt;&lt;a href="https://app.livestorm.co/memgraph/intro-to-graph-analytics-in-python"&gt;sign up for the free course&lt;/a&gt;!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://app.livestorm.co/memgraph/intro-to-graph-analytics-in-python"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sUf9fd31--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bbegaoo0gm3xek9jy23d.jpg" alt="free-course" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hello graph world
&lt;/h2&gt;

&lt;p&gt;Graphs can come in many forms, depending on the tool which implements them. Also, there are different types of graphs depending on the type of data stored inside such objects. You’ll learn the basics of the graph world and hear about graph databases. &lt;/p&gt;

&lt;p&gt;To get insights from the graphs, you need to perform graph analytics. It is essential to understand what kinds of algorithms are out there and when to use them. There are many different graph use cases, and we will discuss the most common ones. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S-b4OXCg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/intro-to-graph-analytics-in-python-course/networkx-course_img1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S-b4OXCg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/intro-to-graph-analytics-in-python-course/networkx-course_img1.png" alt="intro-to-graph-analytics-in-python-course-img-1" width="880" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of that is simple enough in theory, but when you, as a Python developer, actually need to get the most out of your data, it is important to find a tool that is powerful but simple to use. One of the most famous such tools is called NetworkX. &lt;/p&gt;

&lt;h2&gt;
  
  
  NetworkX - a Python graph analytics tool
&lt;/h2&gt;

&lt;p&gt;Through this course, you will have an opportunity to see many code examples explaining NetworkX features. You will see how it’s easy to create a simple graph from scratch, explore it and visualize it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T_ZEsrbj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/intro-to-graph-analytics-in-python-course/networkx-course_img2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T_ZEsrbj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/intro-to-graph-analytics-in-python-course/networkx-course_img2.png" alt="intro-to-graph-analytics-in-python-course-img-2" width="880" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NetworkX comes with included graph algorithms, and it is a tool that many researchers use. Besides all of its advantages, we are going to investigate &lt;a href="https://memgraph.com/blog/data-persistency-large-scale-data-analytics-and-visualizations-biggest-networkx-challenges"&gt;the biggest challenges&lt;/a&gt; when working with big or dynamic graphs regarding &lt;a href="https://memgraph.com/blog/who-ranks-better-memgraph-vs-networkx-pagerank"&gt;analysis speed&lt;/a&gt;, memory consumption and quick visualizations. &lt;/p&gt;

&lt;h2&gt;
  
  
  Memgraph - a Python-friendly graph database
&lt;/h2&gt;

&lt;p&gt;Memgraph offers data persistency, large-scale data analytics and visualizations, so it is an excellent NetworkX alternative. You may ask yourself - why a graph database? We are going to answer that and many other questions in this section of the course. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VrNTrdhS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/intro-to-graph-analytics-in-python-course/networkx-course_img3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VrNTrdhS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/intro-to-graph-analytics-in-python-course/networkx-course_img3.png" alt="image alt" width="880" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But you don’t have to give up on NetworkX to use a graph database totally. With the on hands part of the course, you will see how to transform a NetworkX graph into a Memgraph graph. Besides that, Memgraph holds a set of NetworkX algorithms, along with its own, in a library called MAGE. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Enough spoilers! &lt;a href="https://app.livestorm.co/memgraph/intro-to-graph-analytics-in-python"&gt;Sign up for the free course&lt;/a&gt; and cover all the listed topics and more. After the course, you will be able to brag to all of your LinkedIn friends about how you became a graph master. :) &lt;/p&gt;

</description>
      <category>python</category>
      <category>networkx</category>
      <category>memgraph</category>
      <category>analytics</category>
    </item>
    <item>
      <title>NetworkX Developers, Say Farewell to the Boilerplate Code</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Tue, 22 Nov 2022 08:49:07 +0000</pubDate>
      <link>https://forem.com/memgraph/networkx-developers-say-farewell-to-the-boilerplate-code-1kol</link>
      <guid>https://forem.com/memgraph/networkx-developers-say-farewell-to-the-boilerplate-code-1kol</guid>
      <description>&lt;p&gt;If you are using NetworkX, you are aware of the valuable insights you can get from a data network. These networks, or graphs, are becoming popular in diverse business use cases, where they help make important decisions that affect business success in many ways. &lt;/p&gt;

&lt;p&gt;NetworkX has a large set of interesting graph algorithms, and it can analyze a network of data fast, but only on a certain scale. You might have found yourself wondering how you can stay in a safe world built around NetworkX graph algorithms but still be able to create production-ready applications to share your work with others easily. Maybe you are bored of writing hundreds of lines of code just to get the data you want to explore. &lt;/p&gt;

&lt;p&gt;This blog post will tell you more about how to avoid all of that boilerplate code and smoothly deploy applications by using Memgraph, an open-source in-memory graph database, on which you can perform graph analytics using NetworkX you are familiar with, both on static and streaming datasets. &lt;/p&gt;

&lt;h2&gt;
  
  
  Seamlessly connect to many data sources with Memgraph
&lt;/h2&gt;

&lt;p&gt;The beginning of every NetworkX project includes data import. If you are importing data from different sources, your code is probably snowballing with every additional source. Things are getting messy, and every time you change something in the code, you have to pull the data from all those different sources all over again. The project gets harder to maintain, and your time gets unnecessarily wasted on pulling the data rather than on the actual analysis. &lt;/p&gt;

&lt;p&gt;With Memgraph, you can easily connect to data sources and import the data at the beginning of your project, as well as change it on the fly. Although it is in-memory, Memgraph still persists your data, meaning your dataset doesn’t have to be loaded on each run. It’s enough to load it once and then query, analyze and change it. You can explore parts of the graph you need and deliver an analysis of the dataset. How does Memgraph do it?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z_2b51Mj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/Memgraph-Data-Import.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z_2b51Mj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/Memgraph-Data-Import.png" alt="networkX_developers_say_farewell_to_the_boilerplate_code_img_1" width="880" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Memgraph natively has several methods of data import - import from &lt;a href="https://memgraph.com/docs/memgraph/import-data/files/overview"&gt;files&lt;/a&gt;, &lt;a href="https://memgraph.com/docs/memgraph/import-data/migrate/mysql"&gt;MySQL&lt;/a&gt; or &lt;a href="https://memgraph.com/docs/memgraph/import-data/migrate/postgresql"&gt;PostgreSQL&lt;/a&gt;, and &lt;a href="https://memgraph.com/docs/memgraph/import-data/data-streams/overview"&gt;data streams&lt;/a&gt;. Memgraph is also highly extendable, and with the help of its Python client, &lt;a href="https://github.com/memgraph/gqlalchemy"&gt;GQLAlchemy&lt;/a&gt;, you can import data from almost anywhere. &lt;/p&gt;

&lt;p&gt;GQLAlchemy’s &lt;a href="https://github.com/memgraph/gqlalchemy/blob/main/gqlalchemy/loaders.py"&gt;&lt;code&gt;loaders.py&lt;/code&gt;&lt;/a&gt; translates table data from a file to graph data and imports it into Memgraph. Currently, GQLALchemy supports the reading of CSV, Parquet, ORC, and IPC/Feather/Arrow file formats via the PyArrow package. These files can be loaded from local sources, Azure Blob storage, or Amazon S3 service. Besides that, if you want to read from a file system currently not supported by GQLAlchemy, or read from a different source, you can &lt;a href="https://memgraph.com/docs/gqlalchemy/how-to-guides/custom-file-system-importer"&gt;implement a custom file system importer&lt;/a&gt;, by extending abstract classes &lt;a href="https://github.com/memgraph/gqlalchemy/blob/main/gqlalchemy/loaders.py#L180"&gt;&lt;code&gt;FileSystemHandler&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://github.com/memgraph/gqlalchemy/blob/main/gqlalchemy/loaders.py#L293"&gt;&lt;code&gt;DataLoader&lt;/code&gt;&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Memgraph is especially useful when it comes to importing streaming datasets because it can connect to any Kafka, Pulsar, or Redpanda stream of data. For example, if you are using Debezium in your company to monitor changes in a database, with Memgraph, you can &lt;a href="https://memgraph.com/docs/memgraph/import-data/data-streams/manage-streams-lab"&gt;connect to that Kafka stream&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Since NetworkX algorithms are run on graphs that are currently in-memory, it doesn’t offer the possibility of having a dynamic graph and running dynamic graph algorithms on each change. Memgraph can do that with the help of triggers that fire up dynamic algorithms on a certain change or update in the database. This kind of setup gives you the results of graph algorithms much faster. &lt;a href="https://memgraph.com/docs/mage/algorithms/dynamic-graph-analytics/betweenness-centrality-online-algorithm"&gt;Check out&lt;/a&gt; which dynamic graph algorithms are so far implemented in MAGE, an open-source repository that contains graph algorithms and modules written in Python, C/C++, and Rust.&lt;/p&gt;

&lt;p&gt;So, if your project requires importing streaming or static data from various sources, you don’t have to worry about importing in your NetworkX code. &lt;/p&gt;

&lt;h2&gt;
  
  
  Memgraph and NetworkX integration
&lt;/h2&gt;

&lt;p&gt;NetworkX offers a wide range of graph algorithms to explore the data, and it is possible to use them within Memgraph. Memgraph is built in C++ and it holds wrapper objects for Memgraph’s graphs, called MemgraphGraph, MemgraphDiGraph, MemgraphMultiGraph or MemgraphMultiDiGraph, depending on the graph type stored in the database. &lt;/p&gt;

&lt;p&gt;These objects optimize the usage of NetworkX algorithms. To make the transition to Memgraph more convenient, we implemented procedures that call NetworkX functions with Memgraph graphs so that you have out-of-the-box access to graph algorithms. &lt;/p&gt;

&lt;p&gt;For example, call the &lt;code&gt;betweenness_centrality&lt;/code&gt; algorithm on the preloaded dataset by running: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;CALL nxalg.betweenness_centrality() YIELD *;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://memgraph.com/docs/mage/query-modules/python/nxalg"&gt;Here is a list&lt;/a&gt; of all implemented NetworkX algorithms. To learn more about the usage of NetworkX algorithms in Memgraph, check out the &lt;a href="https://memgraph.com/docs/memgraph/2.4.0/tutorials/social-network-analysis#betweenness-centrality"&gt;Social network analysis with NetworkX tutorial.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cypher query language, used to query Memgraph, is easily extendible with custom procedures bundled up in &lt;a href="https://memgraph.com/docs/memgraph/how-to-guides/query-modules#how-to-implement-custom-query-modules"&gt;query modules&lt;/a&gt;. These procedures can be written in Python, C/C++ and Rust. Inside the custom procedures written in Python you can use the NetworkX library. The easiest way to implement a custom procedure is to use &lt;a href="https://memgraph.com/lab"&gt;Memgraph Lab&lt;/a&gt;, Memgraph’s visual user interface. Just paste the NetworkX code to the custom read or write procedure in the code editor in the &lt;strong&gt;Query Modules&lt;/strong&gt; section of Memgraph Lab. &lt;/p&gt;

&lt;p&gt;To use the custom procedure, call it with the Cypher &lt;code&gt;CALL&lt;/code&gt; clause. Memgraph doesn’t have a custom implementation of the &lt;code&gt;girvan_newman&lt;/code&gt; community algorithm so it can be implemented within the custom read procedure. Just be careful to use the correct graph type, depending on the dataset - Graph, DiGraph, MultiGraph, or MultiDiGraph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EJC6YoYE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EJC6YoYE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_1.png" alt="image alt" width="880" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, &lt;code&gt;MemgraphDiGraph&lt;/code&gt; is created from &lt;code&gt;mgp.ProcCtx&lt;/code&gt;, which represents the whole graph inside the database in its current state. That graph is cast to the NetworkX &lt;code&gt;DiGraph&lt;/code&gt;, so that NetworkX &lt;code&gt;girvan_newman&lt;/code&gt; algorithm can be used. The procedure returns lists of nodes belonging to a certain community. &lt;/p&gt;

&lt;p&gt;To call the above custom procedure, we first need to import a dataset. Many datasets can be found in the &lt;strong&gt;Datasets&lt;/strong&gt; section of the Lab. We are going to query the dataset Karate club friendship network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jaw3abO7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jaw3abO7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_2.png" alt="image alt" width="880" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The query used to call the custom procedure and return its results is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CALL communities.detect()
YIELD communities
UNWIND communities AS community
RETURN community; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are the obtained results on the template dataset Karate club friendship network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zw5BIOtw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zw5BIOtw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_3.png" alt="image alt" width="880" height="322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the standalone NetworkX script, you would first need a bunch of code to pull all the data you want to explore. Then you would call the algorithm, and at the end, the results would have to be stored somewhere. So, to run one simple algorithm, you would have to write A LOT of code. Now multiply that with a couple more data sources and a much more complicated analysis with NetworkX. With Memgraph, you import data or connect to data sources and run your favorite existing or custom graph algorithm. &lt;/p&gt;

&lt;p&gt;For more examples of utilizing NetworkX integration, check out the &lt;a href="https://memgraph.com/docs/memgraph/tutorials/understanding-music-with-modules"&gt;Exploring a musical social network tutorial&lt;/a&gt; on Memgraph documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Share the results of your work easily
&lt;/h2&gt;

&lt;p&gt;NetworkX is not a database, so of course, it is missing other features that come in handy when you are deploying your application. For example, with a graph database, you can always do ad-hoc graph querying. If you are using Memgraph, you also get a set of scalable and production-ready algorithms called MAGE (Memgraph Advanced Graph Extensions). This means that you can have your whole project in one place. &lt;/p&gt;

&lt;p&gt;Dataset is loaded inside Memgraph, you can explore it with Memgraph Lab by querying the database or by running already implemented or custom procedures. It gives you the necessary flexibility while still remaining easy to use and share with others. Your script can hold graph analysis, machine learning projects, simple calculations, and can write back to the database or just read and return the wanted results.&lt;/p&gt;

&lt;p&gt;Your queries can be visualized with Memgraph Lab and sent or presented to your colleagues. Also, if you are deploying your project, you don’t need to worry about the set of components needed for your application to run, you just have to manage Memgraph. &lt;/p&gt;

&lt;p&gt;There are many ways to deploy and manage your project, but to make it easier for you, we &lt;a href="https://memgraph.com/docs/memgraph/reference-guide/deployment/docker"&gt;prepared docker-compose.yml&lt;/a&gt; files necessary to run Memgraph Docker images. Read one our blog posts to learn more about &lt;a href="https://memgraph.com/blog/how-to-orchestrate-your-graph-application-with-docker-compose"&gt;how to orchestrate your graph application with Docker Compose&lt;/a&gt;. If you need Memgraph as a part of your Kubernetes cluster, you can use the &lt;a href="https://memgraph.com/docs/memgraph/reference-guide/deployment/kubernetes"&gt;prepared Helm Chart&lt;/a&gt; for a simple setup. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sBJBFCs7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sBJBFCs7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/networkX_developers%2C_say_farewell_to_the_boilerplate_code/networkX_developers%2C_say_farewell_to_the_boilerplate_code/memgraph-networkX_developers_say_farewell_to_the_boilerplate_code_4.png" alt="image alt" width="880" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Memgraph Lab offers the possibility to save prepared queries in query collections. Memgraph Lab has rich query collections, allowing you to name every query inside the collection and add its description. Also, you can run each query inside the collection to present the results of your work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Memgraph is a drop-in replacement for a huge part of the boilerplate code in the NetworkX project and give relevant insights. It can work with streaming or static datasets and it offers easy integration of any NetworkX code. &lt;/p&gt;

&lt;p&gt;The results provided by Memgraph, in terms of visualization and speed, are incredible and good enough reason to try it out now. Check out &lt;a href="https://dev.to/katelatte/data-persistency-large-scale-data-analytics-and-visualizations-biggest-networkx-challenges-d5f"&gt;how Memgraph deals with data persistency, large-scale data analytics and visualizations when compared to NetworkX&lt;/a&gt; and &lt;a href="https://dev.to/katelatte/who-ranks-better-memgraph-vs-networkx-pagerank-27ag"&gt;how much faster Memgraph graph algorithms are&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To learn more, head over to our &lt;a href="https://memgraph.com/memgraph-for-networkx?utm_source=dev-to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=networkx_ppp&amp;amp;utm_term=say%2Bfarewell%2Bto%2Bboilerplate%2Bcode&amp;amp;utm_content=headovertoresources"&gt;resources&lt;/a&gt; for NetworkX developers.&lt;/p&gt;

</description>
      <category>networkx</category>
      <category>python</category>
      <category>memgraph</category>
      <category>deployment</category>
    </item>
    <item>
      <title>Who ranks better? Memgraph vs NetworkX PageRank</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Tue, 22 Nov 2022 08:42:25 +0000</pubDate>
      <link>https://forem.com/memgraph/who-ranks-better-memgraph-vs-networkx-pagerank-27ag</link>
      <guid>https://forem.com/memgraph/who-ranks-better-memgraph-vs-networkx-pagerank-27ag</guid>
      <description>&lt;p&gt;NetworkX is an impressive tool for many Python developers who enjoy researching data networks. An important part of that research are graph algorithms. There are various graph algorithms out there, and they all perform differently, depending on their implementations and the scale of the dataset being analyzed. NetworkX’s pure Python implementation is easy to use for any Python developer. Still, when it comes to issues with scaling and the need for persistence when working on applications in production, Memgraph saves the day. &lt;/p&gt;

&lt;p&gt;Memgraph is an open-source in-memory graph computation platform for static or real-time graph analytics. It holds a set of highly optimized graph algorithms implemented in C++ and also offers the possibility to create custom procedures in Python, C/C++, or Rust. Read &lt;a href="https://memgraph.com/blog/data-persistency-large-scale-data-analytics-and-visualizations-biggest-networkx-challenges"&gt;how to explore your NetworkX graphs with Memgraph&lt;/a&gt; to understand the benefits of using Memgraph compared to NetworkX.&lt;/p&gt;

&lt;p&gt;One of the most popular graph algorithms is the PageRank algorithm, used initially by Google Search to rank web pages in their search engine results. There are many implementations of PageRank out there, and NetworkX and Memgraph have theirs. Let’s find out which one is faster on a sample dataset!&lt;/p&gt;

&lt;h2&gt;
  
  
  The dataset
&lt;/h2&gt;

&lt;p&gt;Both the NetworkX and Memgraph PageRank can and will be run from Memgraph because in Memgraph the Cypher query language can be expanded with Python procedures. In one of the procedures, we will utilize the NetworkX library. &lt;/p&gt;

&lt;p&gt;Memgraph’s visual interface, &lt;a href="https://memgraph.com/lab"&gt;Memgraph Lab&lt;/a&gt;, has a collection of datasets that can be used for various graph experimentations and explorations. The dataset chosen for this comparison is the Wikipedia articles dataset made out of 78,181 nodes and 310,227 relationships. The Wikipedia articles dataset can be imported into the database from the &lt;strong&gt;Datasets&lt;/strong&gt; section. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VgrjapN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/1-Memgraph-vs-NetworkX-PageRank.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VgrjapN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/1-Memgraph-vs-NetworkX-PageRank.png" alt="Memgraph-vs-NetworkX-PageRank-img-1" width="880" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A graph data model of the Wikipedia articles dataset can be generated in the &lt;strong&gt;Graph Schema&lt;/strong&gt; section to understand better how the nodes and relationships interact with each other in the dataset.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BZo3FY6I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/2-Memgraph-vs-NetworkX-PageRank.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BZo3FY6I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/2-Memgraph-vs-NetworkX-PageRank.png" alt="Memgraph-vs-NetworkX-PageRank-img-2" width="577" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Wikipedia articles dataset is large enough to obtain significant results to compare Memgraph’s and NetworkX’s PageRank algorithms. Comparison can be made on much larger datasets, but NetworkX eats up memory pretty fast, and those kinds of use cases are where Memgraph would, without a question or need for testing, be a better choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom query module
&lt;/h2&gt;

&lt;p&gt;Memgraph is integrated with NetworkX, which means it can transform NetworkX graphs into Memgraph graphs, along with the set of NetworkX algorithms and algorithms that utilize the NetworkX library. NetworkX algorithms inside Memgraph are optimized for the best performance and run on Memgraph DiGraph objects. &lt;/p&gt;

&lt;p&gt;A custom query module allows us to run the NetworkX PageRank algorithm on the NetworkX DiGraph object instead of running it on the Memgraph DiGraph object for a fairer comparison. A custom query module can be developed in the &lt;strong&gt;Query Modules&lt;/strong&gt; section by creating a new module. Names are given per preference, and we called this the query module &lt;code&gt;measure&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mWA8bjfr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/3-Memgraph-vs-NetworkX-PageRank.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mWA8bjfr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/3-Memgraph-vs-NetworkX-PageRank.png" alt="image alt" width="880" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the code for the custom query module used for the comparison:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;mgp&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;networkx&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;nx&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;mgp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_proc&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pagerank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mgp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ProcCtx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;mgp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Record&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;mgp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Vertex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DiGraph&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_nodes_from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;vertices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;vertices&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_edges_from&lt;/span&gt;&lt;span class="p"&gt;([(&lt;/span&gt;&lt;span class="n"&gt;edge&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;from_vertex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edge&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_vertex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;edge&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;in_edges&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="n"&gt;pg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pagerank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1e-05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mgp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Record&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the query module, procedure pagerank extracts a graph from the context and creates an instance of NetworkX DiGraph. Then, the NetworkX PageRank algorithm is run on that DiGraph.&lt;/p&gt;

&lt;p&gt;Procedures from custom query modules are run from the &lt;strong&gt;Query Execution&lt;/strong&gt; section. The &lt;code&gt;pagerank()&lt;/code&gt; procedure from the measure query module is called with the following Cypher query: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;CALL measure.pagerank() YIELD node, rank;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you are interested in developing custom query modules with Memgraph, head to our &lt;a href="https://memgraph.com/docs/memgraph/tutorials/implement-custom-query-module-in-python"&gt;documentation&lt;/a&gt; and learn more about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The comparison
&lt;/h2&gt;

&lt;p&gt;In order to get the best comparison, Memgraph’s &lt;a href="https://memgraph.com/docs/mage/query-modules/cpp/pagerank#getmax_iterations-damping_factor-stop_epsilon"&gt;get()&lt;/a&gt; procedure is called from the &lt;a href="https://memgraph.com/docs/mage/query-modules/cpp/pagerank"&gt;pagerank&lt;/a&gt; module and the custom procedure &lt;code&gt;pagerank()&lt;/code&gt; from the &lt;code&gt;measure&lt;/code&gt; module. The number of return results is limited to 1 because if the results are filtered or not limited, the unnecessary time would be counted in. &lt;/p&gt;

&lt;p&gt;Below are the results for Memgraph’s PageRank on the Wikipedia articles dataset:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y1MLYNTd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/4-Memgraph-vs-NetworkX-PageRank.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y1MLYNTd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/4-Memgraph-vs-NetworkX-PageRank.png" alt="image alt" width="880" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here are the results of NetworkX’s PageRank on the same dataset:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0eeF_xHX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/5-Memgraph-vs-NetworkX-PageRank.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0eeF_xHX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/who-ranks-better-memgraph-vs-networkx-pagerank/5-Memgraph-vs-NetworkX-PageRank.png" alt="image alt" width="880" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memgraph is more than 5 times faster than NetworkX in performing the PageRank algorithm&lt;/strong&gt; on a graph of Wikipedia articles dataset scale (78,181 nodes and 310,227 relationships)! &lt;/p&gt;

&lt;p&gt;It’s important to note that Memgraph outperforms NetworkX on a larger scale without question due to its C++ implementation and highly optimized &lt;a href="https://memgraph.com/docs/memgraph/2.4.0/under-the-hood/storage"&gt;storage memory usage&lt;/a&gt;. PageRank is just one example of a graph algorithm that Memgraph offers out of the box. For more, &lt;a href="https://memgraph.com/docs/mage#browse-the-spellbook-of-query-modules"&gt;check out the list&lt;/a&gt; of available query modules. &lt;/p&gt;

&lt;p&gt;Another thing worth mentioning is that Memgraph supports dynamic graph algorithms, which can speed up the graph analysis even more! For example, with &lt;a href="https://memgraph.com/docs/mage/algorithms/dynamic-graph-analytics/pagerank-online-algorithm"&gt;dynamic PageRank&lt;/a&gt; and a stream of data, Memgraph gives you newly updated results as soon as the graph object is consumed, that is, created in the database. For real-time use cases, such as credit card fraud detection, and that’s where Memgraph shines the best.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Due to its optimized storage memory usage and implementations of graph algorithms in C++, Memgraph handles graph computing on large datasets better than NetworkX, as shown by running PageRank algorithm on a dataset of 78,181 nodes and 310,227 relationships which Memgraph handled 5 times faster than NetworkX. And as the dataset size increases, so does the Memgraph’s speed compared to NetworkX. &lt;/p&gt;

&lt;p&gt;If you want to check more examples and comparisons, head over to the &lt;a href="https://memgraph.com/docs/memgraph/2.4.0/tutorials/understanding-music-with-modules"&gt;music social network tutorial&lt;/a&gt; for betweenness centrality comparison or social network analysis tutorial to learn more about &lt;a href="https://memgraph.com/docs/memgraph/2.4.0/tutorials/social-network-analysis"&gt;community detection&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To learn more, head over to our &lt;a href="https://memgraph.com/memgraph-for-networkx?utm_source=dev-to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=networkx_ppp&amp;amp;utm_term=who%2Branks%2Bbetter&amp;amp;utm_content=headovertoresources"&gt;resources&lt;/a&gt; for NetworkX developers.&lt;/p&gt;

</description>
      <category>networkx</category>
      <category>memgraph</category>
      <category>python</category>
      <category>analytics</category>
    </item>
    <item>
      <title>Data persistency, large-scale data analytics and visualizations - biggest NetworkX challenges</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Tue, 22 Nov 2022 08:37:12 +0000</pubDate>
      <link>https://forem.com/memgraph/data-persistency-large-scale-data-analytics-and-visualizations-biggest-networkx-challenges-d5f</link>
      <guid>https://forem.com/memgraph/data-persistency-large-scale-data-analytics-and-visualizations-biggest-networkx-challenges-d5f</guid>
      <description>&lt;p&gt;If you have been using NetworkX for one of your projects, you’ve probably noticed some of its limitations. Each time you want to change something in the dataset or run another algorithm, you have to load the dataset all over again. This repetitive loading wastes time and slows down the development process, especially for large datasets. &lt;/p&gt;

&lt;p&gt;After running the queries, you probably want to explore the results by playing around with their visualization and share exciting insights you come across. As you probably know, NetworkX is not primarily a graph drawing package, so it doesn’t offer much to create visually pleasing and interactive graphs. Also, NetworkX cannot handle visualizations of large graphs, so you need to reach out for another drawing library and learn how to use it. Even when those libraries are better than NetworkX alone, they still have limitations regarding zooming and interacting with nodes and relationships, such as dragging and clicking.&lt;/p&gt;

&lt;p&gt;Memgraph can offer you data persistence, allow you to run queries and graph algorithms and create visualizations you can interact with and customize, and it is free to use as it’s open source. Read on to find out more. &lt;/p&gt;

&lt;h2&gt;
  
  
  To persist or not persist, that is the question
&lt;/h2&gt;

&lt;p&gt;The issue with NetworkX is that it stores data in-memory in instantiated Python objects - Graph, DiGraph, MultiGraph, or MultiDiGraph. So NetworkX can actually give results of graph algorithms on smaller-scale graphs pretty fast. Still, each time you need to change something in the database or run another algorithm, you have to reload the dataset into the appropriate Python object. What’s even more annoying, if you plan to use your project in production, you need to find an appropriate permanent storage solution and additional graph analytics capabilities. There are a couple of solutions to store the data somewhere else, including exporting and importing those Python objects to different formats or using on-disk storage solutions, but that means more software you need to figure out, which slows down the development process significantly. &lt;/p&gt;

&lt;p&gt;The bottom line is - you like using Python and NetworkX for analyzing graphs as it allows you to harness the power of graphs, but you have reached its limits. Your graph exceeds the memory limit, or the memory gets eaten up as soon as you fire up one of NetworkX’s graph algorithms, or you need a graph data storage that allows you to perform graph analytics quickly. &lt;/p&gt;

&lt;p&gt;Memgraph is, at its core, an in-memory graph database. With Memgraph, you can &lt;strong&gt;import large datasets, store them as graphs&lt;/strong&gt; and &lt;strong&gt;run queries and graph algorithms&lt;/strong&gt;. Although it is an in-memory database, it still has mechanisms that ensure durability, that is, it persists the data. Once you load your data into Memgraph, you can run different graph algorithms and change the database content without wasting time on data re-loading. &lt;/p&gt;

&lt;p&gt;To ease the process of using Memgraph for NetworkX developers, NetworkX graph can be transferred into Memgraph using predefined &lt;a href="https://memgraph.com/docs/gqlalchemy/reference/transformations"&gt;transformations&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Graph analytics on a scale
&lt;/h2&gt;

&lt;p&gt;Although NetworkX is easy to use and fires up quickly, it cannot handle large amounts of data. Many NetworkX graph algorithms, like the Girvan-Newman algorithm, become computationally very expensive on a scale of hundreds of thousands or millions of nodes and relationships. That computational cost comes from a pure Python implementation of NetworkX, and Python implementations are significantly slower than C/C++ implementations.&lt;/p&gt;

&lt;p&gt;Memgraph is built in C++ and holds wrapper objects for Memgraph’s graph, called MemgraphGraph, MemgraphDiGraph, MemgraphMultiGraph, or MemgraphMultiDiGraph, depending on the graph type. Each of the wrapper objects optimizes the usage of NetworkX algorithms. With procedures from the &lt;a href="https://memgraph.com/docs/mage/query-modules/python/nxalg"&gt;nxalg query module&lt;/a&gt; within MAGE, a graph algorithm library, you can call most of the NetworkX algorithms with Memgraph graphs. If an algorithm you require isn’t available, the MAGE &lt;a href="https://github.com/memgraph/mage/tree/main/python"&gt;project&lt;/a&gt; is open-sourced, so you are more than welcome to contribute. &lt;/p&gt;

&lt;p&gt;The library also holds implementations of the &lt;a href="https://memgraph.com/docs/mage/query-modules/python/graph-analyzer"&gt;graph analyzer&lt;/a&gt; and &lt;a href="https://memgraph.com/docs/mage/query-modules/cpp/weakly-connected-components"&gt;weakly connected components&lt;/a&gt; which utilize the NetworkX library. All in all, even though you switch to an environment, all the familiar algorithms are still available. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y8G0b99H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/1_Explore_NetworkX_graphs_with_Memgraph_Lab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y8G0b99H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/1_Explore_NetworkX_graphs_with_Memgraph_Lab.png" alt="Explore_NetworkX_graphs_with_Memgraph_Lab_1" width="880" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you get used to query modules, utilize Memgraph’s graph algorithms as well. Most of the algorithms are implemented in C++ and heavily optimized to offer the best possible performance, meaning that in most cases, they outperform NetworkX algorithms. &lt;/p&gt;

&lt;p&gt;Besides standard implementations of algorithms, Memgraph also offers &lt;a href="https://memgraph.com/docs/mage/algorithms/dynamic-graph-analytics/pagerank-online-algorithm"&gt;dynamic graph algorithms&lt;/a&gt;, which allow you to analyze the data during ingestion instead of waiting for the long imports of massive datasets. If you have a data stream, you can consume it with Memgraph and trigger dynamic graph algorithm updates on each change. The dynamic graph algorithm approximates values locally around the updated node and propagates them through the whole graph. New values are received much faster, and that speeds up the decision time in time-sensitive use cases. &lt;/p&gt;

&lt;p&gt;If the algorithms and procedures above don’t cover your use case, you can always implement your custom graph algorithms in Python by &lt;a href="https://memgraph.com/docs/memgraph/tutorials/implement-custom-query-module-in-python"&gt;creating your own query modules and procedures&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Drawing large graphs with Memgraph Lab
&lt;/h2&gt;

&lt;p&gt;NetworkX isn’t primarily a graph drawing package, but it does offer basic drawing with Matplotlib and an interface for Graphviz. If your research requires drawing graphs that consist of tens of thousands of nodes and relationships, you’ll probably experience several nervous breakdowns waiting for the visualization to complete. You can utilize other tools, but they all have limited usage, so not every tool will fit the use case you are working on, and there is no end to learning every new tool from scratch. &lt;/p&gt;

&lt;p&gt;Memgraph Lab is a visual user interface that can also render graphs. It uses an open-source visualization library called &lt;a href="https://github.com/memgraph/orb"&gt;Orb&lt;/a&gt;, which allows the implementation of visualizations in the frontend code. The visualizations are adaptable and customizable using a graph-style editor defined by the &lt;a href="https://memgraph.com/docs/memgraph-lab/graph-style-script-language"&gt;GSS language&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Check out how Orb and Memgraph Lab visualize 32,436 nodes and 122,920 relationships:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yWZhZHOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/2_Explore_NetworkX_graphs_with_Memgraph_Lab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yWZhZHOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/2_Explore_NetworkX_graphs_with_Memgraph_Lab.png" alt="Explore_NetworkX_graphs_with_Memgraph_Lab_2" width="880" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Graphs can also be interacted with. Clicking on graph objects previews their details, such as labels and properties. Nodes can be expanded to show relationships, collapsed to hide them, or dragged around to visualize the story you want the data to tell. If you need objects to interact, you can enable physics and adjust the collision or repulsive forces within the graph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---J-kpUfe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/3_Explore_NetworkX_graphs_with_Memgraph_Lab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---J-kpUfe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/3_Explore_NetworkX_graphs_with_Memgraph_Lab.png" alt="Explore_NetworkX_graphs_with_Memgraph_Lab_3" width="744" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above visualizations show the default style, but if you decide to tweak it with the Graph Style Script, you can create any kind of visualization that best represents your data. In the image below, nodes are of different sizes and colors, depending on their ranks and the communities they belong to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dAFv2kRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/4_Explore_NetworkX_graphs_with_Memgraph_Lab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dAFv2kRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/explore-networkx-graphs-with-memgraph-lab/4_Explore_NetworkX_graphs_with_Memgraph_Lab.png" alt="Explore_NetworkX_graphs_with_Memgraph_Lab_4" width="880" height="736"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you like using NetworkX as a graph analytic tool required for your project but often need to reach for other tools, remember that Memgraph can speed up your development by being persistent in-memory data storage. You still get to use the NetworkX algorithms you are used to or explore other, more efficient, and dynamic algorithms. &lt;br&gt;
If default and implemented algorithms and procedures do not cover your use case, extend the Cypher query language with custom procedures.&lt;/p&gt;

&lt;p&gt;In the end, a visualization tool is also a part of the Memgraph package, so there is no more need to explore other solutions. Feel free to shape the graph results so they reflect the insights you discovered in the best possible way. Once the project is ready for production, you only need to handle the Memgraph deployment to ship your app easily and show your hard work to other graphistas out there, without writing any boilerplate code! &lt;/p&gt;

&lt;p&gt;To learn more, head over to our &lt;a href="https://memgraph.com/memgraph-for-networkx?utm_source=dev-to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=networkx_ppp&amp;amp;utm_term=biggest%2Bnetworkx%2Bchallenges&amp;amp;utm_content=headovertoresources"&gt;resources&lt;/a&gt; for NetworkX developers.&lt;/p&gt;

</description>
      <category>networkx</category>
      <category>python</category>
      <category>memgraph</category>
      <category>analytics</category>
    </item>
    <item>
      <title>How to orchestrate your graph application with Docker Compose</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Thu, 27 Oct 2022 11:43:46 +0000</pubDate>
      <link>https://forem.com/memgraph/how-to-orchestrate-your-graph-application-with-docker-compose-33b3</link>
      <guid>https://forem.com/memgraph/how-to-orchestrate-your-graph-application-with-docker-compose-33b3</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Docker&lt;/strong&gt; is an open platform for developing, shipping, and running applications. It helps you package and run an application in an isolated environment called a container. The container has everything needed to run the application, including the libraries that now don’t have to be installed on host machines. The Dockerized application is easy to share with someone and to run because it will work in the same way on different hosts. &lt;strong&gt;Docker Compose&lt;/strong&gt; is a tool for defining and running multi-container Docker applications. All you need is a YAML file called &lt;code&gt;docker-compose.yml&lt;/code&gt; in the root of your project in order to configure the application’s services. &lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying applications with Docker Compose
&lt;/h2&gt;

&lt;p&gt;Docker Compose can be used for production, staging, development, testing, or CI workflow environments. In Memgraph, we create many demo web applications to showcase Memgraph’s capabilities. When creating such applications, we follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; We create a Dockerfile to define a Docker image that will be used, copy certain directories and install necessary libraries inside the container. The application usually has a backend, frontend, and Memgraph (database) service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-application
├── backend
│   ├── app.py
│   └── Dockerfile
├── frontend
│   ├── src
│   │   └── App.js
│   └── Dockerfile
├── memgraph
│   └── Dockerfile
└── docker-compose.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For &lt;code&gt;memgraph&lt;/code&gt; service Dockerfile, we often copy the folder with newly defined procedures, called query modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM memgraph/memgraph-mage:1.1
USER root
# Copy the local query modules
COPY query_modules/twitch.py /usr/lib/memgraph/query_modules/twitch.py
USER memgraph
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we used &lt;code&gt;memgraph/memgraph-mage&lt;/code&gt; image, version &lt;code&gt;1.1.&lt;/code&gt; We switched to user root so that the service within the container has the necessary permissions to copy the local query modules file and then gave the permissions back to the user &lt;code&gt;memgraph&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Next, we define all services from the application in the &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3"

networks:
 app-tier:
   driver: bridge

memgraph:
   build: ./memgraph
​​   ports:
     - "7687:7687"
     - "7444:7444"
   networks:
     - app-tier

backend-app:
   build: ./backend
   volumes:
     - ./backend:/app
   ports:
     - "5000:5000"
   networks:
     - app-tier

frontend-app:
   build: ./frontend
   volumes:
     - ./frontend:/app
   ports:
     - "3000:3000"
   networks:
     - app-tier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every service is running on different ports and copies different necessary files from the host machine to the container in its Dockerfile. For example, if the &lt;code&gt;frontend&lt;/code&gt; service is a React app, you need to copy the &lt;code&gt;package.json&lt;/code&gt; file and run &lt;code&gt;npm install&lt;/code&gt; to install all packages and dependencies needed for the React app to run. All services are on the same &lt;code&gt;app-tier&lt;/code&gt; bridge network. A bridge network allows containers connected to the same bridge network, &lt;code&gt;app-tier&lt;/code&gt; in this case, to communicate while providing isolation from containers that are not connected to that bridge network. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; In the end, to build the application, we use &lt;code&gt;docker-compose build&lt;/code&gt;, and to run it, we use &lt;code&gt;docker-compose up&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Once you define your application with Docker Compose, it’s pretty easy to run it in different environments. Before deploying it, you need to make just a couple of changes regarding the volume bindings, exposed ports, and similar. If you want to learn more about it, check out the &lt;a href="https://docs.docker.com/compose/production/"&gt;Docker documentation&lt;/a&gt;. The easiest way to deploy the application is to run it on a single server since that is the most similar behavior to your development environment. &lt;/p&gt;

&lt;h2&gt;
  
  
  Memgraph Docker Compose file
&lt;/h2&gt;

&lt;p&gt;Let’s check out what’s written inside the  Memgraph Docker Compose file. Memgraph offers you three different Docker images:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Memgraph Platform&lt;/strong&gt;, which contains:

&lt;ul&gt;
&lt;li&gt;MemgraphDB - the database that holds your data&lt;/li&gt;
&lt;li&gt;Memgraph Lab - visual user interface for running queries and visualizing graph data&lt;/li&gt;
&lt;li&gt;mgconsole - command-line interface for running queries&lt;/li&gt;
&lt;li&gt;MAGE - graph algorithms and modules library&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memgraph MAGE&lt;/strong&gt;, which contains MemgraphDB and MAGE.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memgraph&lt;/strong&gt;, which includes only MemgraphDB.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Definition of a Memgraph service within your &lt;code&gt;docker-compose.yml&lt;/code&gt; file depends on the image you are using. Since Memgraph Platform provides a wholesome solution, its image is most widely used. This is the Docker Compose for Memgraph Platform image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3"
services:
  memgraph-platform:
    image: "memgraph/memgraph-platform"
    ports:
      - "7687:7687"
      - "3000:3000"
      - "7444:7444"
    volumes:
      - mg_lib:/var/lib/memgraph
      - mg_log:/var/log/memgraph
      - mg_etc:/etc/memgraph
    environment:
      - MEMGRAPH="--log-level=TRACE"
    entrypoint: ["/usr/bin/supervisord"]
volumes:
  mg_lib:
  mg_log:
  mg_etc:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Port &lt;code&gt;7687&lt;/code&gt; is used for communication with Memgraph via Bolt protocol. The port &lt;code&gt;3000&lt;/code&gt; is exposed because Memgraph Lab will be running on &lt;code&gt;localhost:3000&lt;/code&gt;, while the port &lt;code&gt;7444&lt;/code&gt; is there so that you can access logs within Memgraph Lab. We also specified three useful volumes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mg_lib&lt;/code&gt; - directory containing data that enables data persistency&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mg_log&lt;/code&gt; - directory containing log files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mg_etc&lt;/code&gt; - directory containing the configuration file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The exact location of the local directories depends on your specific setup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://memgraph.com/docs/memgraph/next/reference-guide/configuration"&gt;Configuration settings&lt;/a&gt; can be changed by setting the value of the &lt;code&gt;MEMGRAPH&lt;/code&gt; environment variable. In the above example, you can see how to set &lt;code&gt;--log-level&lt;/code&gt; to &lt;code&gt;TRACE&lt;/code&gt;. Since Memgraph Platform is not a single service, the process manager &lt;a href="https://docs.docker.com/config/containers/multi-service_container/"&gt;supervisord&lt;/a&gt; is used as the main running process in the &lt;code&gt;entrypoint&lt;/code&gt;. Since the MAGE library is included in this image, you can use the available graph algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we built Twitch analytics demo using Docker Compose
&lt;/h2&gt;

&lt;p&gt;When we’re building demo applications to showcase Memgraph, we always use Docker Compose. This allows us to fire up the application on any system, which is useful when showing a demo at conferences or meetups. Also, applications created with Docker Compose are much easier to deploy. One such demo is the &lt;a href="https://github.com/memgraph/twitch-analytics-demo"&gt;Twitch analytics demo&lt;/a&gt;. In the &lt;a href="https://github.com/memgraph/twitch-analytics-demo/blob/main/docker-compose.yml"&gt;docker-compose.yml&lt;/a&gt; file, we defined a couple of services: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;kafka&lt;/code&gt; - a message broker&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;zookeeper&lt;/code&gt; - a service that manages &lt;code&gt;kafka&lt;/code&gt; service&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;memgraph-mage&lt;/code&gt; - a service that uses Memgraph MAGE Docker image which gives us the possibility to use graph algorithms, such as PageRank and betweenness centrality&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;twitch-app&lt;/code&gt; - a Flask server that sends all the data we query from &lt;code&gt;memgraph-mage&lt;/code&gt; to the &lt;code&gt;react-app&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;react-app&lt;/code&gt; - a React app that visualizes the Twitch network &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;twitch-stream&lt;/code&gt; - a Python script that produces new messages to a Kafka topic &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4N8kz67--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/twitch-streaming-graph-analysis/memgraph-tutorial-twitch-app-architecture.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4N8kz67--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://public-assets.memgraph.com/twitch-streaming-graph-analysis/memgraph-tutorial-twitch-app-architecture.png" alt="Memgraph - How we built Twitch analytics demo using Docker Compose&amp;lt;br&amp;gt;
" width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As mentioned before, all services are on the same app-tier bridge network to communicate with each other. To learn more about the implementation of this application, head over to the &lt;a href="https://dev.to/katelatte/series/15209"&gt;Twitch Streaming Graph Analysis&lt;/a&gt; blog post series.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now that you learned how to use Docker Compose to orchestrate your graph application, we hope that the application development process with Memgraph will be more straightforward. Whichever Memgraph Docker image you decide to use, &lt;a href="https://discord.gg/memgraph"&gt;join our Discord server&lt;/a&gt; and showcase your creations!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>memgraph</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>How to migrate from Neo4j to Memgraph</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Thu, 17 Mar 2022 10:53:14 +0000</pubDate>
      <link>https://forem.com/memgraph/how-to-migrate-from-neo4j-to-memgraph-efc</link>
      <guid>https://forem.com/memgraph/how-to-migrate-from-neo4j-to-memgraph-efc</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Through this tutorial, you'll learn how to migrate the movies dataset from Neo4j to Memgraph. If you used Neo4j, you are probably familiar with their example graph that helps you learn the basics of the Cypher query language. &lt;strong&gt;Neo4j&lt;/strong&gt; is an ACID-compliant transactional native graph database, while &lt;strong&gt;Memgraph&lt;/strong&gt; is a platform designed for graph computations on streaming data. You can read more about their differences in the &lt;a href="https://memgraph.com/blog/neo4j-vs-memgraph" rel="noopener noreferrer"&gt;Neo4j vs Memgraph article&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://docs.docker.com/get-started/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;/strong&gt; (Linux) or &lt;strong&gt;Docker Desktop&lt;/strong&gt; (macOS/Windows) - you will run Memgraph and Neo4j in a Docker container&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Neo4j&lt;/strong&gt; with &lt;strong&gt;APOC&lt;/strong&gt; - in this tutorial, you'll use the &lt;a href="https://neo4j.com/labs/apoc/4.1/export/csv/#export-database-csv" rel="noopener noreferrer"&gt;&lt;code&gt;apoc.export.csv.all()&lt;/code&gt;&lt;/a&gt; procedure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://memgraph.com/download/#memgraph-platform" rel="noopener noreferrer"&gt;Memgraph&lt;/a&gt;&lt;/strong&gt; - you are going to import your data using the &lt;code&gt;LOAD CSV&lt;/code&gt; clause.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Run Neo4j and Memgraph
&lt;/h2&gt;

&lt;p&gt;You need to start &lt;strong&gt;Neo4j with APOC&lt;/strong&gt;, and you can do that by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -p 7474:7474 -p 7687:7687 \
-v data:/data -v  plugins:/plugins --name neo4j-apoc \ 
-e NEO4J_apoc_export_file_enabled=true \ 
-e NEO4J_apoc_import_file_enabled=true \ 
-e NEO4J_apoc_import_file_use__neo4j__config=true \ 
-e NEO4JLABS_PLUGINS=\[\"apoc\"\] \  
-e NEO4J_AUTH=neo4j/password neo4j:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If you're having trouble running this on the new Apple M1 chip, try adding &lt;code&gt;--platform linux/arm64/v8&lt;/code&gt; after the run command. Also, you can set &lt;code&gt;NEO4J_AUTH&lt;/code&gt; however you like, here &lt;code&gt;neo4j&lt;/code&gt; is username and &lt;code&gt;password&lt;/code&gt; is password.&lt;br&gt;
The Neo4j Browser is available at &lt;code&gt;http://localhost:7474&lt;/code&gt;, and you can use the credentials from the &lt;code&gt;NEO4J_AUTH&lt;/code&gt; environment variable. The ports 7474 and 7687 are now exposed, and since Memgraph also uses port 7687, you can run it at the next available port, that is, 7688:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it -p 7688:7687 -p 3000:3000 -v mg_lib:/var/lib/memgraph memgraph/memgraph-platform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since you started &lt;strong&gt;Memgraph Platform&lt;/strong&gt;, the command-line tool &lt;strong&gt;mgconsole&lt;/strong&gt; should be open in your terminal, and the visual user interface &lt;strong&gt;Memgraph Lab&lt;/strong&gt; is available at &lt;code&gt;http://localhost:3000&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Great, now you have both databases running and you're ready to play with the movies dataset!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Load the movies dataset into Neo4j
&lt;/h2&gt;

&lt;p&gt;The movies dataset contains actors and directors that are related through the movies they've collaborated on. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fmovies-dataset-model.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fmovies-dataset-model.png" alt="movies-dataset-graph-model"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a simple dataset and a good example of how you can migrate the whole graph database from Neo4j to Memgraph. You can import it to Neo4j by running the &lt;strong&gt;Movie Graph&lt;/strong&gt; example from &lt;strong&gt;Example Graphs&lt;/strong&gt; in the Neo4j Browser or Desktop app. Once the movie dataset is loaded into Neo4j, you can jump to exporting the whole database.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Export the movies dataset from Neo4j
&lt;/h2&gt;

&lt;p&gt;You are going to export the whole database from Neo4j to a CSV file &lt;code&gt;movies.csv&lt;/code&gt; by using the &lt;code&gt;apoc.export.csv.all()&lt;/code&gt; procedure. Through the Neo4j Browser (or Desktop app), run the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CALL apoc.export.csv.all("movies.csv", {})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have exported the whole database to the &lt;code&gt;movies.csv&lt;/code&gt; file. But where is this file located? Since you ran both Neo4j and Memgraph with Docker, files you are exporting or importing are located inside the Docker container. To enter the container, you first must find out the container ID of the container where Neo4j is running. Run &lt;code&gt;docker ps&lt;/code&gt; to check all the running containers. There you can find the Neo4j container ID and copy it. After that, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker exec -it &amp;lt;container_ID&amp;gt; bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you run the above command, you are inside the container where Neo4j is running. All exported data is located at &lt;code&gt;/var/lib/neo4j/import/&lt;/code&gt;. Hence, run &lt;code&gt;cd /var/lib/neo4j/import/&lt;/code&gt; to check whether the &lt;code&gt;movies.csv&lt;/code&gt; file is there. Next, you are going to copy the &lt;code&gt;movies.csv&lt;/code&gt; file to your local file system. To do that, you need to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker cp &amp;lt;container_ID&amp;gt;:/var/lib/neo4j/import/movies.csv /path_to_local_folder/movies.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;container_ID&amp;gt;&lt;/code&gt; is the ID of the Neo4j container, which you already found before. On the right, you can give the path to one of your local folders where you want the &lt;code&gt;movies.csv&lt;/code&gt; file to be copied to.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Import the movies dataset into Memgraph
&lt;/h2&gt;

&lt;p&gt;After you have exported the whole database from Neo4j into the &lt;code&gt;movies.csv&lt;/code&gt; file and copied it to your local file system, you are ready to import the movies dataset into Memgraph. First, you have to copy the &lt;code&gt;movies.csv&lt;/code&gt; file to the Docker container where Memgraph is running. Here's what you have to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;docker ps&lt;/code&gt; to find out Memgraph's container ID&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;docker cp /path_to_local_folder/movies.csv &amp;lt;container_ID&amp;gt;:/usr/lib/memgraph/movies.csv&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now the &lt;code&gt;movies.csv&lt;/code&gt; file is ready to be imported to Memgraph with the &lt;code&gt;LOAD CSV&lt;/code&gt; clause.&lt;br&gt;
First, you need to import all nodes, and after that, relationships. In order to create the relationships, start and end nodes have to already be in the database, and that's why you are importing in that order.&lt;/p&gt;

&lt;p&gt;You can write the queries in the &lt;strong&gt;mgconsole&lt;/strong&gt;, a command-line tool, or in the query editor in the &lt;strong&gt;Memgraph Lab&lt;/strong&gt;. Memgraph Lab is more user-friendly, so I would recommend this way of querying. To connect to Memgraph from Memgraph Lab, you will have to choose the &lt;code&gt;Connect manually&lt;/code&gt; option, since the port on which Memgraph is running is not the default one (7687). Once you choose &lt;code&gt;Connect manually&lt;/code&gt;, you just have to change the port to 7688 and click &lt;code&gt;Connect&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To create all &lt;code&gt;Person&lt;/code&gt; nodes, copy the following query in the query editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;':Person'&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;:Person&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._id&lt;/span&gt;&lt;span class="ss"&gt;,&lt;/span&gt; &lt;span class="py"&gt;name:&lt;/span&gt; &lt;span class="n"&gt;row.name&lt;/span&gt;&lt;span class="ss"&gt;,&lt;/span&gt; &lt;span class="py"&gt;born:&lt;/span&gt; &lt;span class="n"&gt;row.born&lt;/span&gt;&lt;span class="ss"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;movies.csv&lt;/code&gt; file, the column &lt;code&gt;_labels&lt;/code&gt; is empty if the data in the row represents a relationship. If the row is a node, then the column &lt;code&gt;_labels&lt;/code&gt; contains the label of that node. Hence, you can create the &lt;code&gt;Person&lt;/code&gt; nodes by going through the &lt;code&gt;_labels&lt;/code&gt; column. Every person has the properties &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;born&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In a similar way, you can create the &lt;code&gt;Movie&lt;/code&gt; nodes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;':Movie'&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;:Movie&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._id&lt;/span&gt;&lt;span class="ss"&gt;,&lt;/span&gt; &lt;span class="py"&gt;relased:&lt;/span&gt; &lt;span class="n"&gt;row.released&lt;/span&gt;&lt;span class="ss"&gt;,&lt;/span&gt; &lt;span class="py"&gt;tagline:&lt;/span&gt; &lt;span class="n"&gt;row.tagline&lt;/span&gt;&lt;span class="ss"&gt;,&lt;/span&gt; &lt;span class="py"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;row.title&lt;/span&gt;&lt;span class="ss"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can check whether you created all nodes correctly. First, in the &lt;strong&gt;Overview tab&lt;/strong&gt;, you can see that the number of nodes is 171, and it matches the number of nodes in Neo4j. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fmemgraph-lab-overview-nodes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fmemgraph-lab-overview-nodes.png" alt="memgraph-lab-overview-node"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, you can import the relationships. There are 6 different types of relationships, some have properties and some don't. It's best to import them one by one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Import ACTED_IN relationship&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'ACTED_IN'&lt;/span&gt;
&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._start&lt;/span&gt;&lt;span class="ss"&gt;}),&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._end&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ss"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;:ACTED_IN&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;roles:&lt;/span&gt; &lt;span class="n"&gt;row.roles&lt;/span&gt;&lt;span class="ss"&gt;}]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="ss"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Import DIRECTED relationship&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'DIRECTED'&lt;/span&gt;
&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._start&lt;/span&gt;&lt;span class="ss"&gt;}),&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._end&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ss"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;:DIRECTED&lt;/span&gt;&lt;span class="ss"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="ss"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Import PRODUCED relationship&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'PRODUCED'&lt;/span&gt;
&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._start&lt;/span&gt;&lt;span class="ss"&gt;}),&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._end&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ss"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;:PRODUCED&lt;/span&gt;&lt;span class="ss"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="ss"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Import WROTE relationship&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'WROTE'&lt;/span&gt;
&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._start&lt;/span&gt;&lt;span class="ss"&gt;}),&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._end&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ss"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;:WROTE&lt;/span&gt;&lt;span class="ss"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="ss"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Import FOLLOWS relationship&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'FOLLOWS'&lt;/span&gt;
&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._start&lt;/span&gt;&lt;span class="ss"&gt;}),&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._end&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ss"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;:FOLLOWS&lt;/span&gt;&lt;span class="ss"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="ss"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Import REVIEWED relationship&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;LOAD&lt;/span&gt; &lt;span class="k"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="s2"&gt;"/usr/lib/memgraph/movies.csv"&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;HEADER&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;row._type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'REVIEWED'&lt;/span&gt;
&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._start&lt;/span&gt;&lt;span class="ss"&gt;}),&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;id:&lt;/span&gt; &lt;span class="n"&gt;row._end&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ss"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;:REVIEWED&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;rating:&lt;/span&gt; &lt;span class="n"&gt;row.rating&lt;/span&gt;&lt;span class="ss"&gt;,&lt;/span&gt; &lt;span class="py"&gt;summary:&lt;/span&gt; &lt;span class="n"&gt;row.summary&lt;/span&gt;&lt;span class="ss"&gt;}]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="ss"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can check again that the number of relationships in the &lt;strong&gt;Overview tab&lt;/strong&gt; in Memgraph Lab is the same as in Neo4j.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fmemgraph-lab-overview-relationships.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fmemgraph-lab-overview-relationships.png" alt="memgraph-lab-overview-relationships"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's it! You have migrated the whole movies dataset from Neo4j to Memgraph.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Explore the data
&lt;/h2&gt;

&lt;p&gt;You can run a couple of example queries from the Neo4j and compare them with the results in Memgraph, to make sure you did everything right. &lt;/p&gt;

&lt;p&gt;For example, run the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tom&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;name:&lt;/span&gt; &lt;span class="s2"&gt;"Tom Hanks"&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt; &lt;span class="k"&gt;RETURN&lt;/span&gt; &lt;span class="n"&gt;tom&lt;/span&gt;&lt;span class="ss"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and check the results:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Ffirst-query-neo4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Ffirst-query-neo4j.png" alt="first-query-neo4j"&gt;&lt;/a&gt;&lt;/p&gt;
Results in Neo4j





&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Ffirst-query-memgraph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Ffirst-query-memgraph.png" alt="first-query-memgraph"&gt;&lt;/a&gt;&lt;/p&gt;
Results in Memgraph





&lt;p&gt;Next, you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cloudAtlas&lt;/span&gt; &lt;span class="ss"&gt;{&lt;/span&gt;&lt;span class="py"&gt;title:&lt;/span&gt; &lt;span class="s2"&gt;"Cloud Atlas"&lt;/span&gt;&lt;span class="ss"&gt;})&lt;/span&gt; &lt;span class="k"&gt;RETURN&lt;/span&gt; &lt;span class="n"&gt;cloudAtlas&lt;/span&gt;&lt;span class="ss"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and check the results:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fsecond-query-neo4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fsecond-query-neo4j.png" alt="second-query-neo4j"&gt;&lt;/a&gt;&lt;/p&gt;
Results in Neo4j





&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fsecond-query-memgraph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpublic-assets.memgraph.com%2Fhow-to-migrate-from-neo4j-to-memgraph%2Fsecond-query-memgraph.png" alt="second-query-memgraph"&gt;&lt;/a&gt;&lt;/p&gt;
Results in Memgraph





&lt;p&gt;Feel free to try out a different set of queries and make sure that the results are the same in Neo4j and Memgraph.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's it for now! You've learned how to migrate the whole database from Neo4j to Memgraph. In this tutorial, you used the &lt;code&gt;apoc.export.csv.all()&lt;/code&gt; procedure to export the data from Neo4j and the &lt;code&gt;LOAD CSV&lt;/code&gt; clause to import the data to Memgraph. This is not the only way to migrate your data from Neo4j to Memgraph. If you feel creative and find some easier way of doing this, join our &lt;strong&gt;&lt;a href="https://discord.gg/memgraph" rel="noopener noreferrer"&gt;Discord server&lt;/a&gt;&lt;/strong&gt; and share it with the Memgraph team and community.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://memgraph.com/memgraph-for-neo4j-developers/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=blog_repost&amp;amp;utm_content=banner" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw0azgpsgm3wp9w5sd5wu.png" alt="Read more about Neo4j and Memgraph on memgraph.com"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>beginners</category>
      <category>todayilearned</category>
      <category>database</category>
    </item>
    <item>
      <title>Building robust applications using GQLAlchemy</title>
      <dc:creator>Katarina Supe</dc:creator>
      <pubDate>Mon, 31 Jan 2022 14:33:28 +0000</pubDate>
      <link>https://forem.com/memgraph/building-robust-applications-using-gqlalchemy-c0h</link>
      <guid>https://forem.com/memgraph/building-robust-applications-using-gqlalchemy-c0h</guid>
      <description>&lt;p&gt;While building the whole web application, you save the necessary data to the database and load it whenever needed. Fetching the data can be error-prone since there may be that one minor typo that will bug you. In this tutorial, you'll learn how to build a small part of the &lt;a href="https://github.com/memgraph/twitch-analytics-demo"&gt;Twitch analytics app&lt;/a&gt; with the help of &lt;strong&gt;GQLAlchemy&lt;/strong&gt;, an object graph mapper (OGM) that makes building graph-based apps much easier. &lt;/p&gt;

&lt;h2&gt;
  
  
  Backend implementation
&lt;/h2&gt;

&lt;p&gt;Through this tutorial, you are going to find the most popular game from the Twitch dataset. The &lt;a href="https://github.com/memgraph/twitch-analytics-demo/tree/main/backend/import-data"&gt;data&lt;/a&gt; was retrieved from the &lt;a href="https://dev.twitch.tv/docs/api/"&gt;Twitch API&lt;/a&gt;, and for this tutorial, you will just need the &lt;code&gt;streamers.csv&lt;/code&gt; file. First, you have to define the necessary data classes in &lt;a href="https://github.com/memgraph/twitch-analytics-demo/blob/main/backend/models.py"&gt;&lt;code&gt;models.py&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;gqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Relationship&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;app&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;memgraph&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"User"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;followers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;totalViewCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Game&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you have to load the data from the CSV file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load_streams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;read_obj&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;csv_reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;read_obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;csv_reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;csv_reader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="n"&gt;followers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="n"&gt;totalViewCount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;game&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Game&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;plays_rel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Plays&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="n"&gt;_start_node_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_end_node_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;game&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_id&lt;/span&gt;
                &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;memgraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You modeled objects using &lt;strong&gt;GQLAlchemy's&lt;/strong&gt; Object Graph Mapper (OGM), which offers schema validation, so you can be sure that the data inside Memgraph will be accurate.&lt;br&gt;
All loading methods can be found in &lt;a href="https://github.com/memgraph/twitch-analytics-demo/blob/main/backend/twitch_data.py"&gt;&lt;code&gt;twitch_data.py&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After the data is loaded, you can create an API endpoint for GET requests in &lt;a href="https://github.com/memgraph/twitch-analytics-demo/blob/main/backend/app.py"&gt;&lt;code&gt;app.py&lt;/code&gt;&lt;/a&gt; to find out which game is the most popular:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/top-games/&amp;lt;num_of_games&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"GET"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;log_time&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_top_games&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_of_games&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="s"&gt;"""Get top num_of_games games by number of streamers who play them."""&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;Match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Stream"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"s"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"PLAYS"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Game"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"g"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"g.name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"game_name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"count(s)"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"num_of_players"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"num_of_players DESC"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_of_games&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;games_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;players_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;game_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"game_name"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="n"&gt;num_of_players&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"num_of_players"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="n"&gt;games_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;game_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;players_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_of_players&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;games&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;game_name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;game_name&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;games_list&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;players&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s"&gt;"players"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;player_count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;player_count&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;players_list&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"games"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;games&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"players"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;players&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mimetype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"application/json"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Fetching top games went wrong."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;query builder&lt;/strong&gt; from &lt;strong&gt;GQLAlchemy&lt;/strong&gt; was used to avoid writing Cypher queries and to notice if there are any errors before the query is executed in the database. The query above counts how many streamers play each game and then returns results in descending order. This is how the query builder construct looks when executed as a Cypher query in Memgraph:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Query builder&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Match&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Stream"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"s"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"PLAYS"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Game"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"g"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;return_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"g.name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"game_name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"count(s)"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"num_of_players"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"num_of_players DESC"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_of_games&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cypher query&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cypher"&gt;&lt;code&gt;&lt;span class="k"&gt;MATCH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="py"&gt;s:&lt;/span&gt;&lt;span class="n"&gt;Stream&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ss"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;:PLAYS&lt;/span&gt;&lt;span class="ss"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="py"&gt;g:&lt;/span&gt;&lt;span class="n"&gt;Game&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;RETURN&lt;/span&gt; &lt;span class="n"&gt;g.name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;game_name&lt;/span&gt;&lt;span class="ss"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;num_of_players&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;num_of_players&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="n"&gt;num_of_games&lt;/span&gt;&lt;span class="ss"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this request, you can determine how many top games you want to fetch. The response you'll get in the frontend is JSON with &lt;code&gt;games&lt;/code&gt; and &lt;code&gt;players&lt;/code&gt; as keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend implementation
&lt;/h2&gt;

&lt;p&gt;In the end, let's show how you can visualize your results. The &lt;a href="https://github.com/memgraph/twitch-analytics-demo/tree/main/frontend"&gt;frontend&lt;/a&gt; is built with the help of Semantic UI React.&lt;/p&gt;

&lt;p&gt;You have to create a component in which you're going to fetch the data from the backend. The most important part is the fetching, which you have to call immediately after a component is mounted, that is, in &lt;code&gt;componentDidMount()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/top-games/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="na"&gt;isLoaded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;games&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;games&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;players&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;players&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="na"&gt;isLoaded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;numOfGames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;header&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Top &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; games&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;numOfGames&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can render the results saved in &lt;code&gt;games&lt;/code&gt; and &lt;code&gt;players&lt;/code&gt; state variables however you want. If you need inspiration, check out the &lt;a href="https://github.com/memgraph/twitch-analytics-demo/blob/main/frontend/src/components/Games.js"&gt;&lt;code&gt;Games.js&lt;/code&gt;&lt;/a&gt; component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sLSOwqpI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/memgraph/twitch-analytics-demo/main/images/app_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sLSOwqpI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/memgraph/twitch-analytics-demo/main/images/app_2.png" alt="twitch-analytics-demo" width="880" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Creating classes representing nodes and relationships in Python offers you more control of your data. GQLAlchemy enables you to easily communicate with the graph database using the technology stack you're already familiar with. If you have questions about GQLAlchemy's OGM or query builder, visit our &lt;a href="https://discord.gg/memgraph"&gt;Discord&lt;/a&gt; server and drop us a message. You can also share any project you come up with! &lt;/p&gt;

</description>
      <category>python</category>
      <category>ogm</category>
      <category>memgraph</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
