Live Streaming Data on web application using RethinkDB with python and flask

Manivannan Murugavel
3 min readSep 25, 2018

--

  • Installing steps for RethinkDB on Ubuntu16.04
  • Installing Rethinkdb connector to python
  • Making Code

Installing steps for RethinkDB in Ubuntu16.04

With binaries

We provide binaries for both 32-bit and 64-bit Ubuntu Precise and above (>= 12.04) and type the below command in your ubuntu terminal.

manivannan@manivannan:~$ source /etc/lsb-release && echo "deb 
manivannan@manivannan:~$ http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
manivannan@manivannan:~$ wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -v -"
manivannan@manivannan:~$ sudo apt-get update
manivannan@manivannan:~$ sudo apt-get install rethinkdb

Start a RethinkDB server

manivannan@manivannan:~$ rethinkdb
info: Creating directory /home/user/rethinkdb_data
info: Listening for intracluster connections on port 29015
info: Listening for client driver connections on port 28015
info: Listening for administrative HTTP connections on port 8080
info: Server ready

Note the port numbers you can use to access RethinkDB:

  • Use the intracluster port (29015 by default) to connect other nodes in the cluster to this node.
  • Point your browser to the HTTP connections port (8080 by default) to access the web interface.

For a complete list of options that can be passed to RethinkDB on the command line, read RethinkDB command line options or type rethinkdb --help at the terminal prompt.

In case you installed any application with 8080 port, please run the rethinkdb with the param “--http-port” with any port number

manivannan@manivannan:~$ rethinkdb --http-port 9090

Now the rethinkdb web interface run in 9090 port.

Installing Rethinkdb connector to python

Python driver:

manivannan@manivannan:~$ sudo pip install rethinkdb

You can use the drivers from Python like this:

manivannan@manivannan:~$ python
import rethinkdb as r
r.connect('localhost', 28015).repl()
r.db('whirldata').table_create('employees').run()
r.table('employees').insert({ 'name': 'Manivannan Murugavel' }).run()

Note: RethinkDB connection objects are not thread-safe. It’s recommended that applications open a separate connection per thread, or establish a connection pool.

Move on to the ten-minute guide and learn how to use RethinkDB.

Making Code

Create database and table in rethinkdb using python code.
DB Create
>>> r.db_create(‘whirldata’).run(conn)
Table Create
>>> r.db(‘whirldata’).table_create(‘live_streaming’).run(conn)

Now DB and Table created successfully.

Needed Python Packages

  • flask(pip install flask)
  • rethinkdb(pip install rethinkdb)

File Structure

Live-Stream
├── app.py
├── static
│ ├── css
│ │ ├── bootstrap.min.css
│ │ └── font-awesome.min.css
│ ├── fonts
│ │ ├── fontawesome-webfont.ttf
│ │ ├── fontawesome-webfont.woff
│ │ └── fontawesome-webfont.woff2
│ └── js
│ ├── bootstrap.min.js
│ ├── bootstrap-toggle.min.js
│ ├── jquery-3.2.1.min.js
│ ├── jquery-3.2.1.slim.min.js
│ └── popper.min.js
└── templates
└── live.html

The tutorial is complete and all the files i used are available in my github.
You can clone the repository and run it.

Run the code:

manivannan@manivannan-whirldatascience:~/Live-Stream$ python app.py

OUTPUT:(I have attached the youtube video)

Next: Question-Server blog

--

--

Manivannan Murugavel
Manivannan Murugavel

Written by Manivannan Murugavel

Artificial Intelligence and Data Science

Responses (2)