Skip to content
Create python web applications for Google Glass
Python CSS
Latest commit 846638d Dec 28, 2013 @SamyPesse Remove codenow link
Failed to load latest commit information.

A simple but powerful library for building and testing Google Glass applications in Python using Mirror API. uses Flask, Requests and Rauth.

I started this project for testing development of applications for Glass using Mirror API, but I'm not part of Explorer Program, so this library will soon contain an emulator.


  • Post cards to timelines
  • Get notification from subscriptions
  • [Coming soon] Emulator for testing the application
  • Built on Requests (v1.x)
  • Built on Flask


Clone this repository :

git clone

Install dependencies :

pip install -r requirements.txt

Install the library (maybe need to be sudo) :

pip install .

Test an Hello World with the emulator

python examples/

Example Usage

Full examples available at master/examples. Complete example of a Foursquare application available at master/examples/foursquare.

Get started

A simple helloworld which display a message when the user connect the application to his Glasses.

import glass

app = glass.Application(

def login(user):
    print "user : %s" % user.token"Hello World!")

if __name__ == '__main__':


Google Glass mirror API uses oAuth for authorizing an application to connect to the glasses. Go to the Google APIs console and create a new API project. Enable the Google Mirror API for your new project. The API is only available to developers who have Glass as part of the Explorer Program, so if it's not available for you, just pass this step. Specify http://localhost:8080/glass/oauth/callback as callback url.

For authorizing the application to connect to your glasses, access the page : http://localhost:8080/glass/oauth/authorize If you don't have Glass as part of the Explorer Program, use the emulator.


Enable the emulator (which will run at localhost:8080/emulator/index.html), emulator user can be identified by his token : "emulator". Emulator is not working yet and it's based on

app.emulator = True

Insert Cards in timeline

Post text cards :"Hello World!")

Post HTML cards :"Hello <b>World</b>")

Post HTML templates, templates are processed using Jinja2 template engine. For templates you can use the full power of Jinja2 templates. Head over to the official Jinja2 Template Documentation for more information.

user.timeline.post_template("message.html", author="Aaron", content="Hey, How are you ?")

Define the directory for the templates using :

app.template_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')

Subscribe to actions

Subscribe to an action "REPLY" :

def reply(user):
    print "User %s reply" % user.token"Thank you!")

A new location is available for the current user, At this time, location notifications are sent every 10 minutes :

def change_location(user):
    print "User %s change location" % user.token"You move !")

Access the user last known location using :

def change_location(user):
    # Get last known location
    location = user.location()

    # Post card with location infos"You move to (Lat: %s, Long: %s) (Accuracy: %s meters)" % (

Get user informations

Get profile data using :

profile = user.profile()
print "Hello %s" % (profile.get("given_name"))

Get last known user location :

location = user.location()
print "User is at (Lat: %s, Long: %s) (Accuracy: %s meters)" % (

Managing user contacts

Inserts a new contact for the authenticated user :

user.contacts.insert(displayName="John Doe", id="johndoe", imageUrls=["http://.....png"])

Retrieves a list of contacts for the authenticated user :

contacts = user.contacts.list()
for contact in contacts:
    print "%s : %s" % (contact.get("id"), contact.get("displayName"))

Gets a single contact item by ID.

card = user.contacts.get("id_of_the_contact")
print "%s : %s" % (contact.get("id"), contact.get("displayName"))

Updates a contact in place. This method supports patch semantics.

contact = user.contacts.patch("id_of_the_contact", text="Hello World (2)!")
print "%s : %s" % (contact.get("id"), contact.get("displayName"))

Deletes a contact.


Advanced timeline gestion

Retrieves a list of timeline items for the authenticated user.

cards = user.timeline.list()
for card in cards:
    print "%s :" % (card.get("id")), card

Gets a single timeline item by ID.

card = user.timeline.get("id_of_the_card")
print "%s :" % (card.get("id")), card

Updates a timeline item in place. This method supports patch semantics.

card = user.timeline.patch("id_of_the_card", text="Hello World (2)!")
print "%s :" % (card.get("id")), card

Deletes a timeline item.


Accessing the Flask web server

You can access the flask applciation for adding views (like index, about pages, ...) using :

def index():
    return "Welcome on my Glass Application website !"

Store users in a database

If you are application need to store glass user credentials for use in the future :

tokens = user.tokens
# tokens is dict with "access_token" and "refersh_token" to store in your user object in the database

Later, initialize a glass user from these stored tokens :

# get the tokens dict from your database
user = glass.User(app=app, tokens=tokens)

Handle offline access and refresh tokens let you manage in a simple way the offline access and refresh tokens, when an glass.exceptions.RefreshTokenException is raised :

    # Try to get user profile
    profile = user.profile()
except glass.exceptions.RefreshTokenException, e:
    # Access token is no longer valid : refresh token
    new_tokens = user.refresh_token()

    # And Store in the database the new acess token (new_tokens["access_token"])
Something went wrong with that request. Please try again.