Slide 1

Slide 1 text

Masashi Shibata / 2016.04.30 / #kosenconf C-BATA PRESENTS Python੡8FCϑϨʔϜϫʔΫͷݪཧͱ࣮૷

Slide 2

Slide 2 text

Masashi Shibata @c_bata_ WEB ENGINEER ໌ੴߴઐ / Pythonista

Slide 3

Slide 3 text

Handling Request from Clients kobin WEB SERVER WEB APPLICATION REQUEST RESPONSE

Slide 4

Slide 4 text

Handling Request from Clients kobin WEB SERVER WEB APPLICATION REQUEST RESPONSE

Slide 5

Slide 5 text

WSGI ʲ Web Server Gateway Interfaceʳ <֓ཁ> PythonͰ࡞ΔWebΞϓϦέʔγϣϯͷ
 ࣮૷ํ๏ͷඪ४Խ࢓༷ PEP3333

Slide 6

Slide 6 text

࢓༷ ᶃ ͭͷҾ਺Λ࣋ͬͨݺͼग़͠ՄೳͳΦϒδΣΫτ ᶄ ୈҾ਺ͱͯ͠౉͞ΕͨΦϒδΣΫτΛݺͼग़͠
 )551εςʔλείʔυͱϔομ৘ใΛ౉͢ ᶅ ϨεϙϯεϘσΟͱͯ͠όΠτจࣈྻΛZJFME͢Δ
 JUFSBCMFΛฦ͢ IUUQTXXXQZUIPOPSHEFWQFQTQFQ

Slide 7

Slide 7 text

def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] Hello World
 with just 3 lines of Python

Slide 8

Slide 8 text

def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] ͭͷҾ਺Λ࣋ͬͨ
 ݺͼग़͠ՄೳͳΦϒδΣΫτ

Slide 9

Slide 9 text

def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] εςʔλε ϔομ৘ใ ୈҾ਺

Slide 10

Slide 10 text

def app(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b"Hello World"] ϨεϙϯεϘσΟ όΠτྻ

Slide 11

Slide 11 text

$ gunicorn -w 1 filename:app [2016-04-15 10:17:00 +0900] [1873] [INFO] Starting gunicorn 19.4.5 [2016-04-15 10:17:00 +0900] [1873] [INFO] Listening at: http://127.0.0.1:8000 (1873) [2016-04-15 10:17:00 +0900] [1873] [INFO] Using worker: sync [2016-04-15 10:17:00 +0900] [1878] [INFO] Booting worker with pid: 1878 WSGI SERVER Enable the use of any framework with any server.

Slide 12

Slide 12 text

ͲΜͳػೳ͕ඞཁʁ

Slide 13

Slide 13 text

Function 1 ROUTING ϧʔςΟϯά ࠓ͸Ͳ͜ʹΞΫηεͯ͠΋l)FMMP8PSMEz

Slide 14

Slide 14 text

Function 2 HTML TEMPLATE HTMLςϯϓϨʔτ ࠓ͸ϓϨʔϯςΩετฦͯ͠Δ͚ͩ

Slide 15

Slide 15 text

Function 3 STATIC FILES ੩తϑΝΠϧ ຊ൪Ͱ͸/HJOYͱ͔࢖ͬͯฦ͚͢Ͳɺ։ൃத͸ʜ $44 +4 ը૾Λ͍͍ײ͡ʹฦͯ͠ཉ͍͠

Slide 16

Slide 16 text

Function 4 REQUEST OBJECT ϦΫΤετΦϒδΣΫτ ࠓ͸ͨͩͷࣙॻܕΦϒδΣΫτ͕౉͞ΕͯΔ͚ͩ ͍͍ײ͡ʹϥοϓͯ͘͠ΕΔΦϒδΣΫτ͕΄͍͠

Slide 17

Slide 17 text

Function 5 RESPONSE OBJECT ϨεϙϯεΦϒδΣΫτ εςʔλεͱ͔ϔομ৘ใͱ͔Λ͍͍ײ͡ʹίϯτϩʔϧ

Slide 18

Slide 18 text

a small and statically-typed web framework kobin https://github.com/c-bata/kobin

Slide 19

Slide 19 text

from kobin import Kobin app = Kobin() @app.route(‘^/$') def hello(): return "Hello World!!" if __name__ == '__main__': app.run()

Slide 20

Slide 20 text

IUUQHJUIVCDPNDCBUBLPCJOFYBNQMF DEMO TODOΞϓϦ [ Kobin + Angular2 ]

Slide 21

Slide 21 text

Kobin is readable (maybe). 84(*ͱ͔1ZUIPOͷจ๏౳ͷཧղ͸ඞཁ ࠓͷͱ͜Ζߦ͙Β͍ 5ZQF)JOUJOH 3PVUJOHͷลΓ͔ΒಡΉͷ͕͍͍͔΋ ! ! ! !

Slide 22

Slide 22 text

3FGFSFODFT • Documentations • https://kobin.readthedocs.org/ja/latest/ • https://kobin.readthedocs.org/en/latest/ • Kobin Example • https://github.com/c-bata/kobin-example • https://kobin.herokuapp.com/

Slide 23

Slide 23 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ THANK YOU