Why you might need Firebase?

I am...

Intro to Firebase

Firebase

  • Backend as a Service
  • Founded in 2011
  • Launched in April 2012
  • Acquired by Google in October 2014
  • Oriented for mobile or web development

Firebase Pros

  • Easy to use
  • Web interface to edit data
  • Real-time features
  • Python/JavaScript/Android/iOS SDK
  • Frontend hosting

Firebase Cons

  • Paid Service
  • Web interface
  • Websockets

Firebase Application

How to create Firebase Application?

  • Sign up with Google Account
  • Create Application via UI
  • Setup hosting if necessary

Security & Rules

Rules to Read/Write/Validate data

{
    "rules": {
      ".read": false,
      ".write": false,

      "public": {
        ".read": true,
        ".write": true
      }
    }
}

Security & Rules

{
  "rules": {
    "messages": {
      "$message": {
        // only messages from the last ten minutes can be read
        ".read": "data.child('timestamp').val() > (now - 600000)",

        // new messages must have a string content and a number timestamp
        ".validate":
          "newData.hasChildren(['content', 'timestamp']) && "
          "newData.child('content').isString() && "
          "newData.child('timestamp').isNumber()"
      }
    }
  }
}

Login & Auth

  • Email & Password
  • Facebook
  • Twitter
  • GitHub
  • Google
  • Anonymous
  • Custom (JWT)

Login & Auth

  • Custom Authentication allows you to integrate Firebase in your SSO
  • Users in our Firebase projects log into with our SSO
  • Request to Auth -> SSO -> JWT -> Response to App

Secrets

  • Python/JavaScript/Android/iOS app can use secrets
  • Secret is an easy way to read restricted data
  • One Firebase app can have multiple secrets

What next?

  • Web UI to change data
  • python-firebase
  • Pyrebase

Web UI to change data

python-firebase

python-firebase

  • Official way to work with Firebase in Python
  • Built on top of requests
  • Making requests to Firebase REST API
  • Not actively developed

python-firebase

from firebase.firebase import FirebaseApplication
from firebase.firebase import FirebaseAuthentication
auth = FirebaseAuthentication(TOKEN, EMAIL, True, True)
ref = FirebaseApplication(URL, auth)

python-firebase

# Get value
ref.get(path, key)
# Push new value to the list
ref.post(path, value)
# Set value
ref.put(path, key, value)
# Update value
ref.patch(path, key, value)
# Delete value
ref.delete(path, key)

Pyrebase

Pyrebase

  • New way to work with Firebase in Python
  • Built on top of requests, but on Python 3.4
  • Fairly active developed

Pyrebase

from pyrebase import Firebase
ref = Firebase(URL, TOKEN)

Pyrebase

# Get value
ref.child(path).get().val()
# Add new key to the list (POST)
ref.child(path).push(value)
# Set value
ref.child(path).set(value)
# Update value
ref.child(path).update(value)
# Delete value
ref.child(path).remove()

Pyrebase

def stream_handler(posts):
    for post in posts:
        ...

stream = ref.child(path).stream(stream_handler)
...
stream.close()

Firebase & Production

Gardener App

  • ~40 Gardeners
  • Gardeners need realtime data
  • Gardener phones sometimes lose signal

Scheduler App

  • ~220 Route Templates + ~110 Routes per Week
  • Collaboration tool for Scheduling Managers
  • One Manager not allowed to overwrite work of other Manager

SketchUp Plugin

  • ~30 new Requests per day
  • Work with your infrastructure from SketchUp
  • Update House measurements in database via Firebase
  • Upload Blueprints to S3 via Firebase

Questions?