SlideShare a Scribd company logo
1 of 49
Download to read offline
Introducing


                  py2neo




nigel@nigelsmall.name                 py2neo.org
@technige                              @py2neo
Me...
Where does py2neo fit in?

               (your app)

             py2neo




         GET /db/data/
         200 OK




           REST Server


               Neo4j
Coming Up...

●
    Connecting & Creating
●
    Property Containers
●
    Indexes & Uniqueness
●
    Cypher & Geoff
●
    Installation
●
    Future Plans
Connecting & Creating
Default Connections
>>> from py2neo import neo4j
>>> graph_db = neo4j.GraphDatabaseService()




                      default connection is made to
                     <http://localhost:7474/db/data/>
Custom Connections
>>> from py2neo import neo4j
>>> uri = "http://otherserv:9999/db/data/"
>>> graph_db = neo4j.GraphDatabaseService(uri)

>>> graph_db.neo4j_version
(1, 8, u'M04', 1, u'g892e348')
A few simple methods...
>>> graph_db.get_node(0)
Node('http://localhost:7474/db/data/node/0')


>>> graph_db.get_reference_node()
Node('http://localhost:7474/db/data/node/0')


>>> graph_db.get_node_count()
1


>>> graph_db.get_relationship_count()
0
Sample data: a family tree

                                      m
                                    (1947)
                      Phil (1921)             Liz (1926)




  Chaz (1948)        Anne (1950)             Andy (1960)     Ed (1964)




All characters appearing in this work are fictitious. Any resemblance to
           real persons, living or dead, is purely coincidental.
list of nodes
                           create

nodes = graph_db.create(
                                      Phil   Liz
    {"name": "Phil", "born": 1921},
    {"name": "Liz", "born": 1926},
    {"name": "Chaz", "born": 1948},
    {"name": "Anne", "born": 1950},   Chaz   Anne

    {"name": "Andy", "born": 1960},
    {"name": "Ed", "born": 1964},
)                                     Andy    Ed
list of
     relationships        create


                                                      MARRIED
rels = graph_db.create(                   Phil                       Liz
    (phil, "MARRIED", liz),
    (chaz, "FATHER", phil),                  FATHER             MOTHER
    (chaz, "MOTHER", liz),
                                                       Chaz
)




                           node must
                          already exist
create
family = graph_db.create(
    {"name": "Phil", "born": 1921}, {"name": "Liz", "born": 1926},
    {"name": "Chaz", "born": 1948}, {"name": "Anne", "born": 1950},
    {"name": "Andy", "born": 1960}, {"name": "Ed", "born": 1964},
    (0, "MARRIED", 1, {"year": 1947, "place": "London"}),
    (2, "FATHER", 0), (3, "FATHER", 0),
    (4, "FATHER", 0), (5, "FATHER", 0),
    (2, "MOTHER", 1), (3, "MOTHER", 1),
    (4, "MOTHER", 1), (5, "MOTHER", 1),
)
list of nodes and
       relationships
                                 create
family = graph_db.create(
    {"name": "Phil", "born": 1921}, {"name": "Liz", "born": 1926},
       {"name": "Chaz", "born": 1948}, {"name": "Anne", "born": 1950},
       {"name": "Andy", "born": 1960}, {"name": "Ed", "born": 1964},
       (0, "MARRIED", 1, {"year": 1947, "place": "London"}),
       (2, "FATHER", 0), (3, "FATHER", 0),
                                                             relationship
       (4, "FATHER", 0), (5, "FATHER", 0),
                                                                properties
       (2, "MOTHER", 1), (3, "MOTHER", 1),
       (4, "MOTHER", 1), (5, "MOTHER", 1),
)
                                                        node defined in
                                                          same batch
nodes, rels = family[0:6], family[6:]
phil, liz, chaz, anne, andy, ed = nodes
Property Containers
neo4j.PropertyContainer


         PropertyContainer




  Node                 Relationship
