Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
Information in a graph database is stored and manipulated as interrelated nodes and edges for modeling entities and their relationships. Graph databases perform compellingly under situations where relationships are of equal or greater significance than the data itself, especially compared to traditional relational databases that are based on tables.
This structure works wonderfully in fraud detection, recommendation systems, and social network applications because it supports complex network querying and analysis efficiently. Such databases, through the employment of graph algorithms, easily uncover patterns and relationships that are normally very hard to discover with traditional data models; hence, a lot of insightful information about complex relationships that are present within the data.
In this article, we are going to learn how to use Py2neo and combine the library with IronPDF so you can go even further and display your findings easily within a PDF.
Py2neo is a client library and toolkit for Python developed to enable the use of Neo4j, a very popular graph database, in applications. It offers an intuitive user interface to access Neo4j's graph topologies, easily adding, editing, removing, and creating nodes with relationships. Py2neo provides a seamless interface between Python programs and the Neo4j database, which, other than executing Cypher queries, allows for the direct manipulation of graph data.
This comprehensive set of Py2neo features eases the integration of Neo4j with Python projects for advanced querying and efficient management of graph data, using the powerful features of a graph database for your Python applications with little to no work.
It supports many Python distributions that are in use under most operating systems in client applications. Just be aware that Py2neo is primarily used with Linux operating systems; it may work with other operating systems, but it isn't directly supported.
The library contains extensive features, including all command line tooling and admin tools. The library is one of the most robust ways to deal with Neo4j databases. Py2neo provides compatibility guarantees for smooth integration and reliable performance. It library supports both the Bolt and HTTP protocols.
The following procedures will help you construct and set up Py2neo to communicate with a Neo4j database:
First, install the Py2neo client library via pip to install the latest release and adopt bug fixes:
pip install py2neo
pip install py2neo
Make sure Neo4j is up and operating on your system. Download it from the Neo4j website, then follow the operating system's installation instructions.
Py2neo can be used to establish a connection between your Neo4j instance and your Python script or interactive environment. Observe this quick example below:
from py2neo import Graph
# Replace with your Neo4j credentials and connection details
uri = "bolt://localhost:7687" # URI for Neo4j Bolt protocol
user = "neo4j" # Username
password = "password" # Password
# Create a connection to the Neo4j database
graph = Graph(uri, auth=(user, password))
# Verify the connection by running a simple query
result = graph.run("RETURN 'Hello, Neo4j!' AS message")
print(result) # Should print: Hello, Neo4j!
from py2neo import Graph
# Replace with your Neo4j credentials and connection details
uri = "bolt://localhost:7687" # URI for Neo4j Bolt protocol
user = "neo4j" # Username
password = "password" # Password
# Create a connection to the Neo4j database
graph = Graph(uri, auth=(user, password))
# Verify the connection by running a simple query
result = graph.run("RETURN 'Hello, Neo4j!' AS message")
print(result) # Should print: Hello, Neo4j!
Additionally, you can modify Py2neo parameters to suit your needs, such as connection settings or default database. An illustration of more setups is provided here:
from py2neo import Graph, Node, Relationship
# Replace with your Neo4j credentials and connection details
uri = "bolt://localhost:7687" # URI for Neo4j Bolt protocol
user = "neo4j" # Username
password = "password" # Password
# Create a connection to the Neo4j database
graph = Graph(uri, auth=(user, password))
# Example of creating nodes and relationships
# Create nodes for Alice and Bob
alice = Node("Person", name="Alice")
bob = Node("Person", name="Bob")
# Add nodes to the graph
graph.create(alice)
graph.create(bob)
# Create a relationship between Alice and Bob
relationship = Relationship(alice, "KNOWS", bob)
graph.create(relationship)
from py2neo import Graph, Node, Relationship
# Replace with your Neo4j credentials and connection details
uri = "bolt://localhost:7687" # URI for Neo4j Bolt protocol
user = "neo4j" # Username
password = "password" # Password
# Create a connection to the Neo4j database
graph = Graph(uri, auth=(user, password))
# Example of creating nodes and relationships
# Create nodes for Alice and Bob
alice = Node("Person", name="Alice")
bob = Node("Person", name="Bob")
# Add nodes to the graph
graph.create(alice)
graph.create(bob)
# Create a relationship between Alice and Bob
relationship = Relationship(alice, "KNOWS", bob)
graph.create(relationship)
Below is the data that we inserted into the Neo4j database from the added tools display.
Using Py2neo, you can use Cypher queries to communicate with your graph database:
# Example of a Cypher query
query = """
MATCH (p:Person)
RETURN p.name AS name
"""
results = graph.run(query)
for record in results:
print(record["name"])
# Example of a Cypher query
query = """
MATCH (p:Person)
RETURN p.name AS name
"""
results = graph.run(query)
for record in results:
print(record["name"])
The Python library named IronPDF can handle the programmatic generation and manipulation of PDFs. It provides immense functionality to generate PDFs from HTML, merge two or more PDF files, and even use pre-existing PDFs by adding annotations, text, and images. On top of this, IronPDF allows users to create quality PDFs from any HTML page or web-based material, which can later be used in making reports, invoices, and other documents with a predefined layout.
Some of the advanced features of this library include the ability to change page layout, encrypt documents, and extract content from within the PDFs. By improving how your products handle PDFs, you will be better placed to improve their general utility. This module will also help with automating document generation operations once IronPDF is integrated into Python programs.
You can use the following command to install the packages that enable Python to use IronPDF functionality via pip.
pip install ironpdf
It is necessary to manage PDF processing with IronPDF and communicate with a Neo4j graph database using Py2neo to integrate Py2neo with IronPDF in Python. A detailed instruction on how to accomplish this integration is provided below:
from py2neo import Graph
from ironpdf import *
import warnings
warnings.filterwarnings('ignore')
# Ensure that you have replaced the string with your own license key
License.LicenseKey = "YOUR LICENSE KEY GOES HERE"
# Create a Graph instance with specific configurations
# Replace with your Neo4j credentials and connection details
uri = "bolt://localhost:7687" # URI for Neo4j Bolt protocol
user = "neo4j" # Username
password = "password" # Password
# Create a connection to the Neo4j database
graph = Graph(uri, auth=(user, password))
content = ''
content += '<h2>User Details</h2>'
# Example of a Cypher query
query = """
MATCH (p:Person)
RETURN p.name AS name
"""
results = graph.run(query)
# Append each name to the content
for record in results:
content += '<p>' + record["name"] + '</p>'
# Create a PDF from the HTML content
html_to_pdf = ChromePdfRenderer()
pdf_document = html_to_pdf.RenderHtmlAsPdf(content)
# Save the PDF document
pdf_document.SaveAs("output.pdf")
from py2neo import Graph
from ironpdf import *
import warnings
warnings.filterwarnings('ignore')
# Ensure that you have replaced the string with your own license key
License.LicenseKey = "YOUR LICENSE KEY GOES HERE"
# Create a Graph instance with specific configurations
# Replace with your Neo4j credentials and connection details
uri = "bolt://localhost:7687" # URI for Neo4j Bolt protocol
user = "neo4j" # Username
password = "password" # Password
# Create a connection to the Neo4j database
graph = Graph(uri, auth=(user, password))
content = ''
content += '<h2>User Details</h2>'
# Example of a Cypher query
query = """
MATCH (p:Person)
RETURN p.name AS name
"""
results = graph.run(query)
# Append each name to the content
for record in results:
content += '<p>' + record["name"] + '</p>'
# Create a PDF from the HTML content
html_to_pdf = ChromePdfRenderer()
pdf_document = html_to_pdf.RenderHtmlAsPdf(content)
# Save the PDF document
pdf_document.SaveAs("output.pdf")
This is a Python script connecting to a Neo4j graph database using Py2neo. It runs a Cypher query that returns the names of Person nodes and converts the results into HTML. Later, it creates a PDF document with this HTML content using IronPDF.
The script begins by importing all required libraries and setting up a Neo4j connection using the given credentials. It then converts a list of usernames to an HTML string and uses the ChromePdfRenderer
class of IronPDF to generate a PDF saved as "output.pdf".
A licensing key allows the code to work without a watermark. You can register for a free trial license at this link. Keep in mind that you can obtain one without having to show identification. To sign up for the free trial edition, all you have to provide is your email address.
The integration of IronPDF and Py2neo provides a powerful ability to handle and visualize data saved in a Neo4j graph database. It greatly simplifies the process of communication between the user and Neo4j, allowing for quick searches and retrieval of associated data. With this, you have the power to easily generate detailed, aesthetic PDFs with content in HTML tags directly from queries to the graph database.
This integration enables higher-level analysis and visualization with graph-based data, making it effectively applicable to a wide array of applications, such as creating business intelligence reports or capturing data relationships. A multitude of libraries is offered by IronSoftware to facilitate the development of programs for a variety of platforms and operating systems, including Windows, Android, macOS, Linux, and others.