SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
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...

Contenu connexe

Tendances

Tendances (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
 

Similaire à Python WSGI introduction

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

Similaire à 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
 

Dernier

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+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
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+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 Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Dernier (20)

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%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
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+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...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+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...
 
%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
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%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
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%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
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
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?
 

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()