PropertyContainers
              implement many of the
            container methods defined
              by the Python standard



<http://docs.python.org/reference/datamodel.html#emulating-container-types>
neo4j.PropertyContainer
                                              set property
# update properties
liz["star_sign"] = "Taurus"


# query properties            get property
                                           test property
for node in nodes:                         containment
    name = node["name"]
    if "star_sign" in node:
        print name + " is a node["star_sign"]
    else:
        print name + " doesn't believe in horoscopes"
neo4j.Node


       PropertyContainer




Node                 Relationship
Relationships and Related Nodes
                                                     Chaz
parental_rels = liz.get_relationships(
                                               Liz
    neo4j.Direction.INCOMING, "MOTHER"
                                                     Anne
)

                                                     Chaz
parental_rels = liz.get_relationships_with(
                                               Liz
    chaz, neo4j.Direction.INCOMING, "MOTHER"
                                                     Anne
)

                                                     Chaz
children = liz.get_related_nodes(
                                               Liz
    neo4j.Direction.INCOMING, "MOTHER"
                                                     Anne
)
Relationships and Related Nodes
>>> liz.has_relationship(neo4j.Direction.BOTH, "MARRIED")
True

>>> anne.is_related_to(phil, neo4j.Direction.OUTGOING, "FATHER")
True

>>> ed.is_related_to(andy, neo4j.Direction.BOTH, "BROTHER")
False


                                could also specify
                                 multiple types
neo4j.Relationship


       PropertyContainer




Node                 Relationship
neo4j.Relationship
>>> rels[0].start_node
Node('http://localhost:7474/db/data/node/1')


>>> rels[0].end_node
Node('http://localhost:7474/db/data/node/2')


>>> rels[0].type
'MARRIED'
More sample data: a second tree

                        m
        George (1895)       Betty (1900)




          Liz (1926)        Maggie (1930)
m
                                                               George (1895)       Betty (1900)




                                                                 Liz (1926)        Maggie (1930)




                              m
                            (1947)
              Phil (1921)             Liz (1926)




Chaz (1948)   Anne (1950)            Andy (1960)   Ed (1964)
m
                                                               George (1895)       Betty (1900)




                 same person

                                                                 Liz (1926)        Maggie (1930)




                              m
                            (1947)
              Phil (1921)             Liz (1926)




Chaz (1948)   Anne (1950)            Andy (1960)   Ed (1964)
How can we avoid
duplicate nodes?
Indexes
Indexing the first family...
>>> people = graph_db.get_or_create_index(neo4j.Node, "People")

>>> for node in nodes:
...     people.add("name", node["name"], node)

>>> people.get("name", "Liz")
[Node('http://localhost:7474/db/data/node/2')]




                                    list of matching
                                         entities
...and the second
>>> new_props = [
...     {"name": "George", "born": 1895},
...     {"name": "Betty", "born": 1900},
...     {"name": "Liz", "born": 1926},
...     {"name": "Maggie", "born": 1930},
... ]


>>> george, betty, liz, maggie = [
...     people.get_or_create("name", prop["name"], prop)
...     for prop in new_props                              same node
... ]                                                       as before


>>> people.get("name", "Liz")
[Node('http://localhost:7474/db/data/node/2')]
A Quick Query
>>> people.query("name:*e*")
[Node('http://localhost:7474/db/data/node/4'),
Node('http://localhost:7474/db/data/node/7'),
Node('http://localhost:7474/db/data/node/8'),
Node('http://localhost:7474/db/data/node/9')]

         People
                                                 George
 name    Andy
 name    Anne
                                                              Maggie
 name    Betty
 name    Chaz
 name    Ed
 name    George                                                        Anne
 name    Liz
 name    Maggie
                                                      Betty
 name    Phil
We've added the
nodes... what about
 the relationships?
Cypher & Geoff
Cypher RELATE


START a=node(1), b=node(2)
RELATE (a)-[ab:KNOWS]->(b)
RETURN ab
Cypher RELATE

