#1
  1. cosmos curator
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2002
    Location
    Leeds, UK
    Posts
    678
    Rep Power
    14

    Question Is python what I need?


    Hi all

    After posting a recent question, I've decided to start looking into python. Strangely, the answers I recieved in that post have enabled me, in part, to formulate a solution to a problem at work yesterday. However, being new to python, I'd to know from the community whether python is what I need to develop my solution in.

    Here's the problem...

    I have an application which needs to connect over the web to a resource. However, the resource tied to its location and is stuck in the dark-ages, so requires some kind of "middleware" to access it. I've a contact who is going to slap some DOS stuff together and hopefully provide some sort of API (which I'll design) to do what I need to.

    Now, I need to create something which will sit on the resource's server, wait for requests, use this API to get/set information, and return some sort of response.

    And now the questions...

    From what I gathered from my previous post, Python can be "compiled" in some way to run on a windows box, and can run as a service (on NT). Which is just what I need. However, what I also need my interface to do is to act kind of like a web server. I don't want to have some other web server running, because this is another layer waiting for problems.

    So, can python act as a web server?

    Being an interface, I need to "hook in" to the DOS API-thing what my contact is going to develop.

    Can python do this?

    I then need to send something back to my webapp. I understand that python has libraries which can handle XML/XSL and the like.

    Is there a standard one so that python can act as a XMLRPC/SOAP server? Is this the best protocol to use?

    And finally, is python the best road to go down? Am I missing some better way to solve my issue?

    Thanks for any help you can provide.
    R.T.F.M - Its the only way to fly...

    "No matter what you do, or how good it is, someone will always ask for more features. Or to change the colour of something, then change their minds."

    Personal:
    experience// 8 Years Web Development
    technologies// Standards-compliant, valid, & accessible (x)HTML/CSS, XML/XSL/XPath/XQuery/XUpdate, (OOP) PHP/(My)SQL, eXist/Xindice/XMLDBs
    packages// Photoshop, Illustrator, Flash/Fireworks/Director
    environment// FC2, MySQL, Lighttpd, PHP5, Mojavi/Agavi
    site// //refactored.net/ (Coming soon...)
    quote// Programming is the eternal competition between programmers who try to make apps more and more idiot proof and the universe that makes dumber idiots. So far, the universe is winning...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    Python can make servers i think so atleast with the socket module.
    But i am not sure about the other stuff either. So just take it what bad can happen.
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Yes, you would use the socket module. Of course. But the httplib module which is on the Python main site can be used for sending/receiving data over the internet. Python can be used as a web server if you know what you're doing and it can sit and wait for replies from a server as long as it has to. Even though Python can handle XML & XSL I do not know if it can handle SOAP or if it even has a module for that. If you really wanted to use SOAP you could probably come up with your own module or code to work with it properly. I'm not really sure if Python would be the very best choice to make, there's most likely another solution for your problem. Maybe you could use Visual Studio .NET? But anyways, if you do decide to use Python, it is capable of handling the jobs of being a webserver.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    89
    Rep Power
    13
    python can do everything you want. I don't see any problems.
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Not necessarily, Python cannot do everything thing. As far as I know there are no public modules that are specifically designed for XMLRPC or SOAP. I'm sure it can handle a job as such, even as a webserver, but he may have to do that part manually.
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    There are several different implementations of SOAP for Python. There is an a XML-RPC library that comes with your Python installation. I'll reiterate: Python can do everything you want it to do and more .

    Note: you should pick up a the fix from python.org if you intent to use XML-RPC.

    http://pywebsvcs.sourceforge.net/

    I'm sure there's a lot more on this subject, try google and you should find everything you need; including articles like this one:

    http://www-106.ibm.com/developerworks/library/ws-pyth8.html

    Mark.
    programming language development: www.netytan.com Hula

  12. #7
  13. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    This is completely off-topic, but netytan, you should respond one more, you'll have your 2000th post. 8>
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    Originally Posted by neobuddah
    Hi all
    Hi

    I've decided to start looking into python. Strangely, the answers I recieved in that post have enabled me, in part, to formulate a solution to a problem at work yesterday.
    Good good.

    However, being new to python, I'd to know from the community whether python is what I need to develop my solution in.
    Whoa, Python isn't what you 'need', it's just "one possible way". However, it might well be one of the nicer ways

    I have an application which needs to connect over the web to a resource. However, the resource tied to its location and is stuck in the dark-ages, so requires some kind of "middleware" to access it. I've a contact who is going to slap some DOS stuff together and hopefully provide some sort of API (which I'll design) to do what I need to.
    ... DOS stuff?

    From what I gathered from my previous post, Python can be "compiled" in some way to run on a windows box
    Install Python on the Windows PC, copy the script over.

    , and can run as a service (on NT).
    Yes.

    Which is just what I need. However, what I also need my interface to do is to act kind of like a web server.
    http://docs.python.org/modindex.html

    SimpleXMLRPCServer - you'll have a server in a dozen lines of code, and a client in half a dozen.
    SimpleHTTPServer
    www.twistedmatrix.com - Twisted Matrix (just about the opposite of a simple server )

    [/quote]So, can python act as a web server?[/quote]
    You can write web servers in Python, or use existing ones. But just to be pedantic, it's a programming language - it can no more 'act as a web server' than wood pulp can act as a newspaper.

    Being an interface, I need to "hook in" to the DOS API-thing what my contact is going to develop.

    Can python do this?
    What on earth is a DOS API-thing?
    No matter, if it's a set of executable programs you call, Python can call them with one of:
    os.popen
    os.spawn
    os.exec
    something_new_to_2.4_which_makes_these_easier_but_I_forget_what_it's_called

    If it's a Windows DLL, you could use the ctypes module.
    If it's a web-interface, you could go with urllib2.
    If it's an XML-RPC server, then that would work as well.
    If it writes to a file periodically, then you could use a timer to check for file updates periodically.

    I then need to send something back to my webapp. I understand that python has libraries which can handle XML/XSL and the like.
    Yes, but I couldn't tell you much more, sorry.

    Is there a standard one so that python can act as a XMLRPC/SOAP server? Is this the best protocol to use?
    SimpleXMLRPCServer.
    Maybe - it depends what you're doing, really.

    And finally, is python the best road to go down? Am I missing some better way to solve my issue?
    Yes - ask your contact to build the API so your application can connect to it. Cut out the middleman. Fewer layers, less code, someone else doing the bulk of the work, it's all good.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Colorado, USA
    Posts
    68
    Rep Power
    11
    If you want to simplify some of this stuff, take a look at CherryPy.
    Although it is, and can be used as a stand alone web server,
    I found it much easier to use than writing your own socket server.
    Writing your own socket server is probably still important, to understand the nuts and bolts of using Python in this way.

    CherryPy gave me a nice way to have a lite, CGI capable server that could accept requests, do some python action,and return some data.

    http://www.cherrypy.org

    Oh, and FYI, I have found the built in XML modules in python to be incredibly robust. You will be able to do whatever you need in Python.
  18. #10
  19. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by sfb
    ...What on earth is a DOS API-thing?
    No matter, if it's a set of executable programs you call, Python can call them with one of:
    os.popen
    os.spawn
    os.exec
    something_new_to_2.4_which_makes_these_easier_but_I_forget_what_it's_called

    ...
    Think your talking about the subprocess module . This is by far the easiest/best way to work with processes in Python especially if you use the call() function (usually for simple things).

    have fun all,

    Mark.
    programming language development: www.netytan.com Hula

  20. #11
  21. cosmos curator
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2002
    Location
    Leeds, UK
    Posts
    678
    Rep Power
    14
    Thanks for all your replies guys.

    ... DOS stuff?
    I know. The app I'll be connecting to is a very old yet widely available app, which uses a proprietary filesystem. And its all DOS-based. Really, the only way to get into it is to use some DOS code my contact has already developed. They're going to alter this to allow me to make simple requests and get structured responses, so I can use it as an interface for my "server" layer. This is all going to be hosted on the client's machine. The app I've developed will sit on a webserver somewhere, and talk via HTTP to my "server" layer. Its not nice, but its the only way to do things without completely altering the way the client does business.

    What on earth is a DOS API-thing?
    I've no idea. Still, makes sense to me, my client, and the fella building the DOS thingummy.

    Install Python on the Windows PC...
    Ah. This might be seen as something terrible for my client(s). They'd much prefer to recieve a simple installer where they answer a few questions, maybe browse to a file, click "install", and they're done. Anything more complicated than that, and they'll not be too happy. From what I understand though, Python scripts can be "packedged" with the interpreter into an exe file, so thats good enough.

    Maybe you could use Visual Studio .NET?
    Yes, maybe for this version. But the "server" layer might need to be ported to mac/linux/unix in future versions, so if I can use something open-source and cross-platform, all the better.

    Thanks for your help guys!
    R.T.F.M - Its the only way to fly...

    "No matter what you do, or how good it is, someone will always ask for more features. Or to change the colour of something, then change their minds."

    Personal:
    experience// 8 Years Web Development
    technologies// Standards-compliant, valid, & accessible (x)HTML/CSS, XML/XSL/XPath/XQuery/XUpdate, (OOP) PHP/(My)SQL, eXist/Xindice/XMLDBs
    packages// Photoshop, Illustrator, Flash/Fireworks/Director
    environment// FC2, MySQL, Lighttpd, PHP5, Mojavi/Agavi
    site// //refactored.net/ (Coming soon...)
    quote// Programming is the eternal competition between programmers who try to make apps more and more idiot proof and the universe that makes dumber idiots. So far, the universe is winning...
  22. #12
  23. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Actually most .NET applications can run under *nix & Mac OS X via the Mono project (www.go-mono.com).

    Anyway, you can use py2exe/py2app to create a stand a long application from your program however as you know the interpreter is included with this .

    http://starship.python.net/crew/theller/py2exe/
    http://undefined.org/python/py2app.html

    That said you can always create an installer to handle any hard work for you using a program like INNO. Installing Python isn't really hard to do though; I'd expect your clients biggest problem to be the size unless you're planning to include the program on a CD .

    http://www.jrsoftware.org/isinfo.php

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  24. #13
  25. cosmos curator
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2002
    Location
    Leeds, UK
    Posts
    678
    Rep Power
    14
    Yea, forgot about Mono... Still, Python seems to make sense to me. Its open-source, free, cross-platform, and from what I've read is the natural progression from PHP if you don't fancy the Perl route.

    Thanks guys.

    Comments on this post

    • netytan agrees
    R.T.F.M - Its the only way to fly...

    "No matter what you do, or how good it is, someone will always ask for more features. Or to change the colour of something, then change their minds."

    Personal:
    experience// 8 Years Web Development
    technologies// Standards-compliant, valid, & accessible (x)HTML/CSS, XML/XSL/XPath/XQuery/XUpdate, (OOP) PHP/(My)SQL, eXist/Xindice/XMLDBs
    packages// Photoshop, Illustrator, Flash/Fireworks/Director
    environment// FC2, MySQL, Lighttpd, PHP5, Mojavi/Agavi
    site// //refactored.net/ (Coming soon...)
    quote// Programming is the eternal competition between programmers who try to make apps more and more idiot proof and the universe that makes dumber idiots. So far, the universe is winning...

IMN logo majestic logo threadwatch logo seochat tools logo