Jupyter and RethinkDB

Ba70f10866cbab0bc6b9b1d547ef8015?s=47 Ryan Paul
August 26, 2015

Jupyter and RethinkDB

Learn how to use RethinkDB with Jupyter, a rich platform for interactive programming built on top of the powerful IPython REPL. In this talk, I'll demonstrate how to perform ReQL queries in a Jupyter notebook, integrating with matplotlib and other libraries to generate data visualizations.

Ba70f10866cbab0bc6b9b1d547ef8015?s=128

Ryan Paul

August 26, 2015
Tweet

Transcript

  1. 8.

    • Rich interactive REPL with terminal and desktop frontends •

    Persistent REPL notebook that can evaluate code and save results What is Jupyter?
  2. 9.

    • Language-agnostic platform abstracted out of IPython • IPython itself

    now provides Jupyter’s Python kernel • Wide range of other programming languages are supported What is Jupyter?
  3. 10.

    • Interactive literate programming environment that runs in browser •

    Combine code snippets and output with rich text content • Displays embedded content like visualizations Jupyter Notebook
  4. 12.

    What is RethinkDB? • Open source database for building realtime

    web applications • NoSQL database that stores schemaless JSON documents • Distributed database that is easy to scale • High availability database that is resilient against failure
  5. 13.

    ReQL & Jupyter • ReQL is the RethinkDB query language

    • ReQL integrates with syntax of the underlying language • ReQL is expressive and provides useful tools for data manipulation
  6. 17.

    • Add special commands to Jupyter that work on REPL

    and notebook • Typically prefixed with a % sign • Can programmatically transform user input Magic Functions
  7. 18.

    Magic Functions from IPython.core.magic import register_line_magic @register_line_magic def r(line): import

    rethinkdb as r conn = r.connect() response = eval(line).run(conn) if type(response) == r.net.DefaultCursor: response = list(response) print to_pretty_json(response) conn.close()
  8. 19.

    • Jupyter provides APIs for displaying rich content • Can

    embed images, HTML, JSON, and other kinds of content • Import from IPython.display Display Functions
  9. 22.

    Using Matplotlib %matplotlib inline from matplotlib import pyplot import rethinkdb

    as r conn = r.connect() quakes = r.table("quake") \ .filter(r.row["time"].month() == r.now().month()) \ .group(r.row["time"].day()).count() \ .ungroup().order_by(r.row["group"]) \ .do([r.row["group"], r.row["reduction"]]).run(conn) conn.close() pyplot.bar(quakes[0], quakes[1]) pyplot.show()
  10. 23.

    Using Matplotlib %matplotlib inline import mplleaflet from matplotlib import pyplot

    import rethinkdb as r conn = r.connect() near_tokyo = list(r.table("quake").get_intersecting( r.circle([139.69, 35.68], 200, unit="mi"), index="geometry") ["geometry"] \ .map(r.row.to_geojson()["coordinates"]).run(conn)) conn.close() pyplot.plot([p[0] for p in near_tokyo], [p[1] for p in near_tokyo], 'rs') mplleaflet.display()