a   b   RELATE   a       b




a   b   RELATE   a       b




                     !
a   b   RELATE
relate
new_rels = graph_db.relate(
    (george, "MARRIED", betty),
    (liz, "FATHER", george),
    (maggie, "FATHER", george),
    (liz, "MOTHER", betty),
    (maggie, "MOTHER", betty),        George     MARRIED
                                                              Betty
)

                                  FATHER   FATHER      MOTHER       MOTHER




                                           Liz             Maggie
For relationships,
relate can be seen as
   an idempotent
 alternative to create
cypher.execute
>>> from py2neo import cypher


>>> query = "START q=node(1) RETURN q"
>>> data, metadata = cypher.execute(graph_db, query)



>>> for row in data:
...     q = row[0]
...    print q
                          first column
cypher.execute
>>> from py2neo import cypher


>>> query = "START q=node(1) RETURN q"
>>> data, metadata = cypher.execute(graph_db, query)
                        available only after
                         all rows received

>>> for row in data:
...     q = row[0]
...    print q
                           first column
cypher.execute
query = "START q=node(1) RETURN q"
                                        executed once
                                        per row as each
def print_row(row):                     row is received
    q = row[0]
    print row


cypher.execute(graph_db, query, row_handler=print_row)
Command Line Cypher
elgin@forge:~% cypher "start a=node(1) match (a)-[:MARRIED]->(b) return a, b"
+------------------------------------------------------------------+
| a                                  | b                           |
+------------------------------------------------------------------+
| (1) {"name":"Phil","born":1921} | (2) {"name":"Liz","born":1926} |
+------------------------------------------------------------------+


elgin@forge:~% cypher -f csv "start a=node(1) match (a)-[ab:MARRIED]->(b) return a, ab, b"
"a","ab","b"
"(1)","(1)-[0:MARRIED]->(2)","(2)"


elgin@forge:~% cypher -f json "start a=node(1) match (a)-[ab:MARRIED]->(b) return a, ab, b"
[
        {"a": "(1)", "ab": "(1)-[0:MARRIED]->(2)", "b": "(2)"}
]


elgin@forge:~% cypher -f geoff "start a=node(1) match (a)-[ab:MARRIED]->(b) return a, ab, b"
(1) {"name": "Phil", "born": 1921}
(2) {"name": "Liz", "born": 1926}
(1)-[0:MARRIED]->(2) {"year": 1947, "place": "London"}
Geoff is to graph data
               as
CSV is to tabular data



  <http://geoff.nigelsmall.net/>
elgin@forge:~% cypher -f geoff "start n=node(*), r=rel(*) return n, r"
(0) {}
(1) {"born": 1921, "name": "Phil", "family": "Windsor"}
(2) {"born": 1926, "star_sign": "Taurus", "family": "Windsor", "name": "Liz"}
(3) {"born": 1948, "name": "Chaz", "family": "Windsor"}
(4) {"born": 1950, "name": "Anne", "family": "Windsor"}
(5) {"born": 1960, "name": "Andy", "family": "Windsor"}
(6) {"born": 1964, "name": "Ed", "family": "Windsor"}
(7) {"born": 1895, "name": "George"}
(8) {"born": 1900, "name": "Betty"}
(9) {"born": 1930, "name": "Maggie"}
(1)-[0:MARRIED]->(2) {"place": "London", "year": 1947}
(3)-[1:FATHER]->(1) {}
(4)-[2:FATHER]->(1) {}
(5)-[3:FATHER]->(1) {}
(6)-[4:FATHER]->(1) {}
(3)-[5:MOTHER]->(2) {}
(4)-[6:MOTHER]->(2) {}
(5)-[7:MOTHER]->(2) {}
(6)-[8:MOTHER]->(2) {}
(7)-[9:MARRIED]->(8) {}
(2)-[10:FATHER]->(7) {}
(9)-[11:FATHER]->(7) {}
(2)-[12:MOTHER]->(8) {}
(9)-[13:MOTHER]->(8) {}
Neo4j Console
Installation
Requirements
●
    Python 2.6+ <http://python.org/>
