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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Sébastien Fievet
February 23, 2017
Technology
66
0
Share
Introduction to Flask
Workshop given for a Swisscom Digital Lab meetup at EPFL
Sébastien Fievet
February 23, 2017
More Decks by Sébastien Fievet
See All by Sébastien Fievet
Django Round-Up – Meetup Django CH #28
zyegfryed
0
64
Django Round-Up – Meetup Django CH #25
zyegfryed
0
57
Django Round-Up – Meetup Django CH #23
zyegfryed
0
54
Django Round-Up – Meetup Django CH #21
zyegfryed
0
72
Django Round-Up – Meetup Django CH #20
zyegfryed
0
77
Django Round-Up – Meetup Django CH #19
zyegfryed
2
89
[Django] URL prefix with runserver
zyegfryed
0
1.5k
[Django] Generating PDF with PDFForm
zyegfryed
0
92
[Django] RESTful API
zyegfryed
1
230
Other Decks in Technology
See All in Technology
AI-DLCを活用した高品質・安全なAI駆動開発実践 / AI Driven Development
yoshidashingo
1
300
ITエンジニアを取り巻く環境とキャリアパス / A career path for Japanese IT engineers
takatama
4
1.8k
最低限これだけ押さえれ大丈夫_Claude Enterprise/Team企業展開ガバナンス入門
tkikuchi
1
650
Gradle×GitHub_ActionsでCI時間を約50%短縮 ジョブ分割の設計と落とし穴 / Cutting CI Time by ~50% with Gradle and GitHub Actions: Job-Splitting Design and Pitfalls
takatty
0
590
AI Adaptable なテストを整える工夫 / Ways to Make Your Tests AI-Adaptable
bitkey
PRO
2
200
Diagnosing performance problems without the guesswork
elenatanasoiu
0
150
オンコールの負荷軽減のためのBits Assistant 活用方法 / How to Use Bits Assistant to Reduce the Workload on On-Call Staff
sms_tech
1
370
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
3
630
Java正規表現エンジン(NFA)の仕組みと パフォーマンスを維持するための最適化手法
takeuchi_132917
0
170
形式手法特論:公平性制約の位相的特徴づけ #kernelvm / Kernel VM Study Kansai 12th
ytaka23
1
670
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
2
1.1k
AI時代の私の技術インプットとアウトプット術
tonkotsuboy_com
16
8.2k
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
220
WENDY [Excerpt]
tessaabrams
11
38k
YesSQL, Process and Tooling at Scale
rocio
174
15k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
430
Prompt Engineering for Job Search
mfonobong
0
330
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
The Cost Of JavaScript in 2023
addyosmani
55
10k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
Utilizing Notion as your number one productivity tool
mfonobong
4
310
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
130
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
44k
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