SlideShare a Scribd company logo
1 of 13
Download to read offline
A
Portion
Of
WSGI
With
Akilesh
What ? Why ? And How ?
• A specification for an interface between a web
server and web application
• Allows servers, frameworks, applications to
evolve independent of each other
• Allows easy intergration of middlewares into
existing applications and servers
• Outlines the Operations and Responses a server
expects from an application and vice versa
Components of a web service
Client
Internet Web Server
Middleware
Application
Application1
Application2
Webservers
● Pythonic
– Gunicorn
– Tornado
– Twisted
– Zope
● Non Pythonic
– Apache
– Just too many of them
Web Application
● Frameworks
– Allow quicker application development cycle
– Abstract all mundane jobs and allows user to concentrate on
logic/business
– Often use several tools like
● Templating engine – For generating page layout from datastructure
● PasteDeploy – For loading and chaining multiple web applications
● Routers – For routing a http request to a correct application
● Applications themselves may be chained to implement a
complex logic
● Some of the middleware may be third party applications
Examples
● Frameworks
– Django
– Flask
●
Theming
– Bootstrap
● Templating engine
– Jinja
– Mako
●
Middleware
– Ldap authentication using django
● Some of these may perform all other the above jobs. But the user
has the power to mix and match, thanks to wsgi.
Play by the rules
● Application has to be a callable. Anything with a
__call__ method with do. Methods, Classes,
Objects all are welcome.
● Application should handle any number of calls.
Server invokes application once for every http
request.
● Application returns and Iterable that yields
bytestrings.
● Server iterates over the Iterable and sends the
data without buffering.
More rules
● Application accepts two objects, name not a
contraint
– environ – A dictionary of request , os and wsgi params
– start_response – A callable that
● accepts two params
– Status – HTTP Status String object
– Headers -- HTTP Response headers List of tuples of header-value
– exec_info (optional) – typically the result of 'sys.exc_info()'
● And returns one
– Write – A callable that inturn accepts one argument
● Body – A bytestring to be sent to the client
– Write – Sends the bytestring to the client
– This is for legacy application only. New applications must not use this
interface
More rules
● Application must call start_response with appropriate
arguments before returning
● Server stores the Status and Headers, but will wait untill
Applications returns an Iterable and the Iterable has
yielded its first bytestring
● If Application sends an 'Content-Length' header to
start_response, Server should not send any more data
to than specified by the length
● If Application sends exec_info optional argument server
should erase the
Server receives request
Server extract request headers
And populates 'environ'
Server calls
Application(environ, start_response)
Application executes Logic
Application calls
start_respons(status, headers)
start_response
saves status and headers
Appliation returns
body
Server returns status,
headers and body
Server validates status,
headers and body
Middlewares
● Plays both server and application game
● Secretly slips between server, application and
other middlewares
● Absolutely Transparent
● Used to integrate apps built using different
frameworks, third party modules, routing, load
balancing, anything else you wish for
Getting Dirty
from wsgiref.simple_server import make_server
def my_application(environ, start_response):
response_headers = [('Content-Type', 'text/html'),
('Akilesh', 'Cool head')]
status_code = '200 OK'
writer = start_response(status_code, response_headers)
# ignore the writer
# it exists only for legacy applications
ret = {'request method': environ['REQUEST_METHOD'],
'path': environ['PATH_INFO'],
'query string': environ['QUERY_STRING']}
return str(ret)
httpd = make_server('localhost', 9090, my_application)
httpd.serve_forever()
Thank you
akilesh1597@gmail.com
Come back for more...

More Related Content

What's hot

What's hot (20)

Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongo
 
Hacking on OpenStack\'s Nova source code
Hacking on OpenStack\'s Nova source codeHacking on OpenStack\'s Nova source code
Hacking on OpenStack\'s Nova source code
 
Openstack study-nova-02
Openstack study-nova-02Openstack study-nova-02
Openstack study-nova-02
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Fast C++ Web Servers
Fast C++ Web ServersFast C++ Web Servers
Fast C++ Web Servers
 
Kubernetes 1.3 - Highlights
Kubernetes 1.3 - HighlightsKubernetes 1.3 - Highlights
Kubernetes 1.3 - Highlights
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebean
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Fighting Against Chaotically Separated Values with Embulk
Fighting Against Chaotically Separated Values with EmbulkFighting Against Chaotically Separated Values with Embulk
Fighting Against Chaotically Separated Values with Embulk
 
Fluentd at Bay Area Kubernetes Meetup
Fluentd at Bay Area Kubernetes MeetupFluentd at Bay Area Kubernetes Meetup
Fluentd at Bay Area Kubernetes Meetup
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
 
[212] large scale backend service develpment
[212] large scale backend service develpment[212] large scale backend service develpment
[212] large scale backend service develpment
 
Data Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby UsageData Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby Usage
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
how to use openstack api
how to use openstack apihow to use openstack api
how to use openstack api
 
Open Stack compute-service-nova
Open Stack compute-service-novaOpen Stack compute-service-nova
Open Stack compute-service-nova
 
