SlideShare a Scribd company logo
+ Google
Who?

CADEMY

Bruno Rocha
bruno@rocha.com
http://github.com/rochacbruno
http://twitter.com.rochacbruno
http://brunorocha.org
http://pythonhub.com

www.quokkaproject.org
Full Stack
Framework
Faz as escolhas por você e oferece uma
plataforma completa

Micro Framework

Define apenas o básico
(WSGI, request, response, session etc)

(ORM, Templates, Organização de arquivos,
arquivos de configurações, etc)
+ Fácil
- controle

Crescimento gradativo
+ trabalhoso
+ controle
What The Flask?
Flask is a microframework for Python based
on Werkzeug, Jinja 2 and good intentions.
Werkzeug - WSGI library

from werkzeug.serving import run_simple
from werkzeug.wrappers import Request, Response
@Request.application
def application(request):
return Response('Hello World!')
run_simple('localhost', 4000, application)
Jinja - Template engine

{% macro render_user(user) %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endmacro %}

{% from _above_file.html import render_user %}
<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
{{ render_user(user) }}
{% endfor %}
</ul>
Good intentions.

# thread locals
from flask import request, session, g
# extensions
from flask.ext import AmazingExtension
# blueprints
from flask import Blueprint
blog = Blueprint(“blog_blueprint”)
blog.template_folder = “path/to/folder”
blog.static_folder = “path/to/static”
# Application factory
app = create_app(**kwargs)
app.register_blueprint(blog)
AmazingExtension(app)
It is not a framework, it is a pattern!

Good intentions

flask.ext.*
your_app.py
your_app.py
$ pip install flask, flask-security, flask-admin, xpto-orm
from
from
from
from
from

flask import Flask
flask.ext.security import Security
flask.ext.admin import Admin
somewhere.db.models import UserDatastore
somewhere.views import indexpage

def create_app(**config):
app = Flask(“myapp”)
app.config_from_object(config)
Admin(app)
Security(app, UserDatastore)
app.add_url_rule(“/index/<something>”, view_func=indexpage)
return app
if __name__ == “__main__”:
app = create_app(SECRET_KEY=”XYZ”)
app.run()
Blueprints
Um Blueprint funciona de forma similar a um objeto Flask, mas na verdade não
é uma aplicação, mas sim um projeto de como construir ou extender uma
aplicação

from flask import Blueprint, render_template
blog_extension = Blueprint(“my_blog_extension”)
blog_extension.endpoint = “/blog”
blog_extension.template_folder = “path/to/blog_templates”
blog_extension.static_folder = “path/to/blog_static”
@blog_extension.route(“/index”)
def blog():
posts = some_db_or_orm.posts.query()
return render_template(“blog.html”, posts=posts)
blog_blueprint.py
from blog_blueprint import blog_extension

your_app.py

def create_app(**config):
app = Flask(“myapp”)
...
app.register_blueprint(blog_extension)
return app
●

●

Flask subclass
○ class MyOwnFlask(Flask):
pass
application factory
○ app = create_app(**config)
○ evitar import circular

●

Blueprints
○ Mesmo que seja uma one-page-app

●

Flask-Admin
○ Modular, insira qualquer view no admin, crud completo, actions, filters

●

Flask-Security
○ Login, Logout, Lembrar senha, Register, Access control, permissions

●

Flask-script
○ python manage.py faça_me_um_sanduiche

●

app.config_from_envvar
○ Settings desacoplado da app
○ export APP_SETTINGS=”/path/to/settings.cfg”
○ app.config_from_envvar(“APP_SETTINGS”)
and Google ?
http://bit.ly/flask-gae
# app.yaml
application : nome_do_app
version : 1
runtime : python27
api_version : 1
threadsafe: true
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
handlers:
- url: /static
static_dir : your_app_folder/static
- url: .*
script : main.app

# your_app.py
from flask import Flask
def create_app():
app = Flask(__name__)
return app
# main.py
from werkzeug import DebuggedApplication
from your_app import create_app
app = DebuggedApplication(create_app())
https://github.com/sashka/flask-googleauth
# your_app.py
from flask import Flask
from flask.ext.googleauth import GoogleFederated
from .configurator import register_views
def create_app():
app = Flask(__name__)
app.secret_key = “XYZ”
auth = GoogleFederated("dominio.com", app)
register_views(app, auth)
return app

