473,761 Members | 5,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python, WSGI, legacy web application

Howdy all,

I'm working on a web application that is starting to gain a lot of
back-end code written in Python. However, all the current interface
code is written in legacy PHP. I'd like to slowly introduce new
features as Python WSGI programs.

Is it possible to write a Python WSGI program that talks to a PHP
program as its "back end"? Where can I find out how to do this,
preferably with examples?

The ideal here is to keep all the existing code as is, but write
little or no new PHP code. Instead, iteratively change the interface,
replacing pieces of the monolithic legacy PHP interface with modular
WSGI programs over time.

--
\ "I don't know anything about music. In my line you don't have |
`\ to." -- Elvis Aaron Presley (1935-1977) |
_o__) |
Ben Finney

Nov 22 '06 #1
7 1821

Ben Finney wrote:
Howdy all,

I'm working on a web application that is starting to gain a lot of
back-end code written in Python. However, all the current interface
code is written in legacy PHP. I'd like to slowly introduce new
features as Python WSGI programs.

Is it possible to write a Python WSGI program that talks to a PHP
program as its "back end"? Where can I find out how to do this,
preferably with examples?

The ideal here is to keep all the existing code as is, but write
little or no new PHP code. Instead, iteratively change the interface,
replacing pieces of the monolithic legacy PHP interface with modular
WSGI programs over time.
Look at mod_python for Apache. If you use it correctly you can on a
page by page basis as need be, replace the existing PHP pages with
equivalents written using Python. You could do this by programming
right at the level of mod_python, or again, if done right by using WSGI
on top of mod_python. If you need to maintain compatibility of URLs,
you could even do things so that even though URLs use .php, that it
maps to Python code underneath, thus easing any transition.

If you are interested in this path, the mod_python mailing list may be
a good place to go to discuss the mod_python aspects of this. The
mod_python mailing list details are on the mod_python web site at
www.modpython.org.
Graham

Nov 23 '06 #2
Ben Finney wrote:

Is it possible to write a Python WSGI program that talks to a PHP
program as its "back end"? Where can I find out how to do this,
preferably with examples?
Perhaps:

http://pythonpaste.org/wphp/
http://blog.ianbicking.org/2006-wphp.html

Nov 23 '06 #3
"ToddG" <td*****@gmail. comwrites:
Ben Finney wrote:
Is it possible to write a Python WSGI program that talks to a
PHP program as its "back end"? Where can I find out how to do
this, preferably with examples?

Perhaps:

http://pythonpaste.org/wphp/
http://blog.ianbicking.org/2006-wphp.html
Looks good. Can anyone here tell any stories about using this for its
stated purpose?

Where would be the best place to ask further questions on this?

--
\ "Two paradoxes are better than one; they may even suggest a |
`\ solution." -- Edward Teller |
_o__) |
Ben Finney

Nov 23 '06 #4
"Graham Dumpleton" <gr*****@dscpl. com.auwrites:
Look at mod_python for Apache. If you use it correctly you can on a
page by page basis as need be, replace the existing PHP pages with
equivalents written using Python. You could do this by programming
right at the level of mod_python, or again, if done right by using
WSGI on top of mod_python. If you need to maintain compatibility of
URLs, you could even do things so that even though URLs use .php,
that it maps to Python code underneath, thus easing any transition.
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?

