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

Getting Started with Graph Database with Python

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for loftkun loftkun
October 10, 2019

Getting Started with Graph Database with Python

2019/10/10 Thu

PyFukuoka #7 - connpass
https://fukuoka-python.connpass.com/event/147318/

- Graph Database
- GitHub GraphQL API v4
- Neo4J

Avatar for loftkun

loftkun

October 10, 2019
Tweet

More Decks by loftkun

Other Decks in Technology

Transcript

  1. About Me • @loftkun • ヤフー株式会社 • サービスプラットフォーム本部 • 将棋(初段)

    / ピアノ(独学) / LIVE(スピッツetc) • Python歴 3年くらい • 週1参加・月1登壇
  2. Graph User User User Tweet Tweet Follow Post Tweet Tweet

    NodeにもEdgeにも 属性(Property, Label)を付与できる name : ロフトくん followers : 1 following : 2 name : hoge followers : 1 following : 0 name : fuga followers : 1 following : 1 text : hello text : むくり text :おやす text : python!!
  3. Graph Database • Graph構造を扱えるデータベース • AWS • Amazon Neptune •

    Azure • Cosmos DB がグラフデータモデルをサポート • GCP • GKEにJanusGraphをデプロイ ( https://cloud.google.com/solutions/running- janusgraph-with-bigtable?hl=ja ) • OSS • Neo4J
  4. Case • ソーシャルグラフ • Web上での人間の相関関係 • Facebook グラフAPI ( https://developers.facebook.com/docs/graph-api

    ) • 最短経路問題 • 鉄道路線、カーナビ • 最短経路 = 各Edgeに付与した重み(距離)の合計が最も少ない経路
  5. Case • イレギュラーなパターンの発見 • クレジットカード等の不正利用検知 • 通常と異なる経路の検出 • https://neo4j.com/developer/ (Fraud

    Detection) • パナマ文書や銀行顧客情報のICIJ国際調査報道ジャーナリスト連合によ る解析 ( Neo4j + Linkrious ) • https://www.itmedia.co.jp/enterprise/articles/1605/25/news024.html • 前職でやっていたこと • IaaSの構成物( 物理マシン、VM、ストレージ、NW )をGraph構造で定義 &可視化 • Node(VM)を2つクリックしたら経路(Edge) を表示など
  6. GitHub GraphQL API v4 • v3 は REST だが、v4 は

    GraphQL APIとなっている • Why GitHub is using GraphQL • GraphQL lets you replace multiple REST requests with a single call to fetch the data you specify => 複数のRESTリクエストを1回の呼び出しに置き換えられる • v3はPRやIssueなどエンドポイントが分かれている • v4 はエンドポイントは1つ https://developer.github.com/v4/
  7. Explorer • 左ペインにGraphQLを書いて実行で きる • Tyr & Errorに便利 • Syntax

    Checkもやってくれる • マウスオーバーで型の説明も出る https://developer.github.com/v4/explorer/?variables=%7B%7D&query=query%20%7B%0A%20%20__ty pe%28name%3A%20%22Repository%22%29%20%7B%0A%20%20%20%20name%0A%20%20%20%20ki nd%0A%20%20%20%20description%0A%20%20%20%20fields%20%7B%0A%20%20%20%20%20%20na me%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D
  8. Authentication & Authorization • v3 (REST)では必須ではない • 認証しない場合はrate limit制限が厳しくなる •

    v4 (GraphQL) では必須 • Basic認証 • あまりパスワードは使いたくない・・・ • OAuth認証 • 権限設定できるのでおすすめ • OAuth用のtokenが必要となる • Settings --> Developer settings ( https://github.com/settings/apps ) で作成しておく • もしくはAuthorizations APIで作成できる
  9. Python Star Ranking : 6 -10 rank stars name description

    6 48441 nvbn/thefuck Magnificent app which corrects your previous console command. 7 46840 pallets/flask The Python micro framework for building web applications. 8 44585 keras-team/keras Deep Learning for humans 9 44494 django/django The Web framework for perfectionists with deadlines. 10 43363 jakubroztocil/httpie As easy as HTTPie /aitch-tee-tee-pie/ Modern command line HTTP client
  10. Python Star Ranking : 1 - 5 rank stars name

    description 1 74412 donnemartin/system- design-primer Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards. 2 73840 vinta/awesome-python A curated list of awesome Python frameworks, libraries, software and resources 3 63299 public-apis/public-apis A collective list of free APIs for use in software and web development. 4 58120 tensorflow/models Models and examples built with TensorFlow 5 56406 ytdl-org/youtube-dl Command-line program to download videos from YouTube.com and other video sites
  11. Neo4J • World's leading graph database • クエリ言語 • Cypher

    ( default ) • Gremlin • プロトコル • Bolt ( バイナリプロトコル ) • HTTP-API • ドライバ • Python / Go / JS / Java / .NET / Ruby / PHP / etc https://neo4j.com/developer/
  12. Summary • Pythonで GitHub GraphQL API v4 と Neo4J を操作してみた

    • それぞれWebUIがあり、クエリの組み立てに便利だった • 特にNeo4JのDashboardは可視化もしてくれるのが便利 • 採用されているクエリ言語が異なるためそれぞれ学習が必要だ • 世の中の事例も参考にし、Graph構造が適していそうなデータ を操作する際はGraph Databaseを活用していきたい