# configurator.py
from .views import myview, …, ...
def register_views(app, auth)
secret = auth.required(myview)
app.add_url_rule(“/secret/”, view_func=secret)
…
...

# views.py
from flask import g
def myview()
return "Logged user, %s (%s)" % (g.user.name, g.user.email)
…
...
github.com/rochacbruno/Flask-GoogleMaps
pip install flask-googlemaps

from flask import Flask
from flask.ext.googlemaps import GoogleMaps
app = Flask(__name__)
GoogleMaps(app)

<div>
{{googlemap("my_awesome_map", 0.23234234, -0.234234234, markers=[(0.12, -0.45345), ...])}}
</div>
Thank you!
Bruno Rocha
http://brunorocha.org
bruno@rocha.com
http://github.com/rochacbruno
http://twitter.com.rochacbruno
http://pythonhub.com

www.quokkaproject.org

More Related Content

PDF
Python Flask app deployed to OPenShift using Wercker CI
PDF
Flask Introduction - Python Meetup
PPT
Learn flask in 90mins
PDF
Quick flask an intro to flask
KEY
LvivPy - Flask in details
PPTX
Powershell: Tu nuevo mejor amigo
PDF
Build website in_django
PPTX
Python Flask app deployed to OPenShift using Wercker CI
Flask Introduction - Python Meetup
Learn flask in 90mins
Quick flask an intro to flask
LvivPy - Flask in details
Powershell: Tu nuevo mejor amigo
Build website in_django

What's hot (20)

PPTX
Python/Flask Presentation
PPTX
Wykorzystanie form request przy implementacji API w Laravelu
PDF
Web development automatisation for fun and profit (Artem Daniliants)
PPTX
Laravel Beginners Tutorial 1
PDF
Intro to Laravel 4
PDF
Datagrids with Symfony 2, Backbone and Backgrid
PPTX
Symfony2 Introduction Presentation
PDF
Alfresco study37 alfresco_ng2_components
ODP
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...
PPTX
Getting started with Salesforce DX & CLI
PPT
Learn Dashing Widget in 90 minutes
PPTX
A few good JavaScript development tools
ZIP
Voiture tech talk
PPTX
Python from zero to hero (Twitter Explorer)
PDF
Add new commands in appium 2.0
PPTX
Laravel for Web Artisans
PPTX
Plugin development wpmeetup010
PDF
Manage appium dependencies with -appium-home in appium 2.0
PDF
Scalable web application architecture
PDF
RESTful API development in Laravel 4 - Christopher Pecoraro
Python/Flask Presentation
Wykorzystanie form request przy implementacji API w Laravelu
Web development automatisation for fun and profit (Artem Daniliants)
Laravel Beginners Tutorial 1
Intro to Laravel 4
Datagrids with Symfony 2, Backbone and Backgrid
Symfony2 Introduction Presentation
Alfresco study37 alfresco_ng2_components
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...
Getting started with Salesforce DX & CLI
Learn Dashing Widget in 90 minutes
A few good JavaScript development tools
Voiture tech talk
Python from zero to hero (Twitter Explorer)
Add new commands in appium 2.0
Laravel for Web Artisans
Plugin development wpmeetup010
Manage appium dependencies with -appium-home in appium 2.0
Scalable web application architecture
RESTful API development in Laravel 4 - Christopher Pecoraro
Ad

Viewers also liked (8)

PDF
PyData - Consumindo e publicando web APIs com Python
PPTX
Dynamically Generate a CRUD Admin Panel with Java Annotations
PDF
Play Framework on Google App Engine
PDF
Flask admin vs. DIY
PDF
Django para portais de alta visibilidade. tdc 2013
PDF
Web develop in flask
PPTX
Flask – Python
PDF
When to use Node? Lessons learned
PyData - Consumindo e publicando web APIs com Python
Dynamically Generate a CRUD Admin Panel with Java Annotations
Play Framework on Google App Engine
Flask admin vs. DIY
Django para portais de alta visibilidade. tdc 2013
Web develop in flask
Flask – Python
When to use Node? Lessons learned
Ad

