Archive for the ‘Tutorial’ Category

Adobe AIR 2 example: UDP sockets with PyAMF and Twisted

Tuesday, January 19th, 2010

The upcoming release of Adobe AIR will provide support for UDP sockets, allowing you to send and receive messages using the Universal Datagram Protocol (UDP).

We created an example, using Adobe AIR 2.0 and the PyAMF and Twisted libraries for Python, that echoes ByteArray messages every x seconds to a Twisted UDP server. The example application also enumerates available hardware and software network interfaces on the client computer using the new NetworkInfo API.

Read more in the tutorial.

screenshot of the example

Running a PyAMF WSGI server in Apache Ant using Jython

Monday, July 20th, 2009

Apache Ant is a Java-based build tool. Ant build files are created using XML but it also support Python scripts using Jython.

There are 2 ways to execute Python scripts in Ant:

JSR-223 enables dynamic languages to be callable via Java in a seamless manner. Unfortunately this is currently only supported with Jython 2.2.1 and not the latest 2.5.0. Since PyAMF only supports Jython 2.5 or newer, you have to use the PythonInterpreter class directly. This style of embedding code is very similar to making use of a scripting engine, but it has the advantage of working with Jython 2.5.

Here you see the gateway running in Ant:

Buildfile: build.xml

clean:

compile:
[mkdir] Created dir: build/classes
[javac] Compiling 1 source file to build/classes

jar:
[mkdir] Created dir: build/jar
[jar] Building jar: build/jar/HelloWorld.jar

run:
[java] *sys-package-mgr*: processing new jar, 'build/jar/HelloWorld.jar'
[java] Running AMF gateway on http://localhost:8000


Read the complete howto, including a sample server/client, on http://docs.pyamf.org/dev/tutorials/jython/ant.html.

Using PyAMF with Apache Tomcat

Monday, July 13th, 2009

Today a new tutorial was added that shows you how to deploy your PyAMF applications with Apache Tomcat and modjy. modjy is an implementation of a WSGI compliant gateway/server for Jython, built on Java/J2EE servlets. This allows you to run Jython WSGI applications inside a Java/J2EE servlet container, e.g. Apache Tomcat. modjy is part of the Jython project.

Tomcat PyAMF

PyAMF server/client using Jython with Swing

Wednesday, May 20th, 2009

Now that the upcoming Jython 2.5 is getting closer to it’s final release, I thought it would be nice to create an example that shows PyAMF running on top of Jython. Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrates with the Java platform. It thus allows you to run Python scripts on any Java platform.

Below you see a screenshot of the example, which was created using Java’s native Swing UI toolkit. It allows you to start a simple AMF server on localhost:8000 and embeds an AMF client that makes calls to that server. This particular example doesn’t interact with an Adobe Flash Player application, it simply shows it’s possible to run PyAMF servers and clients on top of the upcoming Jython release.

Screenshot of Jython/PyAMF example


You can browse or download the source from the Subversion repository. You can find instructions on how to run the example yourself on the wiki page.

SQLAlchemy and Flash: Addressbook example

Monday, March 16th, 2009

SQLAlchemy logo

Dave Thompson created a new address book example that uses the new SQLAlchemy adapter that was added in the latest release of PyAMF. PyAMF provides Action Message Format (AMF) support for Python, mainly used in the Adobe Flash Player for RPC communication.


Get Adobe Flash player



You can browse or download the source from the Subversion repository. You can find instructions on how to run the example yourself on the documentation page.

Getting started with Jython and Apache Ant

Tuesday, December 2nd, 2008

Today I decided to introduce some Jython in one of our build scripts at work because it was simply too painful to use a pure Ant script. It would’ve been nice to avoid the Jython dependency but after screwing around with Ant for a few hours I decided to write a Python script to do the job.

Although the Ant documentation for the Script task is pretty good it wasn’t dead simple to hook up Jython to Ant, and because I couldn’t find any examples online I decided to create a simple example so others might benefit from it. All files (except for the .jar’s) are available in the sandbox of the PyAMF repository.

Steps:

  1. Download Jython and the JSR 223 scripting engine .jar files for Jython
  2. Externalize some paths in a build.properties file (optional)
  3. Create a Python test script that prints out some property defined in the Ant build file
  4. Create the Ant build.xml file that defines a Script task and includes the build.properties file
  5. Run the Ant script on the console and it should output something like:

    Buildfile: build.xml

    jython:
    [script] Apache Ant told Jython: Hello World!

    BUILD SUCCESSFUL
    Total time: 0 seconds

And that’s it, a happy builder!

Interactive Python shell with Flex

Saturday, May 3rd, 2008

Google did the Ajax version of the Python shell, running on Google App Engine, we present you with the Flex version (click image to view the sample):

You can browse or download the source from the Subversion repository. You can find instructions on how to run the example yourself in the documentation.

Ohloh API and Python

Saturday, April 26th, 2008

Ohloh is a website which provides a web services suite and online community platform that aims to map the landscape of open source software development. The Ohloh API is a free, REST-based programming interface to the Ohloh open source directory. You can use the Ohloh API to create your own applications and web services based on Ohloh data. There’s a Python example client and additional examples are available for Java, Ruby, Bash, Perl, PHP and C++.

I decided to create a simple AMF gateway using PyAMF that pulls the account data from Ohloh and then passes it to a Flex application. The reason I use a AMF gateway is because I don’t want to hardcode and expose my API key in the Flex client application, which could be decompiled easily, allowing others to abuse my key.

You can test their API by entering the emailaddress of a registered Ohloh user in the input text-field below, click Submit, and it will display the user’s general account info and load the user’s avatar.

(more…)

Twisted Guestbook Example

Saturday, April 12th, 2008

We created a Guestbook Example to demonstrate a full featured application using Flex, Twisted, and PyAMF of course. Check it out after the jump!

(more…)

Authentication

Sunday, January 13th, 2008

In this tutorial, I’ll run through how to get a remoting server setup that deals with authentication. I’ll assume that you already have the latest version of PyAMF installed (at the time of writing, 0.1b is the most recent version).

I am going to build a WSGI remoting gateway, but you can use the principles applied here to any of the other supported gateway implementations (Django or Twisted). Check out the examples for more info.

(more…)