Personal computing discussed

Moderators: SecretSquirrel, just brew it!

Crayon Shin Chan
Silver subscriber
Minister of Gerbil Affairs
Topic Author
Posts: 2305
Joined: Fri Sep 06, 2002 11:14 am
Location: Malaysia

Have to write a Python web service - any frameworks?

Tue Jan 27, 2015 2:23 pm

I'm trying to write a program in Python that helps abstract payment providers away, depending on the persons' location/mobile service provider. So far I've come up with the following workflow:

1. take some HTTP POST/GET data from the end user (I think POST is best)
2. check the IP, decide which payment provider to use, perhaps looking something up in a MySQL table here
3. Formulate a HTTP GET/POST request to the chosen payment provider's server (more database lookups here)
4. Send the request, parse the response from the payment provider's system, record the whole transaction in a database
5. tell the user everything is ok

But I'm not really sure how. Python has threaded HTTP server classes - maybe I can subclass them, and customize them to do what I want them to do. That was what I was thinking. But then I read about Python WSGI and Is this what a web framework is supposed to simplify? If so then I can modify Django or something to suit my purposes, right? In the end there has to be a sort of CMS where one can manage all aspects of this process, but it's only an addition, the important part is the part that decides which payment provider to use. There's no need to generate many HTML pages for the end user. And how does WSGI fit into all this?
Mothership: FX-8350, 12GB DDR3, M5A99X EVO, MSI GTX 1070 Sea Hawk, Crucial MX500 500GB
Supply ship: Sargas@2.8GHz, 12GB DDR3, M4A88TD-V EVO/USB3
Corsair: Thinkpad X230
Gold subscriber
Gerbil Jedi
Posts: 1878
Joined: Wed Jan 23, 2008 9:18 pm
Location: Probably where I don't belong.

Re: Have to write a Python web service - any frameworks?

Tue Jan 27, 2015 2:29 pm

Pylons comes to mind almost immediately, although it and some of the other frameworks may be more complex than what you really need.

A full-bore CMS that builds on Pylons is called Plone:

Django is another one: (ah, I see you've already spotted Django)

Another network engine that is actually a little lower-level than either of those two is Twisted:
Twisted can do a bunch of networking stuff, including web services.

As for "WSGI", while I don't do a bunch of web service development, it appears to be a common communication format that Python uses to let multiple web services talk to each other. As such, it is not so much a finished product that you use, but an API/protocol that you use to be compatible with existing projects that are also WSGI compatible.
4770K @ 4.7 GHz; 32GB DDR3-2133; GTX-1080 sold and back to hipster IGP!; 512GB 840 Pro (2x); Fractal Define XL-R2; NZXT Kraken-X60
--Many thanks to the TR Forum for advice in getting it built.
Graphmaster Gerbil
Posts: 1324
Joined: Mon Sep 13, 2004 8:33 pm

Re: Have to write a Python web service - any frameworks?

Tue Jan 27, 2015 2:52 pm

WSGI is how a webserver can communicate with a Python web application. WSGI is a better cgi, basically.

You'll probably want to configure Apache, Nginx, or whatever to run in front of the Python application in production.

Webserver --(WSGI spec)--> Python Application

1) POST is good here since this part will deal with enduser data.
2) There are GeoIP modules that will map an IP to geographic location that can be used.
3) urllib
4) SQLAlchemy will simplify dealing with a database.
5) The framework will deal with this.

Flask is another python framework to look at. It's more of a toolkit then a full-fledged framework like Django, but it's pretty neat.

Flask homepage

Flask Mega Tutorial ... ello-world

Who is online

Users browsing this forum: No registered users and 1 guest