Similar to What The Flask? and how to use it with some Google APIs (20)

PPTX
Django web framework
PDF
JCConf 2016 - Dataflow Workshop Labs
PPTX
Django Architecture Introduction
PDF
Introduction to Django
PDF
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
PDF
Filling the flask
ODP
Pyramid Lighter/Faster/Better web apps
PPS
Simplify your professional web development with symfony
PDF
Django introduction
PDF
Django tricks (2)
PDF
بررسی چارچوب جنگو
PDF
Pyramid Deployment and Maintenance
PDF
django_introduction20141030
PPT
DJango
PDF
Flask intro - ROSEdu web workshops
PDF
Automated User Tests with Apache Flex
PDF
using Mithril.js + postgREST to build and consume API's
PPTX
Django Portfolio Website Workshop (1).pptx
PPT
Performance and Scalability Testing with Python and Multi-Mechanize
Django web framework
JCConf 2016 - Dataflow Workshop Labs
Django Architecture Introduction
Introduction to Django
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Filling the flask
Pyramid Lighter/Faster/Better web apps
Simplify your professional web development with symfony
Django introduction
Django tricks (2)
بررسی چارچوب جنگو
Pyramid Deployment and Maintenance
django_introduction20141030
DJango
Flask intro - ROSEdu web workshops
Automated User Tests with Apache Flex
using Mithril.js + postgREST to build and consume API's
Django Portfolio Website Workshop (1).pptx
Performance and Scalability Testing with Python and Multi-Mechanize

More from Bruno Rocha (15)

PDF
Escrevendo modulos python com rust
PDF
The quality of the python ecosystem - and how we can protect it!
PDF
A Qualidade do Ecossistema Python - e o que podemos fazer para mante-la
PPTX
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
PDF
Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015
PDF
Carreira de Programador e Mercado de Trabalho
PDF
Quokka CMS - Content Management with Flask and Mongo #tdc2014
PDF
Web Crawling Modeling with Scrapy Models #TDC2014
PDF
Flask for CMS/App Framework development.
PDF
Desenvolvendo mvp com python
PDF
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
PDF
Guia alimentar de dietas vegetarianas para adultos
ODP
Desmistificando web2py - #TDC2011
PDF
Using web2py's DAL in other projects or frameworks
PPT
Desenvolvimento web ágil com Python e web2py #qconsp #qcon
Escrevendo modulos python com rust
The quality of the python ecosystem - and how we can protect it!
A Qualidade do Ecossistema Python - e o que podemos fazer para mante-la
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015
Carreira de Programador e Mercado de Trabalho
Quokka CMS - Content Management with Flask and Mongo #tdc2014
Web Crawling Modeling with Scrapy Models #TDC2014
Flask for CMS/App Framework development.
Desenvolvendo mvp com python
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
Guia alimentar de dietas vegetarianas para adultos
Desmistificando web2py - #TDC2011
Using web2py's DAL in other projects or frameworks
Desenvolvimento web ágil com Python e web2py #qconsp #qcon

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
cuic standard and advanced reporting.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine learning based COVID-19 study performance prediction
Programs and apps: productivity, graphics, security and other tools
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
cuic standard and advanced reporting.pdf
The AUB Centre for AI in Media Proposal.docx
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars

What The Flask? and how to use it with some Google APIs

  • 3. Full Stack Framework Faz as escolhas por você e oferece uma plataforma completa Micro Framework Define apenas o básico (WSGI, request, response, session etc) (ORM, Templates, Organização de arquivos, arquivos de configurações, etc) + Fácil - controle Crescimento gradativo + trabalhoso + controle
  • 4. What The Flask? Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.
  • 5. Werkzeug - WSGI library from werkzeug.serving import run_simple from werkzeug.wrappers import Request, Response @Request.application def application(request): return Response('Hello World!') run_simple('localhost', 4000, application)
  • 6. Jinja - Template engine {% macro render_user(user) %} <li><a href="{{ user.url }}">{{ user.username }}</a></li> {% endmacro %} {% from _above_file.html import render_user %} <title>{% block title %}{% endblock %}</title> <ul> {% for user in users %} {{ render_user(user) }} {% endfor %} </ul>
  • 7. Good intentions. # thread locals from flask import request, session, g # extensions from flask.ext import AmazingExtension # blueprints from flask import Blueprint blog = Blueprint(“blog_blueprint”) blog.template_folder = “path/to/folder” blog.static_folder = “path/to/static” # Application factory app = create_app(**kwargs) app.register_blueprint(blog) AmazingExtension(app)
  • 8. It is not a framework, it is a pattern! Good intentions flask.ext.* your_app.py
  • 9. your_app.py $ pip install flask, flask-security, flask-admin, xpto-orm from from from from from flask import Flask flask.ext.security import Security flask.ext.admin import Admin somewhere.db.models import UserDatastore somewhere.views import indexpage def create_app(**config): app = Flask(“myapp”) app.config_from_object(config) Admin(app) Security(app, UserDatastore) app.add_url_rule(“/index/<something>”, view_func=indexpage) return app if __name__ == “__main__”: app = create_app(SECRET_KEY=”XYZ”) app.run()
  • 10. Blueprints Um Blueprint funciona de forma similar a um objeto Flask, mas na verdade não é uma aplicação, mas sim um projeto de como construir ou extender uma aplicação from flask import Blueprint, render_template blog_extension = Blueprint(“my_blog_extension”) blog_extension.endpoint = “/blog” blog_extension.template_folder = “path/to/blog_templates” blog_extension.static_folder = “path/to/blog_static” @blog_extension.route(“/index”) def blog(): posts = some_db_or_orm.posts.query() return render_template(“blog.html”, posts=posts) blog_blueprint.py from blog_blueprint import blog_extension your_app.py def create_app(**config): app = Flask(“myapp”) ... app.register_blueprint(blog_extension) return app
  • 11. ● ● Flask subclass ○ class MyOwnFlask(Flask): pass application factory ○ app = create_app(**config) ○ evitar import circular ● Blueprints ○ Mesmo que seja uma one-page-app ● Flask-Admin ○ Modular, insira qualquer view no admin, crud completo, actions, filters ● Flask-Security ○ Login, Logout, Lembrar senha, Register, Access control, permissions ● Flask-script ○ python manage.py faça_me_um_sanduiche ● app.config_from_envvar ○ Settings desacoplado da app ○ export APP_SETTINGS=”/path/to/settings.cfg” ○ app.config_from_envvar(“APP_SETTINGS”)
  • 13. http://bit.ly/flask-gae # app.yaml application : nome_do_app version : 1 runtime : python27 api_version : 1 threadsafe: true libraries: - name: jinja2 version: "2.6" - name: markupsafe version: "0.15" handlers: - url: /static static_dir : your_app_folder/static - url: .* script : main.app # your_app.py from flask import Flask def create_app(): app = Flask(__name__) return app # main.py from werkzeug import DebuggedApplication from your_app import create_app app = DebuggedApplication(create_app())
  • 14. https://github.com/sashka/flask-googleauth # your_app.py from flask import Flask from flask.ext.googleauth import GoogleFederated from .configurator import register_views def create_app(): app = Flask(__name__) app.secret_key = “XYZ” auth = GoogleFederated("dominio.com", app) register_views(app, auth) return app # configurator.py from .views import myview, …, ... def register_views(app, auth) secret = auth.required(myview) app.add_url_rule(“/secret/”, view_func=secret) … ... # views.py from flask import g def myview() return "Logged user, %s (%s)" % (g.user.name, g.user.email) … ...
  • 15. github.com/rochacbruno/Flask-GoogleMaps pip install flask-googlemaps from flask import Flask from flask.ext.googlemaps import GoogleMaps app = Flask(__name__) GoogleMaps(app) <div> {{googlemap("my_awesome_map", 0.23234234, -0.234234234, markers=[(0.12, -0.45345), ...])}} </div>