Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Two approaches to python web services by Matth...

Pycon ZA
October 12, 2018

Two approaches to python web services by Matthew French & Kenneth Goldswain

We discuss two different approaches to building web services using Python. The first and more traditional approach uses Flask to build a web service, while the second approach builds a web service using only native Python 2.7 libraries without dependencies on any additional software.

The talk starts by discussing web services in general before moving onto the different environments our services run in, and what they will be used for. We will briefly cover the code used, but the focus will be on the reason why we need two different approaches and we will compare the risks and benefits of using these two contrasting methods.

We hope the talk will inspire people to experiment even further with web services, or at least give them insight into new ways they could use web services.

Pycon ZA

October 12, 2018
Tweet

More Decks by Pycon ZA

Other Decks in Programming

Transcript

  1. Who are FIS? 2 • FIS is a global leader

    in financial services technology and is 50 years old this week. • Covers the breadth of financial services industry: retail and institutional banking, payments, asset and wealth management, risk and compliance, consulting and outsourcing solutions • FIS serves more than 20,000 clients in over 130 countries • Employs more than 53,000 people worldwide • FIS is a Fortune 500 company and is a member of Standard & Poor’s 500® Index • One of the products offered by FIS is Front Arena, a comprehensive trading platform that offers electronic trading and position management across all asset classes • Python, together with Front Arena, allows FIS to offer flexible and customizable solutions to clients around the world For more information about FIS, visit http://www.fisglobal.com
  2. What are Web Services 3 • Web services are services

    on the web! • In the beginning we had RPC, …and 640Kb of memory, 10Mb hard drives and 2400 baud modems • Later CORBA and RMI… • With the rise of the Internet, the Simple Object Access Protocol (SOAP) gained popularity – But simple it is not… • Representational State Transfer (REST) is the latest favourite. – Typically JSON over HTTP Web services are web pages for computers Postel’s principal: Be conservative in what you do, be liberal in what you accept from others.
  3. Problem Statement 5 • Client needed to integrate data from

    one of their native systems with Front Arena via a web service that they had created • We did not have access to this web service during development and we needed to present a demo of some sort • The requirement was to create a dummy web service, which would mimic some information that would be coming out of the client’s web service • We needed to use a framework or solution that was quick to code and simple to learn • So we used Flask
  4. Getting Started: A Simple Web Service 6 • Flask is

    a python micro-framework with enough functionality to fit our requirements without being extraordinarily difficult to learn. http://flask.pocoo.org/ • It is very easy to setup: • You are now able to import Flask as a library in Python and use it.
  5. 7

  6. Open Source in Large Organizations 9 • While it is

    getting better, many organisations are still hostile to open source: – Big business – Government – Even non-profits and non-governmental organisations • Open source is often confused with shareware • Infrastructure is controlled by Mordac: the preventer of information services (© Scott Adams) – Lowest common denominator security strategies, and yet many internal tools still require IE6 – Windows only, with McAfee sauce – Limited or no admin rights on the desktop – Even less likely to have access to servers – Internet access via restricted poxy servers. SourceForge is a special favourite for the ban hammer. pip install Flask… you are joking, right?!?
  7. Problem Statement 10 • Need to have a reliable service

    to log specific events • Information to be logged represents a low security risk • Service needs to respond quickly, but volume will be low • Service needs to be installed on a server we don’t have access to • Server doesn’t have java, .Net, IIS or Apache installed or configured • Server does have Python 2.7 installed • Clients are Python based
  8. Building a Web Service from Scratch 11 • Step 1:

    Don’t!!! Find someone who has done it before. • Thank you, Tal Liron: https://gist.github.com/tliron/8e9757180506f25e46d9 • Script uses default Python 2.7 libraries • Entry point:
  9. Disadvantages Flask • External library installation • Black Box: Debugging

    issues can be tricky – Obscure problems could be a nightmare RAW Python • Limited functionality out the box • Not easy to read, lots of glue code • You need to know what you are doing • Security is a concern • Not very scalable 16
  10. Advantages Flask • Full featured web services • Plenty of

    documentation – Easy to learn – Pythonic • Simple and extendable Raw Python • Lightweight • No dependencies • Security is easier to control • Flexible 17
  11. Conclusion… 18 • Creating RESTful web services in Python is

    easy (even when the client makes it hard) • When creating web services, Python has many options • We have demonstrated two of the simpler choices • Get started today!