Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Flask
Search
Sébastien Fievet
February 23, 2017
Technology
0
60
Introduction to Flask
Workshop given for a Swisscom Digital Lab meetup at EPFL
Sébastien Fievet
February 23, 2017
Tweet
Share
More Decks by Sébastien Fievet
See All by Sébastien Fievet
Django Round-Up – Meetup Django CH #28
zyegfryed
0
58
Django Round-Up – Meetup Django CH #25
zyegfryed
0
54
Django Round-Up – Meetup Django CH #23
zyegfryed
0
50
Django Round-Up – Meetup Django CH #21
zyegfryed
0
67
Django Round-Up – Meetup Django CH #20
zyegfryed
0
65
Django Round-Up – Meetup Django CH #19
zyegfryed
2
85
[Django] URL prefix with runserver
zyegfryed
0
1.4k
[Django] Generating PDF with PDFForm
zyegfryed
0
85
[Django] RESTful API
zyegfryed
1
220
Other Decks in Technology
See All in Technology
SRE不在の開発チームが障害対応と 向き合った100日間 / 100 days dealing with issues without SREs
shin1988
1
250
ビズリーチが挑む メトリクスを活用した技術的負債の解消 / dev-productivity-con2025
visional_engineering_and_design
3
7.9k
開発生産性を組織全体の「生産性」へ! 部門間連携の壁を越える実践的ステップ
sudo5in5k
3
7.4k
改めてAWS WAFを振り返る~業務で使うためのポイント~
masakiokuda
2
270
Claude Code に プロジェクト管理やらせたみた
unson
6
4.5k
敢えて生成AIを使わないマネジメント業務
kzkmaeda
2
460
OSSのSNSツール「Misskey」をさわってみよう(右下ワイプで私のOSCの20年を振り返ります) / 20250705-osc2025-do
akkiesoft
0
170
品質と速度の両立:生成AI時代の品質保証アプローチ
odasho
1
390
shake-upを科学する
rsakata
6
580
United™️ Airlines®️ Customer®️ USA Contact Numbers: Complete 2025 Support Guide
flyunitedguide
0
250
スタートアップに選択肢を 〜生成AIを活用したセカンダリー事業への挑戦〜
nstock
0
250
クラウド開発の舞台裏とSRE文化の醸成 / SRE NEXT 2025 Lunch Session
kazeburo
1
240
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Navigating Team Friction
lara
187
15k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
960
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
740
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Done Done
chrislema
184
16k
KATA
mclloyd
30
14k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
54k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Transcript
Introduction to Flask Sébastien Fievet Swisscom Digital Lab at EPFL
Prerequisites
$ python --version Python 2.7.12 https://www.python.org/downloads
$ pip --version pip 9.0.1 https://pip.pypa.io/en/stable/installing/
$ pip install virtualenv $ virtualenv --version 13.1.2 https://virtualenv.pypa.io/en/stable/installation/
$ git clone \ https://github.com/zyegfryed/intro_to_flask.git $ cd intro_to_flask $ virtualenv
.venv $ source .venv/bin/activate
Hello Flask!
–Deny “What… Why Flask?”
–http://flask.pocoo.org/ “Flask is a microframework for Python based on Werkzeug,
Jinja 2 and good intentions.”
Diving In https://github.com/zyegfryed/intro_to_flask/tree/01_intro
$ pip install Flask http://flask.pocoo.org/docs/0.12/installation/
# app.y from flask import Flask app = Flask(__name__) @app.route('/')
def hello_world(): return 'Hello, World!'
$ git checkout 01_intro $ export FLASK_APP=app.py $ flask run
$ curl http://127.0.0.1:5000/ Hello, World!
Chatbot
Diving In https://github.com/zyegfryed/intro_to_flask/tree/02_chatbot
$ pip install fbmessenger https://github.com/rehabstudio/fbmessenger
# app.py @app.route('/webhook', methods=['GET', 'POST']) def webhook(): if request.method ==
'GET': if request.args.get('hub.verify_token') == \ os.environ.get('FB_VERIFY_TOKEN'): return request.args.get('hub.challenge') raise ValueError('FB_VERIFY_TOKEN does not match.')
# app.py @app.route('/webhook', methods=['GET', 'POST']) def webhook(): […] elif request.method
== 'POST': messenger.handle(request.get_json(force=True)) return ''
# app.py from fbmessenger import BaseMessenger from fbmessenger import elements
class Messenger(BaseMessenger): def message(self, message): element = elements.Text('Received: {0}’.format( message['message']['text'])) self.send(element.to_dict()) […]
# app.py messenger = \ Messenger(os.environ.get(‘FB_PAGE_TOKEN’))
$ ngrok --version ngrok version 2.1.18 https://ngrok.com/download
Messenger https://developers.facebook.com/docs/messenger- platform/guides/setup
$ git checkout 02_chatbot $ export FB_VERIFY_TOKEN=… $ export FB_PAGE_TOKEN=…
$ flask run - - - - - - - - - — - - - - - - - - - - - - $ ngrok http 5000
Async
Diving In https://github.com/zyegfryed/intro_to_flask/tree/03_async
# app.py from redis import StrictRedis redis = StrictRedis() @job('default',
connection=redis) def messenger_handle(message): messenger.handle(message) @app.route('/webhook', methods=['GET', 'POST']) def webhook(): […] elif request.method == 'POST': messenger_handle.delay(request.get_json(force=True)) return ''
$ redis-server --version Redis server v=3.2.8 https://redis.io/download
$ pip install rq http://python-rq.org/
$ git checkout 03_async $ export FB_PAGE_TOKEN=… $ rqworker default
- - - - - - - - - — - - - - - - - - - - - - $ redis-server
Links • https://github.com/zyegfryed/intro_to_flask • https://www.python.org/downloads/ • https://pip.pypa.io/en/stable/installing/ • http://flask.pocoo.org/ •
http://flask.pocoo.org/docs/0.12/quickstart/ • https://developers.facebook.com/docs/messenger-platform/guides/setup • https://github.com/rehabstudio/fbmessenger • https://redis.io/download • http://python-rq.org/ • https://github.com/rehabstudio/fbmessenger