SlideShare une entreprise Scribd logo
1  sur  69
Télécharger pour lire hors ligne
PyCon India 2014• • created by Sonal Raj •
Neo4j and Python
Playing with graph data
Graph Everything
Sonal Raj
PyCon India 2014• • created by Sonal Raj •
The Plan for today
Graphs and
NOSQL
Step One
Neo4j and
Cypher
Step Two
4
Step Two
Use Cases
Py2neo and
REST
Step Two
PyCon India 2014• • created by Sonal Raj •
Once upon a time..
PyCon India 2014• • created by Sonal Raj •
Once upon a time..
• Relational databases ruled the earth . .
• Data was stored in Tables, Rows and Columns
• Connections using Primary keys, Foreign keys . .
• That’s all that is relational about then 
• No on-the-fly structural (schema) changes
• Horrible for Interconnected data ( joins, really? )
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
RDBMS
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
Elastic scaling – Scale out, not up
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
Elastic scaling – Scale out, not up
Big data, Transaction Friendly
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
Elastic scaling – Scale out, not up
Big data, Transaction Friendly
Economical, can run on commodity hardware
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
Elastic scaling – Scale out, not up
Big data, Transaction Friendly
Economical, can run on commodity hardware
End of the DBA rule
PyCon India 2014• • created by Sonal Raj •
In the NOSQL Space
Elastic scaling – Scale out, not up
Big data, Transaction Friendly
Economical, can run on commodity hardware
End of the DBA rule
Flexible Data models
Graph Trivia
PyCon India 2014• • created by Sonal Raj •
Where are Graphs . . .
PyCon India 2014• • created by Sonal Raj •
Where are Graphs . . .
PyCon India 2014• • created by Sonal Raj •
Where are Graphs . . .
PyCon India 2014• • created by Sonal Raj •
Where are Graphs . . .
PyCon India 2014• • created by Sonal Raj •
Some Graphs
we overlook . .
PyCon India 2014• • created by Sonal Raj •
Some Graphs
we overlook . .
PyCon India 2014• • created by Sonal Raj •
Some Graphs
we overlook . .
PyCon India 2014• • created by Sonal Raj •
Apart from that
Fraud Analyses
Investment securities &
debt analysis
Recommendation
Engines
Impact Analysis in
networks
PyCon India 2014• • created by Sonal Raj •
So, Why Graphs ?
• Increasing Connectivity of Data
• Increasing Semi-Structredness
• Rising Complexity
PyCon India 2014• • created by Sonal Raj •
So, Why Graphs ?
• Increasing Connectivity of Data
• Increasing Semi-Structredness
• Rising Complexity
Seven Bridges of Königsberg
Leonhard Euler in 1735
PyCon India 2014• • created by Sonal Raj •
Property
Graphs
PyCon India 2014• • created by Sonal Raj •
Property
Graphs
- Has nodes
PyCon India 2014• • created by Sonal Raj •
Property
Graphs
- Has nodes
- Has properties for
each node
PyCon India 2014• • created by Sonal Raj •
Property
Graphs
- Has nodes
- Has properties for
each node
- Has Relationships
PyCon India 2014• • created by Sonal Raj •
Property
Graphs
- Has nodes
- Has properties for
each node
- Has Relationships
- Has properties for
each relationship
PyCon India 2014• • created by Sonal Raj •
Building Blocks
Nodes
Relationships
Labels
Graph Database
Properties
PyCon India 2014• • created by Sonal Raj •
Data Models
Native Graphs
Inherently store data
as nodes and
relationships.
PyCon India 2014• • created by Sonal Raj •
Data Models
Native Graphs
Inherently store data
as nodes and
relationships.
The Other ones . . .
Data stored in tables,
joins and aggregates
to simulate a graph
PyCon India 2014• • created by Sonal Raj •
Data Models
Native Graphs
Inherently store data
as nodes and
relationships.
The Other ones . . .
Data stored in tables,
joins and aggregates
to simulate a graph
PyCon India 2014• • created by Sonal Raj •
Why Neo4j ?
Schema-less property graph
PyCon India 2014• • created by Sonal Raj •
Why Neo4j ?
Schema-less property graph
Handles complex connected data efficiently
PyCon India 2014• • created by Sonal Raj •
Why Neo4j ?
Schema-less property graph
Handles complex connected data efficiently
Fully ACID Transactions
PyCon India 2014• • created by Sonal Raj •
Why Neo4j ?
Schema-less property graph
Handles complex connected data efficiently
Fully ACID Transactions
Highly Scalable, High Availability Clusters
PyCon India 2014• • created by Sonal Raj •
Why Neo4j ?
Schema-less property graph
Handles complex connected data efficiently
Fully ACID Transactions
Highly Scalable, High Availability Clusters
REST API for servers. Can be embedded to applications on JVM.
PyCon India 2014• • created by Sonal Raj •
Why Neo4j ?
Schema-less property graph
Handles complex connected data efficiently
Fully ACID Transactions
Highly Scalable, High Availability Clusters
REST API for servers. Can be embedded to applications on JVM.
Cypher – a declarative querying solution
Graph DB with good native python bindings . .
PyCon India 2014• • created by Sonal Raj •
Cypher in action
• Highly expressive query language
• Cares about ‘what’ rather than ‘how’ to retrieve from the graph.
• Uses pattern matching expressions.
1 2
(1) – [ :label ] - (2)
label
PyCon India 2014• • created by Sonal Raj •
Cypher in action
• Highly expressive query language
• Cares about ‘what’ rather than ‘how’ to retrieve from the graph.
• Uses pattern matching expressions.
1 2
START n=(1), m=(2)
MATCH n – [r:label] – m
RETURN r
label
PyCon India 2014• • created by Sonal Raj •
Cypher in action
• Highly expressive query language
• Cares about ‘what’ rather than ‘how’ to retrieve from the graph.
• Uses pattern matching expressions.
• To make life easy for some, it is inspired by SQL.
1 2
START n=(1), m=(2)
MATCH n – [r:label] – m
RETURN r
label
PyCon India 2014• • created by Sonal Raj •
Cypher in action
Create
Read
CREATE (n:Person { name : ‘Chuck Norris', title : ‘Analyst' })
RETURN n
MATCH (a:Person),(b:Person)
WHERE a.name = ‘Chuck' AND b.name = ‘Rajani'
CREATE (a)-[r:RELTYPE { name : ‘cannot_find’ }]->(b)
RETURN r
MATCH (n) RETURN n #everything is returned
MATCH (n:Label) RETURN n #all with specific label
MATCH (Titanic { title:‘Titanic' })<-[:ACTED_IN|:DIRECTED]-(person)
RETURN person
PyCon India 2014• • created by Sonal Raj •
Cypher in action
Update
Delete
MATCH (n { name: 'Andres' })
SET n.surname = 'Taylor'
RETURN n
MATCH (peter { name: 'Peter' })
SET peter += { hungry: TRUE , position: 'Entrepreneur' }
MATCH (n { name: 'Peter' })
REMOVE n.title
REMOVE n:German
RETURN n
SET n.name = NULL
PyCon India 2014• • created by Sonal Raj •
REST in peace !!
Create
POST http://localhost:7474/db/data/node
{
"foo" : "bar"
}
POST http://localhost:7474/db/data/node/1/relationships
{
"to" : "http://localhost:7474/db/data/node/10",
"type" : "LOVES",
"data" : {
"foo" : "bar"
}
}
POST http://localhost:7474/db/data/schema/index/person
{
"property_keys" : [ "name" ]
}
PyCon India 2014• • created by Sonal Raj •
REST in peace !!
Read
Update
Delete
GET http://localhost:7474/db/data/node/144
GET http://localhost:7474/db/data/relationship/65
GET http://localhost:7474/db/data/relationship/61/properties
GET http://localhost:7474/db/data/schema/index/user
PUT http://localhost:7474/db/data/relationship/66/properties
{
"happy" : false
}
PUT http://localhost:7474/db/data/relationship/60/properties/cost
"deadly"
DELETE http://localhost:7474/db/data/node/308
DELETE http://localhost:7474/db/data/relationship/58
DELETE http://localhost:7474/db/data/schema/index/SomeLabel/name
Beauty of py2neo
PyCon India 2014• • created by Sonal Raj •
For the pythonistas
As simple as that!
from py2neo import neo4j
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
from py2neo import node, rel
die_hard = graph_db.create(
node(name="Bruce Willis"),
node(name="John McClane"),
node(name="Alan Rickman"),
node(name="Hans Gruber"),
node(name="Nakatomi Plaza"),
rel(0, "PLAYS", 1),
rel(2, "PLAYS", 3),
rel(1, "VISITS", 4),
rel(3, "STEALS_FROM", 4),
rel(1, "KILLS", 3),
)
PyCon India 2014• • created by Sonal Raj •
For the pythonistas
graphdb • clear()
• create(*abstracts)
• delete(*entities)
• delete_index(content_type, index_name)
• find(label, property_key=None, property_value=None)
• get_index(content_type, index_name)
• get_indexed_node(index_name, key, value)
• ...
PyCon India 2014• • created by Sonal Raj •
For the pythonistas
• get_indexed_relationship(index_name, key, value)
• get_properties(*entities)
• match(start_node=None, rel_type=None, end_node=None,
bidirectional=False, limit=None)
• match_one(start_node=None, rel_type=None, end_node=None,
bidirectional=False)
• node(id_)
• get_or_create_index(content_type, index_name, config=None)
• get_or_create_indexed_node(index_name, key, value,
properties=None)
graphdb
PyCon India 2014• • created by Sonal Raj •
Complexity Handling
“ A graph database without traversals is
just a persistent graph ”
PyCon India 2014• • created by Sonal Raj •
Paths with py2neo
#Create Paths
from py2neo import neo4j, node
a, b, c = node(name="Alice"), node(name="Bob"), node(name="Carol")
abc = neo4j.Path(a, ’KNOWS’, b, ’KNOWS’, c)
d, e = node(name=“Doctor”), node(name=“Easter”)
de = neo4j.Path(d, ‘KNOWS’, e)
#Join paths
abcde = neo4j.Path.join(abc, ‘KNOWS’, de)
#commit to the db
abcde.get_or_create(graph_db)
PyCon India 2014• • created by Sonal Raj •
Schema, Indices with py2neo
#The class
py2neo.neo4j.Schema
py2neo.neo4j.Index
#Join paths
create_index(label, property_key)
drop_index(label, property_key)
get_indexed_property_keys(label)
add_if_none(key, value, entity)
#Apache Lucene Query
people = graph_db.get_or_create_index(neo4j.Node, "People")
s_people = people.query("family_name:S*")
neo4j.Node
neo4j.Relationship
PyCon India 2014• • created by Sonal Raj •
Cypher with py2neo
#Create transaction object
from py2neo import cypher
Session = cypher.Session(“http://localhost:7474/”)
tx = session.create_transaction()
#Add transactions, execute or commit
tx.append(“some cypher query”)
tx.append(“some cypher query”)
tx.execute()
tx.append(“some cypher query”)
tx.commit()
#The classical way
from py2neo import neo4j
graph_db = neo4j.GraphDatabaseSercice()
query = neo4j.CypherQuery(graph_db, ‘your cypher query’)
query.execute()
#query.stream()
PyCon India 2014• • created by Sonal Raj •
Command Line neotool
#Syntax of operation
neotool [<option>] <command> <args>
Or python –m py2neo.tool ..
#Some serious examples
neotool clear
neotool cypher "start n=node(1) return n, n.name?“
neotool cypher-csv "start n=node(1) return n.name, n.age?"
neotool cypher-tsv "start n=node(1) return n.name, n.age?"
#Guess what, you can also access the shell
neotool shell
PyCon India 2014• • created by Sonal Raj •
Neo4j level 2
• Batch Inserter
• High Availability
• Built-in online backup tools
• HTTPS support
PyCon India 2014• • created by Sonal Raj •
Neo4j level 2
• Batch Inserter
• High Availability
• Built-in online backup tools
• HTTPS support
Neo4J Framework.
• GraphUnit, for unit testing neo4j
• Libraries for performance and API testing
• Batch Transaction tools
• Transaction Event tools
• Some other utilities . .
Use Cases
PyCon India 2014• • created by Sonal Raj •
Recommendation Engines
Complex pattern matching
PyCon India 2014• • created by Sonal Raj •
Social Network Data
Many entities, highly interconnected
PyCon India 2014• • created by Sonal Raj •
Map Data
Traversals and routing
PyCon India 2014• • created by Sonal Raj •
Python Family
Relatives for Neo4j
Neo4
• •PyCon India 2014
Thank YouNeo appreciates your patience.
• Sonal Raj
• http://www.sonalraj.com/
• http://github.com/sonal-raj/
• sonal@enfoss.org

Contenu connexe

En vedette

Natural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in LumifyNatural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in LumifyCharlie Greenbacker
 
Round pegs and square holes
Round pegs and square holesRound pegs and square holes
Round pegs and square holesDaniel Greenfeld
 
Leveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4jLeveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4jAlberto Perdomo
 
A quick review of Python and Graph Databases
A quick review of Python and Graph DatabasesA quick review of Python and Graph Databases
A quick review of Python and Graph DatabasesNicholas Crouch
 
Building a Graph-based Analytics Platform
Building a Graph-based Analytics PlatformBuilding a Graph-based Analytics Platform
Building a Graph-based Analytics PlatformKenny Bastani
 
Building social network with Neo4j and Python
Building social network with Neo4j and PythonBuilding social network with Neo4j and Python
Building social network with Neo4j and PythonAndrii Soldatenko
 
Natural Language Processing with Graph Databases and Neo4j
Natural Language Processing with Graph Databases and Neo4jNatural Language Processing with Graph Databases and Neo4j
Natural Language Processing with Graph Databases and Neo4jWilliam Lyon
 

En vedette (7)

Natural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in LumifyNatural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in Lumify
 
Round pegs and square holes
Round pegs and square holesRound pegs and square holes
Round pegs and square holes
 
Leveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4jLeveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4j
 
A quick review of Python and Graph Databases
A quick review of Python and Graph DatabasesA quick review of Python and Graph Databases
A quick review of Python and Graph Databases
 
Building a Graph-based Analytics Platform
Building a Graph-based Analytics PlatformBuilding a Graph-based Analytics Platform
Building a Graph-based Analytics Platform
 
Building social network with Neo4j and Python
Building social network with Neo4j and PythonBuilding social network with Neo4j and Python
Building social network with Neo4j and Python
 
Natural Language Processing with Graph Databases and Neo4j
Natural Language Processing with Graph Databases and Neo4jNatural Language Processing with Graph Databases and Neo4j
Natural Language Processing with Graph Databases and Neo4j
 

Plus de Sonal Raj

Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...
Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...
Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...Sonal Raj
 
IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...
IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...
IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...Sonal Raj
 
Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019
Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019
Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019Sonal Raj
 
Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?Sonal Raj
 
Alexa enabled smart home programming in Python - PyCon India 2018
Alexa enabled smart home programming in Python - PyCon India 2018Alexa enabled smart home programming in Python - PyCon India 2018
Alexa enabled smart home programming in Python - PyCon India 2018Sonal Raj
 
Startup Diagnostics: Reasons why startups can fail.
Startup Diagnostics: Reasons why startups can fail.Startup Diagnostics: Reasons why startups can fail.
Startup Diagnostics: Reasons why startups can fail.Sonal Raj
 
IT Quiz Mains
IT Quiz MainsIT Quiz Mains
IT Quiz MainsSonal Raj
 
IT Quiz Prelims
IT Quiz PrelimsIT Quiz Prelims
IT Quiz PrelimsSonal Raj
 
Spock the human computer interaction system - synopsis
Spock   the human computer interaction system - synopsisSpock   the human computer interaction system - synopsis
Spock the human computer interaction system - synopsisSonal Raj
 

Plus de Sonal Raj (9)

Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...
Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...
Internet of Things with Python & Serverless - PyCon MY 2019 - Kuala Lumpur, M...
 
IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...
IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...
IOT and Home Automation with Serverless Computing | Serverless Days 2019 | So...
 
Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019
Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019
Internet of Python - IOT with Python and Serverless | Sonal Raj | HydPy Feb 2019
 
Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?
 
Alexa enabled smart home programming in Python - PyCon India 2018
Alexa enabled smart home programming in Python - PyCon India 2018Alexa enabled smart home programming in Python - PyCon India 2018
Alexa enabled smart home programming in Python - PyCon India 2018
 
Startup Diagnostics: Reasons why startups can fail.
Startup Diagnostics: Reasons why startups can fail.Startup Diagnostics: Reasons why startups can fail.
Startup Diagnostics: Reasons why startups can fail.
 
IT Quiz Mains
IT Quiz MainsIT Quiz Mains
IT Quiz Mains
 
IT Quiz Prelims
IT Quiz PrelimsIT Quiz Prelims
IT Quiz Prelims
 
Spock the human computer interaction system - synopsis
Spock   the human computer interaction system - synopsisSpock   the human computer interaction system - synopsis
Spock the human computer interaction system - synopsis
 

Dernier

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Dernier (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Neo4j and Python: Playing with graph data - PyCon India 2014 Talk.

  • 1. PyCon India 2014• • created by Sonal Raj • Neo4j and Python Playing with graph data Graph Everything Sonal Raj
  • 2. PyCon India 2014• • created by Sonal Raj • The Plan for today Graphs and NOSQL Step One Neo4j and Cypher Step Two 4 Step Two Use Cases Py2neo and REST Step Two
  • 3. PyCon India 2014• • created by Sonal Raj • Once upon a time..
  • 4. PyCon India 2014• • created by Sonal Raj • Once upon a time.. • Relational databases ruled the earth . . • Data was stored in Tables, Rows and Columns • Connections using Primary keys, Foreign keys . . • That’s all that is relational about then  • No on-the-fly structural (schema) changes • Horrible for Interconnected data ( joins, really? )
  • 5. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space
  • 6. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space
  • 7. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space
  • 8. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space
  • 9. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space RDBMS
  • 10. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space Elastic scaling – Scale out, not up
  • 11. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space Elastic scaling – Scale out, not up Big data, Transaction Friendly
  • 12. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space Elastic scaling – Scale out, not up Big data, Transaction Friendly Economical, can run on commodity hardware
  • 13. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space Elastic scaling – Scale out, not up Big data, Transaction Friendly Economical, can run on commodity hardware End of the DBA rule
  • 14. PyCon India 2014• • created by Sonal Raj • In the NOSQL Space Elastic scaling – Scale out, not up Big data, Transaction Friendly Economical, can run on commodity hardware End of the DBA rule Flexible Data models
  • 16. PyCon India 2014• • created by Sonal Raj • Where are Graphs . . .
  • 17. PyCon India 2014• • created by Sonal Raj • Where are Graphs . . .
  • 18. PyCon India 2014• • created by Sonal Raj • Where are Graphs . . .
  • 19. PyCon India 2014• • created by Sonal Raj • Where are Graphs . . .
  • 20. PyCon India 2014• • created by Sonal Raj • Some Graphs we overlook . .
  • 21. PyCon India 2014• • created by Sonal Raj • Some Graphs we overlook . .
  • 22. PyCon India 2014• • created by Sonal Raj • Some Graphs we overlook . .
  • 23. PyCon India 2014• • created by Sonal Raj • Apart from that Fraud Analyses Investment securities & debt analysis Recommendation Engines Impact Analysis in networks
  • 24. PyCon India 2014• • created by Sonal Raj • So, Why Graphs ? • Increasing Connectivity of Data • Increasing Semi-Structredness • Rising Complexity
  • 25. PyCon India 2014• • created by Sonal Raj • So, Why Graphs ? • Increasing Connectivity of Data • Increasing Semi-Structredness • Rising Complexity Seven Bridges of Königsberg Leonhard Euler in 1735
  • 26. PyCon India 2014• • created by Sonal Raj • Property Graphs
  • 27. PyCon India 2014• • created by Sonal Raj • Property Graphs - Has nodes
  • 28. PyCon India 2014• • created by Sonal Raj • Property Graphs - Has nodes - Has properties for each node
  • 29. PyCon India 2014• • created by Sonal Raj • Property Graphs - Has nodes - Has properties for each node - Has Relationships
  • 30. PyCon India 2014• • created by Sonal Raj • Property Graphs - Has nodes - Has properties for each node - Has Relationships - Has properties for each relationship
  • 31. PyCon India 2014• • created by Sonal Raj • Building Blocks Nodes Relationships Labels Graph Database Properties
  • 32. PyCon India 2014• • created by Sonal Raj • Data Models Native Graphs Inherently store data as nodes and relationships.
  • 33. PyCon India 2014• • created by Sonal Raj • Data Models Native Graphs Inherently store data as nodes and relationships. The Other ones . . . Data stored in tables, joins and aggregates to simulate a graph
  • 34. PyCon India 2014• • created by Sonal Raj • Data Models Native Graphs Inherently store data as nodes and relationships. The Other ones . . . Data stored in tables, joins and aggregates to simulate a graph
  • 35. PyCon India 2014• • created by Sonal Raj • Why Neo4j ? Schema-less property graph
  • 36. PyCon India 2014• • created by Sonal Raj • Why Neo4j ? Schema-less property graph Handles complex connected data efficiently
  • 37. PyCon India 2014• • created by Sonal Raj • Why Neo4j ? Schema-less property graph Handles complex connected data efficiently Fully ACID Transactions
  • 38. PyCon India 2014• • created by Sonal Raj • Why Neo4j ? Schema-less property graph Handles complex connected data efficiently Fully ACID Transactions Highly Scalable, High Availability Clusters
  • 39. PyCon India 2014• • created by Sonal Raj • Why Neo4j ? Schema-less property graph Handles complex connected data efficiently Fully ACID Transactions Highly Scalable, High Availability Clusters REST API for servers. Can be embedded to applications on JVM.
  • 40. PyCon India 2014• • created by Sonal Raj • Why Neo4j ? Schema-less property graph Handles complex connected data efficiently Fully ACID Transactions Highly Scalable, High Availability Clusters REST API for servers. Can be embedded to applications on JVM. Cypher – a declarative querying solution Graph DB with good native python bindings . .
  • 41. PyCon India 2014• • created by Sonal Raj • Cypher in action • Highly expressive query language • Cares about ‘what’ rather than ‘how’ to retrieve from the graph. • Uses pattern matching expressions. 1 2 (1) – [ :label ] - (2) label
  • 42. PyCon India 2014• • created by Sonal Raj • Cypher in action • Highly expressive query language • Cares about ‘what’ rather than ‘how’ to retrieve from the graph. • Uses pattern matching expressions. 1 2 START n=(1), m=(2) MATCH n – [r:label] – m RETURN r label
  • 43. PyCon India 2014• • created by Sonal Raj • Cypher in action • Highly expressive query language • Cares about ‘what’ rather than ‘how’ to retrieve from the graph. • Uses pattern matching expressions. • To make life easy for some, it is inspired by SQL. 1 2 START n=(1), m=(2) MATCH n – [r:label] – m RETURN r label
  • 44. PyCon India 2014• • created by Sonal Raj • Cypher in action Create Read CREATE (n:Person { name : ‘Chuck Norris', title : ‘Analyst' }) RETURN n MATCH (a:Person),(b:Person) WHERE a.name = ‘Chuck' AND b.name = ‘Rajani' CREATE (a)-[r:RELTYPE { name : ‘cannot_find’ }]->(b) RETURN r MATCH (n) RETURN n #everything is returned MATCH (n:Label) RETURN n #all with specific label MATCH (Titanic { title:‘Titanic' })<-[:ACTED_IN|:DIRECTED]-(person) RETURN person
  • 45. PyCon India 2014• • created by Sonal Raj • Cypher in action Update Delete MATCH (n { name: 'Andres' }) SET n.surname = 'Taylor' RETURN n MATCH (peter { name: 'Peter' }) SET peter += { hungry: TRUE , position: 'Entrepreneur' } MATCH (n { name: 'Peter' }) REMOVE n.title REMOVE n:German RETURN n SET n.name = NULL
  • 46. PyCon India 2014• • created by Sonal Raj • REST in peace !! Create POST http://localhost:7474/db/data/node { "foo" : "bar" } POST http://localhost:7474/db/data/node/1/relationships { "to" : "http://localhost:7474/db/data/node/10", "type" : "LOVES", "data" : { "foo" : "bar" } } POST http://localhost:7474/db/data/schema/index/person { "property_keys" : [ "name" ] }
  • 47. PyCon India 2014• • created by Sonal Raj • REST in peace !! Read Update Delete GET http://localhost:7474/db/data/node/144 GET http://localhost:7474/db/data/relationship/65 GET http://localhost:7474/db/data/relationship/61/properties GET http://localhost:7474/db/data/schema/index/user PUT http://localhost:7474/db/data/relationship/66/properties { "happy" : false } PUT http://localhost:7474/db/data/relationship/60/properties/cost "deadly" DELETE http://localhost:7474/db/data/node/308 DELETE http://localhost:7474/db/data/relationship/58 DELETE http://localhost:7474/db/data/schema/index/SomeLabel/name
  • 49.
  • 50. PyCon India 2014• • created by Sonal Raj • For the pythonistas As simple as that! from py2neo import neo4j graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/") from py2neo import node, rel die_hard = graph_db.create( node(name="Bruce Willis"), node(name="John McClane"), node(name="Alan Rickman"), node(name="Hans Gruber"), node(name="Nakatomi Plaza"), rel(0, "PLAYS", 1), rel(2, "PLAYS", 3), rel(1, "VISITS", 4), rel(3, "STEALS_FROM", 4), rel(1, "KILLS", 3), )
  • 51. PyCon India 2014• • created by Sonal Raj • For the pythonistas graphdb • clear() • create(*abstracts) • delete(*entities) • delete_index(content_type, index_name) • find(label, property_key=None, property_value=None) • get_index(content_type, index_name) • get_indexed_node(index_name, key, value) • ...
  • 52. PyCon India 2014• • created by Sonal Raj • For the pythonistas • get_indexed_relationship(index_name, key, value) • get_properties(*entities) • match(start_node=None, rel_type=None, end_node=None, bidirectional=False, limit=None) • match_one(start_node=None, rel_type=None, end_node=None, bidirectional=False) • node(id_) • get_or_create_index(content_type, index_name, config=None) • get_or_create_indexed_node(index_name, key, value, properties=None) graphdb
  • 53. PyCon India 2014• • created by Sonal Raj • Complexity Handling “ A graph database without traversals is just a persistent graph ”
  • 54. PyCon India 2014• • created by Sonal Raj • Paths with py2neo #Create Paths from py2neo import neo4j, node a, b, c = node(name="Alice"), node(name="Bob"), node(name="Carol") abc = neo4j.Path(a, ’KNOWS’, b, ’KNOWS’, c) d, e = node(name=“Doctor”), node(name=“Easter”) de = neo4j.Path(d, ‘KNOWS’, e) #Join paths abcde = neo4j.Path.join(abc, ‘KNOWS’, de) #commit to the db abcde.get_or_create(graph_db)
  • 55. PyCon India 2014• • created by Sonal Raj • Schema, Indices with py2neo #The class py2neo.neo4j.Schema py2neo.neo4j.Index #Join paths create_index(label, property_key) drop_index(label, property_key) get_indexed_property_keys(label) add_if_none(key, value, entity) #Apache Lucene Query people = graph_db.get_or_create_index(neo4j.Node, "People") s_people = people.query("family_name:S*")
  • 56.
  • 59. PyCon India 2014• • created by Sonal Raj • Cypher with py2neo #Create transaction object from py2neo import cypher Session = cypher.Session(“http://localhost:7474/”) tx = session.create_transaction() #Add transactions, execute or commit tx.append(“some cypher query”) tx.append(“some cypher query”) tx.execute() tx.append(“some cypher query”) tx.commit() #The classical way from py2neo import neo4j graph_db = neo4j.GraphDatabaseSercice() query = neo4j.CypherQuery(graph_db, ‘your cypher query’) query.execute() #query.stream()
  • 60. PyCon India 2014• • created by Sonal Raj • Command Line neotool #Syntax of operation neotool [<option>] <command> <args> Or python –m py2neo.tool .. #Some serious examples neotool clear neotool cypher "start n=node(1) return n, n.name?“ neotool cypher-csv "start n=node(1) return n.name, n.age?" neotool cypher-tsv "start n=node(1) return n.name, n.age?" #Guess what, you can also access the shell neotool shell
  • 61. PyCon India 2014• • created by Sonal Raj • Neo4j level 2 • Batch Inserter • High Availability • Built-in online backup tools • HTTPS support
  • 62. PyCon India 2014• • created by Sonal Raj • Neo4j level 2 • Batch Inserter • High Availability • Built-in online backup tools • HTTPS support Neo4J Framework. • GraphUnit, for unit testing neo4j • Libraries for performance and API testing • Batch Transaction tools • Transaction Event tools • Some other utilities . .
  • 64. PyCon India 2014• • created by Sonal Raj • Recommendation Engines Complex pattern matching
  • 65. PyCon India 2014• • created by Sonal Raj • Social Network Data Many entities, highly interconnected
  • 66. PyCon India 2014• • created by Sonal Raj • Map Data Traversals and routing
  • 67.
  • 68. PyCon India 2014• • created by Sonal Raj • Python Family Relatives for Neo4j Neo4
  • 69. • •PyCon India 2014 Thank YouNeo appreciates your patience. • Sonal Raj • http://www.sonalraj.com/ • http://github.com/sonal-raj/ • sonal@enfoss.org

Notes de l'éditeur

  1. When choice your image, you must sent it to back! ‘Right Click on Image’->’Send to Back’ ->’Send Back’
  2. When choice your image, you must sent it to back! ‘Right Click on Image’->’Send to Back’ ->’Send Back’
  3. When choice your image, you must sent it to back! ‘Right Click on Image’->’Send to Back’ ->’Send Back’