●
    Tornado 2.2.1 <http://www.tornadoweb.org/>
●
    Neo4j 1.6+ <http://neo4j.org/>
Installation
          <http://pypi.python.org/pypi/py2neo>


elgin@forge:~% sudo pip install py2neo

elgin@forge:~% sudo pip install --upgrade py2neo
Source Code
         <https://github.com/nigelsmall/py2neo>


elgin@forge:~% git clone git@github.com:nigelsmall/py2neo.git
Future Plans
●
    Fast HTTP
●
    Multi-threading support
●
    Python 3
●
    Command line tools
●
    Property caching
●
    Test harness for multiple Neo4j versions
●
    New methods, e.g. get_paths_to
EOF

nigel@nigelsmall.name     py2neo.org
@technige                  @py2neo

More Related Content

What's hot

アーキテクチャ決定のお供にLightweight architecture decision records
アーキテクチャ決定のお供にLightweight architecture decision recordsアーキテクチャ決定のお供にLightweight architecture decision records
アーキテクチャ決定のお供にLightweight architecture decision recordsdisc99_
 
Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動
Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動
Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動Kanahiro Iguchi
 
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)NTT DATA Technology & Innovation
 
ggplot2できれいなグラフ
ggplot2できれいなグラフggplot2できれいなグラフ
ggplot2できれいなグラフDaisuke Ichikawa
 
位置情報にまつわるデータ補間技術
位置情報にまつわるデータ補間技術位置情報にまつわるデータ補間技術
位置情報にまつわるデータ補間技術Hiroaki Sengoku
 
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話gree_tech
 
[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送
[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送
[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送Google Cloud Platform - Japan
 
Openlink Virtuoso v01
Openlink Virtuoso v01Openlink Virtuoso v01
Openlink Virtuoso v01Satoshi Kume
 
MySQLメインの人がPostgreSQLのベンチマークをしてみた話
MySQLメインの人がPostgreSQLのベンチマークをしてみた話MySQLメインの人がPostgreSQLのベンチマークをしてみた話
MySQLメインの人がPostgreSQLのベンチマークをしてみた話hiroi10
 
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...NTT DATA Technology & Innovation
 
PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)
PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)
PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)Satoshi Yamada
 
企業における自然言語処理技術利用の最先端
企業における自然言語処理技術利用の最先端企業における自然言語処理技術利用の最先端
企業における自然言語処理技術利用の最先端Yuya Unno
 
第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」yoshiaki iwanaga
 
楽天のデータサイエンティスト@SAS Forum 2019
楽天のデータサイエンティスト@SAS Forum 2019楽天のデータサイエンティスト@SAS Forum 2019
楽天のデータサイエンティスト@SAS Forum 2019Rakuten Group, Inc.
 
リアルタイムゲームサーバーの ベンチマークをとる方法
リアルタイムゲームサーバーの ベンチマークをとる方法リアルタイムゲームサーバーの ベンチマークをとる方法
リアルタイムゲームサーバーの ベンチマークをとる方法モノビット エンジン
 
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...NTT DATA Technology & Innovation
 
PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)
PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)
PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)NTT DATA Technology & Innovation
 
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)NTT DATA Technology & Innovation
 
Microsoft Endpoint Configuration Manager 新機能のおさらい
Microsoft Endpoint Configuration Manager 新機能のおさらいMicrosoft Endpoint Configuration Manager 新機能のおさらい
Microsoft Endpoint Configuration Manager 新機能のおさらいYutaro Tamai
 

What's hot (20)

アーキテクチャ決定のお供にLightweight architecture decision records
アーキテクチャ決定のお供にLightweight architecture decision recordsアーキテクチャ決定のお供にLightweight architecture decision records
アーキテクチャ決定のお供にLightweight architecture decision records
 
Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動
Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動
Foss4G Japan 2021 シェープファイルの真の後継規格 FlatGeobufの普及啓蒙活動
 
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
 
