diff --git a/src/pages/blog/2024-06-17-integrating-apache-age-with-python.md b/src/pages/blog/2024-06-17-integrating-apache-age-with-python.md new file mode 100644 index 000000000..9cddd78b8 --- /dev/null +++ b/src/pages/blog/2024-06-17-integrating-apache-age-with-python.md @@ -0,0 +1,132 @@ +--- +templateKey: blog-post +title: Integrating Apache AGE with Python +date: 2024-06-17T07:00:30.672Z +description: Integrating Apache AGE with Python +featuredpost: true +featuredimage: +--- + + +Apache AGE (A Graph Extension) is a PostgreSQL extension that provides graph database functionality. Integrating Apache AGE with Python allows you to leverage this functionality within your Python applications. This guide will walk you through the process of setting up the integration and running a sample code. + +#### Prerequisites + +For this task, we will use the Apache AGE Docker image. + +So before you begin, ensure you have the following installed: + +* Docker; +* Apache AGE image already pulled and executed once (Refer to past tutorials for this); +* Python (version 3.9 or later); + +You will need psycopg2 and antlr4-python3 packages to run it. You can install them by executing the requirements.txt file inside the directory age/drivers/python. + +To do so, navigate to the said python driver directory, then run + +pip install -r requirements.txt + +#### Testing + +You can test if everything is working by issuing the command at the same directory: + +```python +python test_age_py.py \ + -host "127.0.0.1" \ + -db "postgres" \ + -u "postgres" \ + -pass "agens" \ + -port 5432 \ + -gn "test_graph" +``` + + + +#### Setup + +To use the "age" library, you will need to install it, so, in the same directory, there's a setup.py file. Execute it with + +``` +python setup.py install +``` + +Now we're ready to use Apache AGE in Python! + +#### Starting the server + +But first, be sure to put your postgres server to run. I prefer using Docker, so issue this command: + +``` +docker start age +``` + +#### Writing the Python Code + +Here is a sample Python script to connect to the PostgreSQL database, create a graph, and perform basic operations using Apache AGE. + +``` +import age + +GRAPH_NAME = "test_graph" + +""" +Define the connection parameters (host, port, database name, user, and password). +Here, we use the default Apache AGE Docker container settings +""" +CONFIG = ( + "host=127.0.0.1 \ + port=5455 \ + dbname=postgresDB \ + user=postgresUser \ + password=postgresPW" +) + +try: + # Establish a connection to the PostgreSQL database using the defined parameters. + connection = age.connect(graph=GRAPH_NAME, dsn=CONFIG) + + # The Cypher query `CREATE (n:Person {name: 'Maria'}) RETURN n` creates a node with the label `Person` and a property `name` set to 'Maria'. + query = "CREATE (n:Person {name: 'Maria'}) RETURN n" + + # The `execCypher` method sends the query to the database. + cursor = connection.execCypher(query) + + # Print the results + for row in cursor: + print("CREATED: ", row[0]) + + # Save the changes to the database. + connection.commit() + +except Exception as e: + print(f"Error: {e}") + connection.rollback() +finally: + # Clean up: delete the graph and close the connection + age.deleteGraph(connection.connection, GRAPH_NAME) + cursor.close() + connection.close() +``` + +#### Step 4: Running the Script + +* Save the code to a file, for example, age_integration.py. +* Run the script: + +``` +python age_integration.py +``` + +It should output something close to this: + +``` +CREATED: {label:Person, id:844424930131969, properties:{name: Maria, }}::VERTEX +``` + +#### Conclusion + +Integrating Apache AGE with Python allows you to utilize powerful graph database features within your Python applications. By following this guide, you can set up the integration, run queries, and manage graph data efficiently. This integration opens up new possibilities for handling complex relationships and structures in your data. + +If you run into any problems, don't hesitate to reach out. + + \ No newline at end of file diff --git a/src/pages/blog/2024-06-21-video-graph-databases-and-apache-age.md b/src/pages/blog/2024-06-21-video-graph-databases-and-apache-age.md new file mode 100644 index 000000000..0c8fb9469 --- /dev/null +++ b/src/pages/blog/2024-06-21-video-graph-databases-and-apache-age.md @@ -0,0 +1,99 @@ +--- +templateKey: blog-post +title: "[ Video ] Graph databases and Apache AGE" +date: 2024-06-21T01:17:22.666Z +description: +featuredpost: true +featuredimage: +--- +
+ +
+
+ +**1 st : Introduction:**
+Introduction. The rise of graph databases. Data is everywhere. It's the lifeblood of our digital age, +but data alone is not enough. We need to understand the relationships within data to unlock its +true potential. This is where graph databases come into play. Unlike traditional databases, graph +databases excel in understanding connections. They efficiently represent and query relationships. +Graph databases are purpose-built for this challenge, ideal for social networks, recommendation +engines, and fraud detection. Each user is an entity, and their connections are the relationships. +Each user is an entity, and their connections are the relationships. Graph databases can answer +complex queries with remarkable speed. + +--- +
+ +
+ +
+
+ +**2 nd : Understanding the essence of graph structures**
+Understanding the essence of graph structures. At the heart of every graph database lie three +fundamental concepts. Nodes, edges and properties. These elements work together to represent +and organize data in a way that mirrors the interconnected nature of information in the real +world. Understanding these building blocks is key to unlocking the power of graph databases. +Nodes, also known as vertices, represent the entities within our data. In a social network, a node +could be a user, a post, or a group. In a transportation network, nodes could represent cities, +airports, or train stations. Each node encapsulates a distinct piece of information within the +graph. Edges, on the other hand, represent the relationships between these entities. They are the +connecting lines that establish how nodes interact with each other. +Returning to our social network example, an edge might signify a friendship between two users, +or a likes relationship between a user and a post. Edges give context to nodes and highlight the +interconnectedness of our data. Finally, properties provide further details about nodes and edges. +They are attributes that enrich our understanding of the entities and relationships within the +graph. For instance, a user node might have properties like name, age, and location, while a +friendship edge could have properties like date created or connection strength. +Properties add depth and nuance to our graph representation. Together, nodes, edges, and +properties form the basic building blocks of a graph database. They provide a flexible and +expressive way to model a wide range of real-world scenarios, from social networks and +recommendation engines to fraud detection systems and knowledge graphs. By understanding +these fundamental concepts, we can begin to harness the power of graph databases to unravel the +complexities hidden within our data. Apache Age, an extension for PostgreSQL enhances our +ability to manage and understand complex data relationships. +By integrating graph database capabilities directly into PostgreSQL, Apache Edge allows us to +leverage the strengths of both relational and graph databases. This integration simplifies the +process of querying and visualizing complex data relationships, making it easier to uncover +insights and patterns. making it easier to uncover insights and patterns. Whether you're working +on social networks, recommendation systems, or fraud detection, Apache Age provides the tools +needed to enhance your data analysis within PostgreSQL. + +--- +
+ +
+ +
+
+ +**3 rd : PostgreSQL with Apache Age, a powerful combination.**
+While graph databases offer a compelling approach to managing relationships, many organizations have existing investments in +relational databases like PostgreSQL. Fortunately, Apache Age brings the power of +graph databases directly into the familiar realm of PostgreSQL, offering a seamless way to +integrate graph capabilities into existing SQL-based workflows. Apache Edge extends +PostgreSQL with the ability to store, query, and analyze graph data using Open Cypher, a widely +adopted graph query language. +This integration means that developers and data scientists can leverage their existing SQL skills +and tools while benefiting from the expressiveness of graph databases. No need to learn a +completely new database system or migrate existing data. Installing Apache Edge on +PostgreSQL is straightforward, involving simple commands to add the extension to your +PostgreSQL instance. Once installed, you can start modeling your data using familiar graph +concepts. Define your nodes and edges, specify properties, and begin populating your graph +database within the comfortable confines of PostgreSQL. Querying your graph data is equally +intuitive. Apache Edge allows you to use Open Cypher queries directly within your PostgreSQL +environment. +This powerful combination enables you to perform complex graph traversals, pattern matching +This powerful combination enables you to perform complex graph traversals, pattern matching +and analysis, all while leveraging the robustness and familiarity of PostgreSQL. + +
diff --git a/static/img/f_1.mp4 b/static/img/f_1.mp4 new file mode 100644 index 000000000..999fad6df Binary files /dev/null and b/static/img/f_1.mp4 differ diff --git a/static/img/f_2.mp4 b/static/img/f_2.mp4 new file mode 100644 index 000000000..237ce2543 Binary files /dev/null and b/static/img/f_2.mp4 differ diff --git a/static/img/f_3.mp4 b/static/img/f_3.mp4 new file mode 100644 index 000000000..f5adaa952 Binary files /dev/null and b/static/img/f_3.mp4 differ