--
\ "Compulsory unification of opinion achieves only the unanimity |
`\ of the graveyard." -- Justice Roberts in 319 U.S. 624 (1943) |
_o__) |
Ben Finney

Nov 23 '06 #5
Ben Finney wrote:
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?
You can use FastCGI or SCGI too, with Apache, lighttpd or Cherokee. I
have a short description of different ways to run a WSGI app here:

http://pydap.org/docs/server.html

Though it's focused on a specific WSGI app I wrote it uses Paste
Deploy, so you can generalize it easily.

--Rob

Nov 23 '06 #6
Rob De Almeida wrote:
Ben Finney wrote:
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?

You can use FastCGI or SCGI too, with Apache, lighttpd or Cherokee.
I think the motivation behind suggesting an Apache solution was that
you'd be able to migrate the PHP resources you already have running in
Apache (I assume, since PHP can run in other places these days) to
mod_python whilst staying within the Apache environment, rather than
having to maintain a number of different environments at the same time.
In other words, you'd write your replacement resources using WSGI (or
whatever) on mod_python (for performance), CGI (for relative
simplicity), or some other connection technology, and then it'd just be
a matter of changing the various directives and having Apache figure it
out.

I know some people advocate proxying to a variety of backend servers,
and the Web obviously lends itself to flexible architectures in this
respect, but there are fairly good reasons for keeping the component
count low.

Paul

Nov 23 '06 #7
Paul Boddie wrote:
Rob De Almeida wrote:
Ben Finney wrote:
I was under the impression that WSGI in mod_python was a rather kludgy
way to do WSGI, but I don't know what the alternatives are. CGI?
Python http server (e.g. CherryPy)? Something else?
You can use FastCGI or SCGI too, with Apache, lighttpd or Cherokee.

I think the motivation behind suggesting an Apache solution was that
you'd be able to migrate the PHP resources you already have running in
Apache (I assume, since PHP can run in other places these days) to
mod_python whilst staying within the Apache environment, rather than
having to maintain a number of different environments at the same time.
In other words, you'd write your replacement resources using WSGI (or
whatever) on mod_python (for performance), CGI (for relative
simplicity), or some other connection technology, and then it'd just be
a matter of changing the various directives and having Apache figure it
out.
Correct.

As example, imagine you have written a mod_python handler which itself
interprets how to map a URL to something to implement the URL. This
might map to a WSGI application or to some system of basic mod_python
handlers.

Within the .htaccess file of the directory where all your PHP files
live you could then write:

PythonHandler myphppagereplac ementhandler | .php

At this point nothing will happen, but then one could do the following:

<Files index.php>
SetHandler mod_python
</Files>

For the one page called 'index.php' the mod_python handler would be
called instead of PHP. As a Python equivalent for each PHP page is
written, just need to trigger the mod_python handler to be used by
using the Files directive.

One could also have different handlers for each page and use Apache to
make the selection if wanted to:

<Files index.php>
SetHandler mod_python
PythonHandler myphppagereplac ementshandler:: index
</Files>

Now I am sure that some will say it looks messy, but as far as trying
to do a progressive replacement of pages and maintain URLs, it is
probably the quickest way. It should be said that any progressive
migration like this is likely to be a bit messy.

Don't like this, then another way using Apache might be to use
mod_rewrite to remap URLs to new URLs which use Python code. Using
mod_rewrite can be a pain though. Yet another way may be to use
mod_proxy to selectively forward URLs through to a separate back end
web server if you are Apache phobic and want to use a web server
written in pure Python.

Overall, Apache/mod_python has a lot to offer, but from what I have
seen most Python web frameworks simply uses it as a jumping off point
and not much else.

Graham

Nov 23 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2536
by: Phillip J. Eby | last post by:
PEP: 333 Title: Python Web Server Gateway Interface v1.0 Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/08/27 17:30:09 $ Author: Phillip J. Eby <pje at telecommunity.com> Discussions-To: Python Web-SIG <web-sig at python.org> Status: Draft Type: Informational Content-Type: text/x-rst Created: 07-Dec-2003
2
2287
by: matt | last post by:
Hi all- I'm trying to port an ajax spell-checker (http://www.broken-notebook.com/spell_checker/index.php) to use with the moin moin wiki and have been somewhat successful. (By successful I mean I can spell check using the php backend and my python port running as cgi-bin). My question is this: moinmoin runs on many python web backends (cgi-bin/mod-python/twisted/standalone). My spell-checker backend runs
122
7417
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection outside of that class. This structured way allows visual tools to host components, and allows programmers to build applications and libraries visually in a RAD environment. The Java language has JavaBeans as its component model which allows Java...
7
2915
by: Echo | last post by:
I am going to start working on a church website. And since I like python, I decided to use WSGI. However, I later found out about all the different CMS's in php. So I wondered if there where any in python. Sadly, I only found Plone, skeletonz, and PyLucid (If there is any more, please let me know). Of those three, only PyLucid supports WSGI and it didn't look very nice to me. Both Plone and skeletonz looked very nice. However, they...
5
1644
by: Adam Atlas | last post by:
Does anyone know if it would be possible to create a CPython extension -- or use the ctypes module -- to access Python's own embedding API (http://docs.python.org/api/initialization.html &c.)? Could a Python program itself create a sub-interpreter, and work with it with all the privileges and capabilities that an actual C program would have? I realize that this may be a bit too... mystical? ... for a lot of people's tastes, but I'm just...
37
2580
by: Michele Simionato | last post by:
At work we are shopping for a Web framework, so I have been looking at the available options on the current market. In particular I have looked at Paste and Pylons and I have written my impressions here: http://www.phyast.pitt.edu/~micheles/python/yet-another-comparison-of-web-frameworks.html I do not speak too well of Pylons, so if you thing I am wrong feel free to correct me here ;)
5
1641
by: walterbyrd | last post by:
I don't know much php either, but running a php app seems straight forward enough. Python seems to always use some sort of development environment vs production environment scheme. For development, you are supposed to run a local browser and load 127.0.0.1:5000 - or something like that. Then to run the same thing in a development environment, I have to configure some files, or touch all the files, restart the web-server, or something....
8
1584
by: jmDesktop | last post by:
I have been to the main python site, but am still confused. I have been using .net, so it may be obvious how to do this to everyone else. I am aware there are various frameworks (Django, Pylons, etc.), but I would like to know how to create web pages without these. If I have mod_python or fastcgi on apache, where do I start? I don't have clue where to begin to create a web page from scratch in python. I am sure I will want to access...
2
1141
by: Michael Palmer | last post by:
On Sep 5, 9:56 pm, Sean Davis <seand...@gmail.comwrote: xmlrpc is the right idea, as it interfaces easily across languages.
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.