Spring Security Patterns
Spring Security PatternsSpring Security Patterns
Spring Security Patterns
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 

Similar to Python WSGI introduction

Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
divzi1913
 

Similar to Python WSGI introduction (20)

Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet1.ppt
Servlet1.pptServlet1.ppt
Servlet1.ppt
 
Apache Arrow Flight Overview
Apache Arrow Flight OverviewApache Arrow Flight Overview
Apache Arrow Flight Overview
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
 
(ATS6-DEV09) Deep Dive into REST and SOAP Integration for Protocol Authors
(ATS6-DEV09) Deep Dive into REST and SOAP Integration for Protocol Authors(ATS6-DEV09) Deep Dive into REST and SOAP Integration for Protocol Authors
(ATS6-DEV09) Deep Dive into REST and SOAP Integration for Protocol Authors
 
servlets.ppt
servlets.pptservlets.ppt
servlets.ppt
 
servlets.ppt
servlets.pptservlets.ppt
servlets.ppt
 
servlets.ppt
servlets.pptservlets.ppt
servlets.ppt
 
servlets.ppt
servlets.pptservlets.ppt
servlets.ppt
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 
Web technology-guide
Web technology-guideWeb technology-guide
Web technology-guide
 
Servlet
ServletServlet
Servlet
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
High-speed Database Throughput Using Apache Arrow Flight SQL
High-speed Database Throughput Using Apache Arrow Flight SQLHigh-speed Database Throughput Using Apache Arrow Flight SQL
High-speed Database Throughput Using Apache Arrow Flight SQL
 
APITalkMeetupSharable
APITalkMeetupSharableAPITalkMeetupSharable
APITalkMeetupSharable
 

Recently uploaded

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 

Python WSGI introduction

  • 2. What ? Why ? And How ? • A specification for an interface between a web server and web application • Allows servers, frameworks, applications to evolve independent of each other • Allows easy intergration of middlewares into existing applications and servers • Outlines the Operations and Responses a server expects from an application and vice versa
  • 3. Components of a web service Client Internet Web Server Middleware Application Application1 Application2
  • 4. Webservers ● Pythonic – Gunicorn – Tornado – Twisted – Zope ● Non Pythonic – Apache – Just too many of them
  • 5. Web Application ● Frameworks – Allow quicker application development cycle – Abstract all mundane jobs and allows user to concentrate on logic/business – Often use several tools like ● Templating engine – For generating page layout from datastructure ● PasteDeploy – For loading and chaining multiple web applications ● Routers – For routing a http request to a correct application ● Applications themselves may be chained to implement a complex logic ● Some of the middleware may be third party applications
  • 6. Examples ● Frameworks – Django – Flask ● Theming – Bootstrap ● Templating engine – Jinja – Mako ● Middleware – Ldap authentication using django ● Some of these may perform all other the above jobs. But the user has the power to mix and match, thanks to wsgi.
  • 7. Play by the rules ● Application has to be a callable. Anything with a __call__ method with do. Methods, Classes, Objects all are welcome. ● Application should handle any number of calls. Server invokes application once for every http request. ● Application returns and Iterable that yields bytestrings. ● Server iterates over the Iterable and sends the data without buffering.
  • 8. More rules ● Application accepts two objects, name not a contraint – environ – A dictionary of request , os and wsgi params – start_response – A callable that ● accepts two params – Status – HTTP Status String object – Headers -- HTTP Response headers List of tuples of header-value – exec_info (optional) – typically the result of 'sys.exc_info()' ● And returns one – Write – A callable that inturn accepts one argument ● Body – A bytestring to be sent to the client – Write – Sends the bytestring to the client – This is for legacy application only. New applications must not use this interface
  • 9. More rules ● Application must call start_response with appropriate arguments before returning ● Server stores the Status and Headers, but will wait untill Applications returns an Iterable and the Iterable has yielded its first bytestring ● If Application sends an 'Content-Length' header to start_response, Server should not send any more data to than specified by the length ● If Application sends exec_info optional argument server should erase the
  • 10. Server receives request Server extract request headers And populates 'environ' Server calls Application(environ, start_response) Application executes Logic Application calls start_respons(status, headers) start_response saves status and headers Appliation returns body Server returns status, headers and body Server validates status, headers and body
  • 11. Middlewares ● Plays both server and application game ● Secretly slips between server, application and other middlewares ● Absolutely Transparent ● Used to integrate apps built using different frameworks, third party modules, routing, load balancing, anything else you wish for
  • 12. Getting Dirty from wsgiref.simple_server import make_server def my_application(environ, start_response): response_headers = [('Content-Type', 'text/html'), ('Akilesh', 'Cool head')] status_code = '200 OK' writer = start_response(status_code, response_headers) # ignore the writer # it exists only for legacy applications ret = {'request method': environ['REQUEST_METHOD'], 'path': environ['PATH_INFO'], 'query string': environ['QUERY_STRING']} return str(ret) httpd = make_server('localhost', 9090, my_application) httpd.serve_forever()