5

I want to have a browser page that updates some information on a timer or events. I'd like to use Python on the server side. It's quite simple, I don't need anything massively complex.

I can spend some time figuring out how to do all this the "AJAX way", but I'm sure someone has written a nice Python library to do all the heavy lifting. If you have used such a library please let me know the details.

Note: I saw how-to-implement-a-minimal-server-for-ajax-in-python but I want a library to hide the implementation details.

Community
  • 1
  • 1
Nick
  • 27,566
  • 12
  • 60
  • 72
  • What do you mean by "Ajax Library"? Javascript for Ajax? Or a web server for your Ajax transactions? – S.Lott Apr 02 '09 at 14:12
  • 1
    @S.Lott: I think he means server side handling since he mentions python – Brian R. Bondy Apr 02 '09 at 14:15
  • @Brian R. Bondy: Very likely true. However, the "hiding implementation details" could mean anything. And "AJAX library" often means JavaScript side of AJAX -- first hit on a Google search of AJAX Library is Yahoo User Interface Library. – S.Lott Apr 02 '09 at 15:06
  • ha! Sorry for the confusion. I'll clarify the question information. Sorry! – Nick Apr 06 '09 at 10:15
  • 1
    I'm using Web2py with Pyjamas. http://www.web2py.com/AlterEgo/default/show/203 Web2py's json handles AJAX comms and its been a joy writing browser client code in Python rather than native Javascript. – Carl Aug 15 '09 at 09:16

3 Answers3

5

AJAX stands for Asynchronous JavaScript and XML. You don't need any special library, other than the Javascript installed on the browser to do AJAX calls. The AJAX requests comes from the client side Javascript code, and goes to the server side which in your case would be handled in python.

You probably want to use the Django web framework.

Check out this tutorial on Django tips: A simple AJAX example.

Here is a simple client side tutorial on XmlHTTPRequest / AJAX

Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
  • You'd think there's no need for special library, but all the articles and tutorials seem to depend one one or more behemoth libraries. – XTL Feb 01 '12 at 20:13
5

You can also write both the client and server side of the ajax code using python with pyjamas:

Here's an RPC style server and simple example:

http://www.machine-envy.com/blog/2006/12/10/howto-pyjamas-pylons-json/

Lots of people use it with Django, but as the above example shows it will work fine with Pylons, and can be used with TurboGears2 just as easily.

I'm generally in favor of learning enough javascript to do this kind of thing yourself, but if your problem fits what pygjamas can do, you'll get results from that very quickly and easily.

Mark Ramm
  • 111
  • 5
  • Yes, that looks along the lines of what I want. I shall investigate further. Cheers! – Nick Apr 06 '09 at 10:22
1

I suggest you to implement the server part in Django, which is in my opinion a fantastic toolkit. Through Django, you produce your XML responses (although I suggest you to use JSON, which is easier to handle on the web browser side).

Once you have something that generates your reply on server side, you have to code the javascript code that invokes it (through the asynchronous call), gets the result (in JSON) and uses it to do something clever on the DOM tree of the page. For this, you need a JavaScript library.

I did some experience with various javascript libraries for "Web 2.0". Scriptaculous is cool, and Dojo as well, but my absolute favourite is MochiKit, because they focus on a syntax which is very pythonic, so it will hide you quite well the differences between javascript and python.

Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
  • Not sure I need a whole server framework like Django. Mochikit looks very interesting as I only need the AJAX functionality. Thanks. – Nick Apr 06 '09 at 10:23