Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python and neo4j - fuck the jvm

Python and neo4j - fuck the jvm

A lightning talk I gave at pyBelfast on the 30th Jan 2019 re: python, neo4j and an idea I have.

Stephen McCullough

January 30, 2019

More Decks by Stephen McCullough

Other Decks in Programming


  1. About me.. cos it is all about me, me, me!!!!

    • Lead Developer @ Futrli - we’re hiring • I co-organise pyBelfast, BelfastRuby and BelfastElixir • I’ll try and behave and not curse… • You can find me on the inter web on most things as @swmcc apart from twitter!
  2. Python & neo4j - Fuck the jvm • First off…

    I don’t mean “Fuck the jvm” • It is an incendiary title • I find graph databases interesting/fun • I don’t want to have to learn a new language to play with something • Python has a nice eco system around it for neo4j • Standing on others shoulders - Grant Dickerson
  3. What is a graph DB? • Composed of nodes (vertices)

    & relationships (edges) • Completely different paradigm from relationship databases • It focuses on the relationships between values and commonalities among a ‘set’ of values • Designed to treat the relationships between the data as equally important to the data itself • Intended to hold data without constricting it to a pre- defined model
  4. Use cases for a graph db • Fraud Detection &

    Analytics Solution • Ecomm fraud, insurance fraud, link analysis • Knowledge Graph • Asset management, Inventory • Recommendation Engines • Product recommendations, social recommendations • Identity & Access management • Cross referencing of business objects
  5. Knowledge Graph • It represents a knowledge domain. • Connects

    things of different types in a systematic way. • Encodes knowledge arranged in a network of nodes and links rather than tables of rows and columns • Grow a semantic network of facts about “things” and can use it for data integration, knowledge discovery, and in-depth analyses.
  6. For example • Homer Simpson (is friends with) with Kenny

    & Carl • Kenny (is friends with) Carl
  7. Nodes • A node is a “vertex between edges that

    may hold data” • Or as I call it “a wee box of data stores” • [name: Homer] • [name: Lenny] • [name: Carl]
  8. Cypher • Cypher is a graph query language supported by

    neo4j • Based on pattern matching and a SQL-like syntax • …. when I was doing this before I didn’t use it much • I used Gremlin • DSL for Groovy • Wanted to use either ruby or python for an idea I’ve had since 2013
  9. Is python fit enough? • I tried this out with

    ruby in 2013 • It didn’t go well, as you can imagine. • There were libraries but most weren’t fit for purpose • Reason that I went to Groovy • However its now 2019 and there is a very well supported “official” packages for python • Neo4j-python-driver • https://github.com/neo4j-examples/movies-python-bolt • Py2neo • https://py2neo.org/v4/
  10. Example Code from py2neo import Node nicole = Node("Person", name="Nicole",

    age=24) drew = Node("Person", name="Drew", age=20) mtdew = Node("Drink", name="Mountain Dew", calories=9000) cokezero = Node("Drink", name="Coke Zero", calories=0) coke = Node("Manufacturer", name="Coca Cola") pepsi = Node("Manufacturer", name="Pepsi") graph.create(nicole | drew | mtdew | cokezero | coke | pepsi) from scripts.vis import draw options = {"Person": "name", "Drink": "name", "Manufacturer": "name"} draw(graph, options) from py2neo import Relationship graph.create(Relationship(nicole, "LIKES", cokezero)) graph.create(Relationship(nicole, "LIKES", mtdew)) graph.create(Relationship(drew, "LIKES", mtdew)) graph.create(Relationship(coke, "MAKES", cokezero)) graph.create(Relationship(pepsi, "MAKES", mtdew)) draw(graph, options)
  11. The Nodes - The Wire • All have common attributes:

    • Name • First / Last Appearance • Title • Section • Relationship between nodes
  12. Joe
 “Proposition Joe” Stewart name: Joe Stewart alias: Prop Joe

    first_apperance: 1.09 last_apperance: 5.04 section: The Street rank: Kingpin affiliation: [east-side, new day co- op]
  13. Russell
 “Stringer” Bell name: Russell Bell alias: Stringer first_apperance: 1.01

    last_apperance: 3.12 section: The Street rank: Street Boss affiliation: [west-side, new-day co- op, b&b properties]
  14. Cedric Daniels name: Cedric Daniels alias: first_apperance: 1.01 last_apperance: 5.10

    section: The Law rank: [Lieutenant, Major, Colonel, Chief Deputy Ops, Commissioner, ] affiliation: [police, lawyer]
  15. Why do this??? • It doesn’t remind me of my

    day to day to work: • Not taking a section of a monolith and making a ‘micro service’ out of it • Not creating an API so that a front end can use it and display information • Nothing at all to do with my work • It is FUCKING FUN (for me at least).
  16. Going to do the following • Possibly come back at

    some stage and give you an actual talk on this, if there is interest • Will blog about it • Want to help me, please get in touch