ggplot2できれいなグラフ
ggplot2できれいなグラフggplot2できれいなグラフ
ggplot2できれいなグラフ
 
位置情報にまつわるデータ補間技術
位置情報にまつわるデータ補間技術位置情報にまつわるデータ補間技術
位置情報にまつわるデータ補間技術
 
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話
 
[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送
[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送
[Cloud OnAir] BigQuery の一般公開データセットを 利用した実践的データ分析 2019年3月28日 放送
 
Openlink Virtuoso v01
Openlink Virtuoso v01Openlink Virtuoso v01
Openlink Virtuoso v01
 
MySQLメインの人がPostgreSQLのベンチマークをしてみた話
MySQLメインの人がPostgreSQLのベンチマークをしてみた話MySQLメインの人がPostgreSQLのベンチマークをしてみた話
MySQLメインの人がPostgreSQLのベンチマークをしてみた話
 
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...
 
PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)
PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)
PostgreSQLの実行計画を読み解こう(OSC2015 Spring/Tokyo)
 
企業における自然言語処理技術利用の最先端
企業における自然言語処理技術利用の最先端企業における自然言語処理技術利用の最先端
企業における自然言語処理技術利用の最先端
 
第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」
 
本当に怖いパフォーマンスが悪い実装 #phpcon2013
本当に怖いパフォーマンスが悪い実装 #phpcon2013本当に怖いパフォーマンスが悪い実装 #phpcon2013
本当に怖いパフォーマンスが悪い実装 #phpcon2013
 
楽天のデータサイエンティスト@SAS Forum 2019
楽天のデータサイエンティスト@SAS Forum 2019楽天のデータサイエンティスト@SAS Forum 2019
楽天のデータサイエンティスト@SAS Forum 2019
 
リアルタイムゲームサーバーの ベンチマークをとる方法
リアルタイムゲームサーバーの ベンチマークをとる方法リアルタイムゲームサーバーの ベンチマークをとる方法
リアルタイムゲームサーバーの ベンチマークをとる方法
 
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...
データ活用を俊敏に進めるためのDataOps実践方法とその高度化のためのナレッジグラフ活用の取り組み(NTTデータ テクノロジーカンファレンス 2020 ...
 
PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)
PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)
PostgreSQLモニタリング機能の現状とこれから(Open Developers Conference 2020 Online 発表資料)
 
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)
 
Microsoft Endpoint Configuration Manager 新機能のおさらい
Microsoft Endpoint Configuration Manager 新機能のおさらいMicrosoft Endpoint Configuration Manager 新機能のおさらい
Microsoft Endpoint Configuration Manager 新機能のおさらい
 

Viewers also liked

Django and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks assDjango and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks assTobias Lindaaker
 
Word Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neoWord Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neoGrant Paton-Simpson
 
Persistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4jPersistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4jTobias Lindaaker
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonMax Klymyshyn
 
Creative Data Analysis with Python
Creative Data Analysis with PythonCreative Data Analysis with Python
Creative Data Analysis with PythonGrant Paton-Simpson
 
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
 
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
 
An example graph visualization with processing
An example graph visualization with processingAn example graph visualization with processing
An example graph visualization with processingMax De Marzi
 
Importing Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflowImporting Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflowNeo4j
 
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
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j InternalsTobias Lindaaker
 
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
 
Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...
Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...
Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...Kavita Ganesan
 

Viewers also liked (15)

Django and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks assDjango and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks ass
 
Word Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neoWord Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neo
 
Py2neo 1.6
Py2neo 1.6Py2neo 1.6
Py2neo 1.6
 
Persistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4jPersistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4j
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
 
Creative Data Analysis with Python
Creative Data Analysis with PythonCreative Data Analysis with Python
Creative Data Analysis with Python
 
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
 
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
 
