SlideShare a Scribd company logo
1 of 16
Download to read offline
+ 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

What's hot

Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask PresentationParag Mujumdar
 
Wykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w LaraveluWykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w LaraveluLaravel Poland MeetUp
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)LumoSpark
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
Alfresco study37 alfresco_ng2_components
Alfresco study37 alfresco_ng2_componentsAlfresco study37 alfresco_ng2_components
Alfresco study37 alfresco_ng2_componentsTakeshi Totani
 
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...Juliano Martins
 
Getting started with Salesforce DX & CLI
Getting started with Salesforce DX & CLIGetting started with Salesforce DX & CLI
Getting started with Salesforce DX & CLIMichael Gill
 
Learn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLearn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLarry Cai
 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development toolsSimon Kim
 
Voiture tech talk
Voiture tech talkVoiture tech talk
Voiture tech talkHoppinger
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Yuriy Senko
 
Add new commands in appium 2.0
Add new commands in appium 2.0Add new commands in appium 2.0
Add new commands in appium 2.0Kazuaki Matsuo
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
Plugin development wpmeetup010
Plugin development wpmeetup010Plugin development wpmeetup010
Plugin development wpmeetup010Barry Kooij
 
Manage appium dependencies with -appium-home in appium 2.0
Manage appium dependencies with  -appium-home in appium 2.0Manage appium dependencies with  -appium-home in appium 2.0
Manage appium dependencies with -appium-home in appium 2.0Kazuaki Matsuo
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 

What's hot (20)

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

Viewers also liked

PyData - Consumindo e publicando web APIs com Python
PyData - Consumindo e publicando web APIs com PythonPyData - Consumindo e publicando web APIs com Python
PyData - Consumindo e publicando web APIs com PythonBruno Rocha
 
Dynamically Generate a CRUD Admin Panel with Java Annotations
Dynamically Generate a CRUD Admin Panel with Java AnnotationsDynamically Generate a CRUD Admin Panel with Java Annotations
Dynamically Generate a CRUD Admin Panel with Java AnnotationsBroadleaf Commerce
 
Play Framework on Google App Engine
Play Framework on Google App EnginePlay Framework on Google App Engine
Play Framework on Google App EngineFred Lin
 
Flask admin vs. DIY
Flask admin vs. DIYFlask admin vs. DIY
Flask admin vs. DIYdokenzy
 
Django para portais de alta visibilidade. tdc 2013
Django para portais de alta visibilidade.   tdc 2013Django para portais de alta visibilidade.   tdc 2013
Django para portais de alta visibilidade. tdc 2013Bruno Rocha
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flaskJim Yeh
 
When to use Node? Lessons learned
When to use Node? Lessons learnedWhen to use Node? Lessons learned
When to use Node? Lessons learnedbeatlevic
 

Viewers also liked (8)

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

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

JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsJCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsSimon Su
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Edureka!
 
Build Secure Cloud-Hosted Apps for SharePoint 2013
Build Secure Cloud-Hosted Apps for SharePoint 2013Build Secure Cloud-Hosted Apps for SharePoint 2013
Build Secure Cloud-Hosted Apps for SharePoint 2013Danny Jessee
 
Filling the flask
Filling the flaskFilling the flask
Filling the flaskJason Myers
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsDylan Jay
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگوrailsbootcamp
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and MaintenanceJazkarta, Inc.
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030Kevin Wu
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsAlex Eftimie
 
Automated User Tests with Apache Flex
Automated User Tests with Apache FlexAutomated User Tests with Apache Flex
Automated User Tests with Apache FlexGert Poppe
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanizecoreygoldberg
 

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

Django web framework
Django web frameworkDjango web framework
Django web framework
 
JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsJCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop Labs
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 
Build Secure Cloud-Hosted Apps for SharePoint 2013
Build Secure Cloud-Hosted Apps for SharePoint 2013Build Secure Cloud-Hosted Apps for SharePoint 2013
Build Secure Cloud-Hosted Apps for SharePoint 2013
 
Filling the flask
Filling the flaskFilling the flask
Filling the flask
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Django introduction
Django introductionDjango introduction
Django introduction
 
Gwt.create
Gwt.createGwt.create
Gwt.create
 
Django tricks (2)
Django tricks (2)Django tricks (2)
Django tricks (2)
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
DJango
DJangoDJango
DJango
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshops
 
Automated User Tests with Apache Flex
Automated User Tests with Apache FlexAutomated User Tests with Apache Flex
Automated User Tests with Apache Flex
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 

More from Bruno Rocha

Escrevendo modulos python com rust
Escrevendo modulos python com rustEscrevendo modulos python com rust
Escrevendo modulos python com rustBruno Rocha
 
The quality of the python ecosystem - and how we can protect it!
The quality of the python ecosystem - and how we can protect it!The quality of the python ecosystem - and how we can protect it!
The quality of the python ecosystem - and how we can protect it!Bruno Rocha
 
A Qualidade do Ecossistema Python - e o que podemos fazer para mante-la
A Qualidade do Ecossistema Python - e o que podemos fazer para mante-laA Qualidade do Ecossistema Python - e o que podemos fazer para mante-la
A Qualidade do Ecossistema Python - e o que podemos fazer para mante-laBruno Rocha
 
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015Bruno Rocha
 
Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015
Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015
Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015Bruno Rocha
 
Carreira de Programador e Mercado de Trabalho
Carreira de Programador e Mercado de TrabalhoCarreira de Programador e Mercado de Trabalho
Carreira de Programador e Mercado de TrabalhoBruno Rocha
 
Quokka CMS - Content Management with Flask and Mongo #tdc2014
Quokka CMS - Content Management with Flask and Mongo #tdc2014Quokka CMS - Content Management with Flask and Mongo #tdc2014
Quokka CMS - Content Management with Flask and Mongo #tdc2014Bruno Rocha
 
Web Crawling Modeling with Scrapy Models #TDC2014
Web Crawling Modeling with Scrapy Models #TDC2014Web Crawling Modeling with Scrapy Models #TDC2014
Web Crawling Modeling with Scrapy Models #TDC2014Bruno Rocha
 
Flask for CMS/App Framework development.
Flask for CMS/App Framework development.Flask for CMS/App Framework development.
Flask for CMS/App Framework development.Bruno Rocha
 
Desenvolvendo mvp com python
Desenvolvendo mvp com pythonDesenvolvendo mvp com python
Desenvolvendo mvp com pythonBruno Rocha
 
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDBFlask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDBBruno Rocha
 
Guia alimentar de dietas vegetarianas para adultos
Guia alimentar de dietas vegetarianas para adultosGuia alimentar de dietas vegetarianas para adultos
Guia alimentar de dietas vegetarianas para adultosBruno Rocha
 
Desmistificando web2py - #TDC2011
Desmistificando web2py - #TDC2011Desmistificando web2py - #TDC2011
Desmistificando web2py - #TDC2011Bruno Rocha
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksBruno Rocha
 
Desenvolvimento web ágil com Python e web2py #qconsp #qcon
Desenvolvimento web ágil com Python e web2py #qconsp #qconDesenvolvimento web ágil com Python e web2py #qconsp #qcon
Desenvolvimento web ágil com Python e web2py #qconsp #qconBruno Rocha
 

More from Bruno Rocha (15)

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

Recently uploaded

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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>