Skip to content

Commit 1727512

Browse files
authored
Update blog (#328)
* Test * Update gatsby-config.js * Changes search result text * Fix gatsby-config.js and title * Change meta description * Fix sitemap.xml for broken links * Update landing page: Key Update and image * Create Blog “2024-04-21-how-to-integrate-langchain-with-apache-age-for-graph-database-applications” * Update Blog “2024-04-21-how-to-integrate-langchain-with-apache-age-for-graph-database-applications” * Update Blog “2024-04-21-how-to-integrate-langchain-with-apache-age-for-graph-database-applications” * Update blog, cms * Update blog * Fix spelling error * Activate "blog" * Update download page, modified blog * modified footer, download * Update landing image and blog scss * modified: src/components/styles/Blog-post.scss * modified: src/pages/download/index.md * modified: src/templates/blog-post.js * Create Blog “2024-04-23-beyond-chatgpt-how-to-maximize-the-use-of-chatgpt-with-interactive-graph-models” * Create Blog “2024-04-23-combating-cyber-attack-with-apache-ages-link-analysis” * Create Blog “2024-04-23-from-data-to-connections-leveraging-hyperconnectivity-in-e-commerce-data-part-1” * Create Blog “2024-04-23-learn-machine-learning-with-graph-in-hyperconnected-data-part-2” * Create Blog “2024-04-23-graph-database-in-postgresql-apache-age” * Create Blog “2024-04-23-comparison-of-apache-age-postgraphile-and-hasura” * modified: static/admin/config.yml * modified: src/components/styles/Blog-post.scss modified: src/components/styles/BlogRollTemplate.module.scss modified: src/templates/blog-post.js * Update Blog “blog_240401” * Match file name format * deleted: src/pages/blog/blog_240401.md * Change button color * modified: static/sitemap.xml * modified blog * modified: src/pages/404.js modified: src/pages/index.md * Create Blog “2024-04-25-discovering-the-inner-workings-of-postgresqls-data-allocation” * Create Blog “2024-04-25-seamless-data-migration-migrating-apache-age-data-between-different-versions-of-postgresql” * Create Blog “2024-04-25-how-to-deploy-apache-age-docker-image-on-aws” * modified: static/admin/config.yml * modified: src/pages/blog/ modified: src/pages/blog/2024-04-25-how-to-deploy-apache-age-docker-image-on-aws.md modified: src/pages/blog/2024-04-25-seamless-data-migration-migrating-apache-age-data-between-different-versions-of-postgresql.md * Create Blog “2024-05-01-what-is-a-graph-database” * modified: src/templates/blog-post.js * modified: src/pages/blog/ * modified: src/pages/blog/ * Remove sign® * modified ™ * Create Blog “2024-05-21-a-dockerhub-guide” * Create Blog “2024-05-21-a-beginners-guide-to-downloading-docker” * Create Blog “2024-05-21-basic-understanding-what-is-a-container” * Create Blog “2024-05-21-navigating-the-maze-of-data-with-apache-age-and-langchain” * Create Blog “2024-05-21-how-to-use-the-official-apache-age-docker-image” * modified blogs * Update Blog “2024-05-21-a-dockerhub-guide” * modified BlogRoll * modified BlogRollTemplate * new file: static/ads.txt * Create Blog “2024-06-12-integrating-apache-age-docker-image-and-pgadmin-4-a-step-by-step-guide” * Create Blog “2024-06-12-video-the-easiest-way-to-install-apache-age-docker” * Add file * modified and renamed * modified and renamed * Create Blog “2024-06-12-video-beginners-guide” * Create Blog “2024-06-12-video-future-landscape-of-graph-db” * Update Blog “2024-06-12-video-future-landscape-of-graph-db” * Create Blog “2024-06-12-video-future-landscape-of-graph-db-1” * new file and modified * modified * renamed * modified: src/templates/index-page.js * modified: src/pages/blog/2024-06-12 * renamed * Create Blog “2024-06-17-integrating-apache-age-with-python” * Update Blog “2024-06-17-integrating-apache-age-with-python” * modified * Create Blog “2024-06-21-video-graph-databases-and-apache-age” * modified & new file * modified * modified * # This is a combination of 4 commits. # This is the 1st commit message: modified # This is the commit message #2: Create Blog “2024-06-21-video-graph-databases-and-apache-age” # This is the commit message #3: modified & new file # This is the commit message #4: modified * modified
1 parent 0518ad8 commit 1727512

File tree

5 files changed

+231
-0
lines changed

5 files changed

+231
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
templateKey: blog-post
3+
title: Integrating Apache AGE with Python
4+
date: 2024-06-17T07:00:30.672Z
5+
description: Integrating Apache AGE with Python
6+
featuredpost: true
7+
featuredimage:
8+
---
9+
<!--StartFragment-->
10+
11+
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.
12+
13+
#### Prerequisites
14+
15+
For this task, we will use the Apache AGE Docker image.
16+
17+
So before you begin, ensure you have the following installed:
18+
19+
* Docker;
20+
* Apache AGE image already pulled and executed once (Refer to past tutorials for this);
21+
* Python (version 3.9 or later);
22+
23+
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.
24+
25+
To do so, navigate to the said python driver directory, then run
26+
27+
pip install -r requirements.txt
28+
29+
#### Testing
30+
31+
You can test if everything is working by issuing the command at the same directory:
32+
33+
```python
34+
python test_age_py.py \
35+
-host "127.0.0.1" \
36+
-db "postgres" \
37+
-u "postgres" \
38+
-pass "agens" \
39+
-port 5432 \
40+
-gn "test_graph"
41+
```
42+
43+
<!--EndFragment-->
44+
45+
#### Setup
46+
47+
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
48+
49+
```
50+
python setup.py install
51+
```
52+
53+
Now we're ready to use Apache AGE in Python!
54+
55+
#### Starting the server
56+
57+
But first, be sure to put your postgres server to run. I prefer using Docker, so issue this command:
58+
59+
```
60+
docker start age
61+
```
62+
63+
#### Writing the Python Code
64+
65+
Here is a sample Python script to connect to the PostgreSQL database, create a graph, and perform basic operations using Apache AGE.
66+
67+
```
68+
import age
69+
70+
GRAPH_NAME = "test_graph"
71+
72+
"""
73+
Define the connection parameters (host, port, database name, user, and password).
74+
Here, we use the default Apache AGE Docker container settings
75+
"""
76+
CONFIG = (
77+
"host=127.0.0.1 \
78+
port=5455 \
79+
dbname=postgresDB \
80+
user=postgresUser \
81+
password=postgresPW"
82+
)
83+
84+
try:
85+
# Establish a connection to the PostgreSQL database using the defined parameters.
86+
connection = age.connect(graph=GRAPH_NAME, dsn=CONFIG)
87+
88+
# The Cypher query `CREATE (n:Person {name: 'Maria'}) RETURN n` creates a node with the label `Person` and a property `name` set to 'Maria'.
89+
query = "CREATE (n:Person {name: 'Maria'}) RETURN n"
90+
91+
# The `execCypher` method sends the query to the database.
92+
cursor = connection.execCypher(query)
93+
94+
# Print the results
95+
for row in cursor:
96+
print("CREATED: ", row[0])
97+
98+
# Save the changes to the database.
99+
connection.commit()
100+
101+
except Exception as e:
102+
print(f"Error: {e}")
103+
connection.rollback()
104+
finally:
105+
# Clean up: delete the graph and close the connection
106+
age.deleteGraph(connection.connection, GRAPH_NAME)
107+
cursor.close()
108+
connection.close()
109+
```
110+
111+
#### Step 4: Running the Script
112+
113+
* Save the code to a file, for example, age_integration.py.
114+
* Run the script:
115+
116+
```
117+
python age_integration.py
118+
```
119+
120+
It should output something close to this:
121+
122+
```
123+
CREATED: {label:Person, id:844424930131969, properties:{name: Maria, }}::VERTEX
124+
```
125+
126+
#### Conclusion
127+
128+
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.
129+
130+
If you run into any problems, don't hesitate to reach out.
131+
132+
<!--EndFragment-->
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
templateKey: blog-post
3+
title: "[ Video ] Graph databases and Apache AGE"
4+
date: 2024-06-21T01:17:22.666Z
5+
description:
6+
featuredpost: true
7+
featuredimage:
8+
---
9+
<div style="display: flex; justify-content: center; align-items: center; ">
10+
<video width="960" height="540" controls>
11+
<source src="../../../static/img/f_1.mp4" type="video/mp4">
12+
Your browser does not support the video tag.
13+
</video>
14+
</div>
15+
</br>
16+
17+
**1 st : Introduction:**</br>
18+
Introduction. The rise of graph databases. Data is everywhere. It&#39;s the lifeblood of our digital age,
19+
but data alone is not enough. We need to understand the relationships within data to unlock its
20+
true potential. This is where graph databases come into play. Unlike traditional databases, graph
21+
databases excel in understanding connections. They efficiently represent and query relationships.
22+
Graph databases are purpose-built for this challenge, ideal for social networks, recommendation
23+
engines, and fraud detection. Each user is an entity, and their connections are the relationships.
24+
Each user is an entity, and their connections are the relationships. Graph databases can answer
25+
complex queries with remarkable speed.
26+
27+
---
28+
</br>
29+
30+
<div style="display: flex; justify-content: center; align-items: center; ">
31+
<video width="960" height="540" controls>
32+
<source src="../../../static/img/f_2.mp4" type="video/mp4">
33+
Your browser does not support the video tag.
34+
</video>
35+
</div>
36+
</br>
37+
38+
**2 nd : Understanding the essence of graph structures**</br>
39+
Understanding the essence of graph structures. At the heart of every graph database lie three
40+
fundamental concepts. Nodes, edges and properties. These elements work together to represent
41+
and organize data in a way that mirrors the interconnected nature of information in the real
42+
world. Understanding these building blocks is key to unlocking the power of graph databases.
43+
Nodes, also known as vertices, represent the entities within our data. In a social network, a node
44+
could be a user, a post, or a group. In a transportation network, nodes could represent cities,
45+
airports, or train stations. Each node encapsulates a distinct piece of information within the
46+
graph. Edges, on the other hand, represent the relationships between these entities. They are the
47+
connecting lines that establish how nodes interact with each other.
48+
Returning to our social network example, an edge might signify a friendship between two users,
49+
or a likes relationship between a user and a post. Edges give context to nodes and highlight the
50+
interconnectedness of our data. Finally, properties provide further details about nodes and edges.
51+
They are attributes that enrich our understanding of the entities and relationships within the
52+
graph. For instance, a user node might have properties like name, age, and location, while a
53+
friendship edge could have properties like date created or connection strength.
54+
Properties add depth and nuance to our graph representation. Together, nodes, edges, and
55+
properties form the basic building blocks of a graph database. They provide a flexible and
56+
expressive way to model a wide range of real-world scenarios, from social networks and
57+
recommendation engines to fraud detection systems and knowledge graphs. By understanding
58+
these fundamental concepts, we can begin to harness the power of graph databases to unravel the
59+
complexities hidden within our data. Apache Age, an extension for PostgreSQL enhances our
60+
ability to manage and understand complex data relationships.
61+
By integrating graph database capabilities directly into PostgreSQL, Apache Edge allows us to
62+
leverage the strengths of both relational and graph databases. This integration simplifies the
63+
process of querying and visualizing complex data relationships, making it easier to uncover
64+
insights and patterns. making it easier to uncover insights and patterns. Whether you&#39;re working
65+
on social networks, recommendation systems, or fraud detection, Apache Age provides the tools
66+
needed to enhance your data analysis within PostgreSQL.
67+
68+
---
69+
</br>
70+
71+
<div style="display: flex; justify-content: center; align-items: center; ">
72+
<video width="960" height="540" controls>
73+
<source src="../../../static/img/f_3.mp4" type="video/mp4">
74+
Your browser does not support the video tag.
75+
</video>
76+
</div>
77+
</br>
78+
79+
**3 rd : PostgreSQL with Apache Age, a powerful combination.**</br>
80+
While graph databases offer a compelling approach to managing relationships, many organizations have existing investments in
81+
relational databases like PostgreSQL. Fortunately, Apache Age brings the power of
82+
graph databases directly into the familiar realm of PostgreSQL, offering a seamless way to
83+
integrate graph capabilities into existing SQL-based workflows. Apache Edge extends
84+
PostgreSQL with the ability to store, query, and analyze graph data using Open Cypher, a widely
85+
adopted graph query language.
86+
This integration means that developers and data scientists can leverage their existing SQL skills
87+
and tools while benefiting from the expressiveness of graph databases. No need to learn a
88+
completely new database system or migrate existing data. Installing Apache Edge on
89+
PostgreSQL is straightforward, involving simple commands to add the extension to your
90+
PostgreSQL instance. Once installed, you can start modeling your data using familiar graph
91+
concepts. Define your nodes and edges, specify properties, and begin populating your graph
92+
database within the comfortable confines of PostgreSQL. Querying your graph data is equally
93+
intuitive. Apache Edge allows you to use Open Cypher queries directly within your PostgreSQL
94+
environment.
95+
This powerful combination enables you to perform complex graph traversals, pattern matching
96+
This powerful combination enables you to perform complex graph traversals, pattern matching
97+
and analysis, all while leveraging the robustness and familiarity of PostgreSQL.
98+
99+
</br>

static/img/f_1.mp4

18.8 MB
Binary file not shown.

static/img/f_2.mp4

44 MB
Binary file not shown.

static/img/f_3.mp4

32.5 MB
Binary file not shown.

0 commit comments

Comments
 (0)