An example graph visualization with processing
An example graph visualization with processingAn example graph visualization with processing
An example graph visualization with processing
 
Importing Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflowImporting Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflow
 
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
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j Internals
 
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
 
Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...
Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...
Opinosis Presentation @ Coling 2010: Opinosis - A Graph Based Approach to Abs...
 

Recently uploaded

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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
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
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Recently uploaded (20)

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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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!
 
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!
 
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?
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

py2neo: A Python Graph Database Connector/TITLE

  • 1. Introducing py2neo nigel@nigelsmall.name py2neo.org @technige @py2neo
  • 3. Where does py2neo fit in? (your app) py2neo GET /db/data/ 200 OK REST Server Neo4j
  • 4. Coming Up... ● Connecting & Creating ● Property Containers ● Indexes & Uniqueness ● Cypher & Geoff ● Installation ● Future Plans
  • 6. Default Connections >>> from py2neo import neo4j >>> graph_db = neo4j.GraphDatabaseService() default connection is made to <http://localhost:7474/db/data/>
  • 7. Custom Connections >>> from py2neo import neo4j >>> uri = "http://otherserv:9999/db/data/" >>> graph_db = neo4j.GraphDatabaseService(uri) >>> graph_db.neo4j_version (1, 8, u'M04', 1, u'g892e348')
  • 8. A few simple methods... >>> graph_db.get_node(0) Node('http://localhost:7474/db/data/node/0') >>> graph_db.get_reference_node() Node('http://localhost:7474/db/data/node/0') >>> graph_db.get_node_count() 1 >>> graph_db.get_relationship_count() 0
  • 9. Sample data: a family tree m (1947) Phil (1921) Liz (1926) Chaz (1948) Anne (1950) Andy (1960) Ed (1964) All characters appearing in this work are fictitious. Any resemblance to real persons, living or dead, is purely coincidental.
  • 10. list of nodes create nodes = graph_db.create( Phil Liz {"name": "Phil", "born": 1921}, {"name": "Liz", "born": 1926}, {"name": "Chaz", "born": 1948}, {"name": "Anne", "born": 1950}, Chaz Anne {"name": "Andy", "born": 1960}, {"name": "Ed", "born": 1964}, ) Andy Ed
  • 11. list of relationships create MARRIED rels = graph_db.create( Phil Liz (phil, "MARRIED", liz), (chaz, "FATHER", phil), FATHER MOTHER (chaz, "MOTHER", liz), Chaz ) node must already exist
  • 12. create family = graph_db.create( {"name": "Phil", "born": 1921}, {"name": "Liz", "born": 1926}, {"name": "Chaz", "born": 1948}, {"name": "Anne", "born": 1950}, {"name": "Andy", "born": 1960}, {"name": "Ed", "born": 1964}, (0, "MARRIED", 1, {"year": 1947, "place": "London"}), (2, "FATHER", 0), (3, "FATHER", 0), (4, "FATHER", 0), (5, "FATHER", 0), (2, "MOTHER", 1), (3, "MOTHER", 1), (4, "MOTHER", 1), (5, "MOTHER", 1), )
  • 13. list of nodes and relationships create family = graph_db.create( {"name": "Phil", "born": 1921}, {"name": "Liz", "born": 1926}, {"name": "Chaz", "born": 1948}, {"name": "Anne", "born": 1950}, {"name": "Andy", "born": 1960}, {"name": "Ed", "born": 1964}, (0, "MARRIED", 1, {"year": 1947, "place": "London"}), (2, "FATHER", 0), (3, "FATHER", 0), relationship (4, "FATHER", 0), (5, "FATHER", 0), properties (2, "MOTHER", 1), (3, "MOTHER", 1), (4, "MOTHER", 1), (5, "MOTHER", 1), ) node defined in same batch nodes, rels = family[0:6], family[6:] phil, liz, chaz, anne, andy, ed = nodes
  • 15. neo4j.PropertyContainer PropertyContainer Node Relationship
  • 16. PropertyContainers implement many of the container methods defined by the Python standard <http://docs.python.org/reference/datamodel.html#emulating-container-types>
  • 17. neo4j.PropertyContainer set property # update properties liz["star_sign"] = "Taurus" # query properties get property test property for node in nodes: containment name = node["name"] if "star_sign" in node: print name + " is a node["star_sign"] else: print name + " doesn't believe in horoscopes"
  • 18. neo4j.Node PropertyContainer Node Relationship
  • 19. Relationships and Related Nodes Chaz parental_rels = liz.get_relationships( Liz neo4j.Direction.INCOMING, "MOTHER" Anne ) Chaz parental_rels = liz.get_relationships_with( Liz chaz, neo4j.Direction.INCOMING, "MOTHER" Anne ) Chaz children = liz.get_related_nodes( Liz neo4j.Direction.INCOMING, "MOTHER" Anne )
  • 20. Relationships and Related Nodes >>> liz.has_relationship(neo4j.Direction.BOTH, "MARRIED") True >>> anne.is_related_to(phil, neo4j.Direction.OUTGOING, "FATHER") True >>> ed.is_related_to(andy, neo4j.Direction.BOTH, "BROTHER") False could also specify multiple types
  • 21. neo4j.Relationship PropertyContainer Node Relationship
  • 23. More sample data: a second tree m George (1895) Betty (1900) Liz (1926) Maggie (1930)
  • 24. m George (1895) Betty (1900) Liz (1926) Maggie (1930) m (1947) Phil (1921) Liz (1926) Chaz (1948) Anne (1950) Andy (1960) Ed (1964)
  • 25. m George (1895) Betty (1900) same person Liz (1926) Maggie (1930) m (1947) Phil (1921) Liz (1926) Chaz (1948) Anne (1950) Andy (1960) Ed (1964)
  • 26. How can we avoid duplicate nodes?
  • 28. Indexing the first family... >>> people = graph_db.get_or_create_index(neo4j.Node, "People") >>> for node in nodes: ... people.add("name", node["name"], node) >>> people.get("name", "Liz") [Node('http://localhost:7474/db/data/node/2')] list of matching entities
  • 29. ...and the second >>> new_props = [ ... {"name": "George", "born": 1895}, ... {"name": "Betty", "born": 1900}, ... {"name": "Liz", "born": 1926}, ... {"name": "Maggie", "born": 1930}, ... ] >>> george, betty, liz, maggie = [ ... people.get_or_create("name", prop["name"], prop) ... for prop in new_props same node ... ] as before >>> people.get("name", "Liz") [Node('http://localhost:7474/db/data/node/2')]
  • 30. A Quick Query >>> people.query("name:*e*") [Node('http://localhost:7474/db/data/node/4'), Node('http://localhost:7474/db/data/node/7'), Node('http://localhost:7474/db/data/node/8'), Node('http://localhost:7474/db/data/node/9')] People George name Andy name Anne Maggie name Betty name Chaz name Ed name George Anne name Liz name Maggie Betty name Phil
  • 31. We've added the nodes... what about the relationships?
  • 33. Cypher RELATE START a=node(1), b=node(2) RELATE (a)-[ab:KNOWS]->(b) RETURN ab
  • 34. Cypher RELATE a b RELATE a b a b RELATE a b ! a b RELATE
  • 35. relate new_rels = graph_db.relate( (george, "MARRIED", betty), (liz, "FATHER", george), (maggie, "FATHER", george), (liz, "MOTHER", betty), (maggie, "MOTHER", betty), George MARRIED Betty ) FATHER FATHER MOTHER MOTHER Liz Maggie
  • 36. For relationships, relate can be seen as an idempotent alternative to create
  • 37. cypher.execute >>> from py2neo import cypher >>> query = "START q=node(1) RETURN q" >>> data, metadata = cypher.execute(graph_db, query) >>> for row in data: ... q = row[0] ... print q first column
  • 38. cypher.execute >>> from py2neo import cypher >>> query = "START q=node(1) RETURN q" >>> data, metadata = cypher.execute(graph_db, query) available only after all rows received >>> for row in data: ... q = row[0] ... print q first column
  • 39. cypher.execute query = "START q=node(1) RETURN q" executed once per row as each def print_row(row): row is received q = row[0] print row cypher.execute(graph_db, query, row_handler=print_row)
  • 40. Command Line Cypher elgin@forge:~% cypher "start a=node(1) match (a)-[:MARRIED]->(b) return a, b" +------------------------------------------------------------------+ | a | b | +------------------------------------------------------------------+ | (1) {"name":"Phil","born":1921} | (2) {"name":"Liz","born":1926} | +------------------------------------------------------------------+ elgin@forge:~% cypher -f csv "start a=node(1) match (a)-[ab:MARRIED]->(b) return a, ab, b" "a","ab","b" "(1)","(1)-[0:MARRIED]->(2)","(2)" elgin@forge:~% cypher -f json "start a=node(1) match (a)-[ab:MARRIED]->(b) return a, ab, b" [ {"a": "(1)", "ab": "(1)-[0:MARRIED]->(2)", "b": "(2)"} ] elgin@forge:~% cypher -f geoff "start a=node(1) match (a)-[ab:MARRIED]->(b) return a, ab, b" (1) {"name": "Phil", "born": 1921} (2) {"name": "Liz", "born": 1926} (1)-[0:MARRIED]->(2) {"year": 1947, "place": "London"}
  • 41. Geoff is to graph data as CSV is to tabular data <http://geoff.nigelsmall.net/>
  • 42. elgin@forge:~% cypher -f geoff "start n=node(*), r=rel(*) return n, r" (0) {} (1) {"born": 1921, "name": "Phil", "family": "Windsor"} (2) {"born": 1926, "star_sign": "Taurus", "family": "Windsor", "name": "Liz"} (3) {"born": 1948, "name": "Chaz", "family": "Windsor"} (4) {"born": 1950, "name": "Anne", "family": "Windsor"} (5) {"born": 1960, "name": "Andy", "family": "Windsor"} (6) {"born": 1964, "name": "Ed", "family": "Windsor"} (7) {"born": 1895, "name": "George"} (8) {"born": 1900, "name": "Betty"} (9) {"born": 1930, "name": "Maggie"} (1)-[0:MARRIED]->(2) {"place": "London", "year": 1947} (3)-[1:FATHER]->(1) {} (4)-[2:FATHER]->(1) {} (5)-[3:FATHER]->(1) {} (6)-[4:FATHER]->(1) {} (3)-[5:MOTHER]->(2) {} (4)-[6:MOTHER]->(2) {} (5)-[7:MOTHER]->(2) {} (6)-[8:MOTHER]->(2) {} (7)-[9:MARRIED]->(8) {} (2)-[10:FATHER]->(7) {} (9)-[11:FATHER]->(7) {} (2)-[12:MOTHER]->(8) {} (9)-[13:MOTHER]->(8) {}
  • 45. Requirements ● Python 2.6+ <http://python.org/> ● Tornado 2.2.1 <http://www.tornadoweb.org/> ● Neo4j 1.6+ <http://neo4j.org/>
  • 46. Installation <http://pypi.python.org/pypi/py2neo> elgin@forge:~% sudo pip install py2neo elgin@forge:~% sudo pip install --upgrade py2neo
  • 47. Source Code <https://github.com/nigelsmall/py2neo> elgin@forge:~% git clone git@github.com:nigelsmall/py2neo.git
  • 48. Future Plans ● Fast HTTP ● Multi-threading support ● Python 3 ● Command line tools ● Property caching ● Test harness for multiple Neo4j versions ● New methods, e.g. get_paths_to
  • 49. EOF nigel@nigelsmall.name py2neo.org @technige @py2neo