February 3, 2010

Pre-order your copy of Spring Python 1.1 book today!

Filed under: book — gregturn @ 4:04 pm

Spring Python 1.1

Pre-order your copy of the Spring Python book!

“Create powerful and versatile Spring Python applications using pragmatic libraries and useful abstractions

  • Maximize the use of Spring features in Python and develop impressive Spring Python applications
  • Explore the versatility of Spring Python by integrating it with frameworks, libraries, and tools
  • Discover the non-intrusive Spring way of wiring together Python components
  • Packed with hands-on-examples, case studies, and clear explanations for better understanding”
  • Visit the Packt Publishing site for more details.

    VN:F [1.8.1_1037]
    Rating: 1.0/5 (1 vote cast)
    VN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
    Share and Enjoy:
    • Digg
    • Sphinn
    • del.icio.us
    • Facebook
    • Mixx
    • Google Bookmarks
    • Reddit
    • LinkedIn

    January 22, 2010

    Spring Python 1.1.0.M1 Released

    Filed under: news, releases — gregturn @ 2:15 pm

    See http://www.springsource.org/node/2282 for the official announcement.

    I chatted with Mark Pollack earlier this week and asked if we wouldn’t mind me taking over. He said no problem, and I was able to get keys later to push releases up to SpringSource’s S3 site.

    This release is first milestone in our new 1.1 baseline. More features, improvements, and enhancements will be coming out with the next milestone, as we work towards getting this released.

    VN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.8.1_1037]
    Rating: +1 (from 1 vote)
    Share and Enjoy:
    • Digg
    • Sphinn
    • del.icio.us
    • Facebook
    • Mixx
    • Google Bookmarks
    • Reddit
    • LinkedIn

    December 12, 2009

    I’m going to work for SpringSource

    Filed under: news — gregturn @ 1:05 pm

    Starting January 11th, I’m going to be working for SpringSource. I told my daughter, Audrey, and look what she had to say!

    Audrey_heart_spring

    I’m glad she approves.

    No, they didn’t hire me to work on Spring Python. That is still in my spare time. Hopefully, I can become sponsor and not have to bug Mark Pollack.

    Anyway, my first assignment will involve working on integration between tcServer and some of SpringSource’s management products. I can’t wait!

    VN:F [1.8.1_1037]
    Rating: 4.5/5 (2 votes cast)
    VN:F [1.8.1_1037]
    Rating: +1 (from 1 vote)
    Share and Enjoy:
    • Digg
    • Sphinn
    • del.icio.us
    • Facebook
    • Mixx
    • Google Bookmarks
    • Reddit
    • LinkedIn

    October 15, 2009

    See how Spring Python works with Jython

    Filed under: java, jython, python — gregturn @ 1:59 pm

    I recently completed a patch that replaces the amara library with python’s default elementTree library. As much as I like amara’s API, its C-extension basis was unacceptable. I just merged the patch into the trunk, and verified it works with Jython 2.5.1.FINAL. When Spring Python’s 1.1.0.M2 release comes out, we will be Jython-compatible.

    With this change, there were only a couple of tweaks to the rest of Spring Python.

    What does this mean? How about looking at some code to see how we can start with a Java app, and migrate things over to Python. To kick this off, let’s start with an uber-contrived example Java app: a wiki engine. The wiki engine calls into a data access layer in order to look up some statistics on the site.

    public interface DataAccess {
     
            public void statistics();
     
    }
    public class MySqlDataAccess implements DataAccess {
     
            public void statistics() {
                    System.out.println("MySQL: You are calling for some statistics.");
            }
     
    }
    public class WikiService {
     
            private DataAccess dataAccess;
     
            public DataAccess getDataAccess() {
                    return this.dataAccess;
            }
     
            public void setDataAccess(DataAccess dataAccess) {
                    this.dataAccess = dataAccess;
            }
     
            public void calculateWikiStats() {
                    System.out.println("You are passing through a pure Java WikiService...");
                    dataAccess.statistics();
            }
     
    }

    Let’s assume this is a Spring app. That means we need an XML application context. Let’s create one and call it javaBeans.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
     
            <bean id="dataAccess" class="MySqlDataAccess"/>
     
            <bean id="wikiService" class="WikiService">
                    <property name="dataAccess" ref="dataAccess"/>
            </bean>
     
    </beans>

    We can start up our pure java app along with its context by writing jython script javabeans.py. It uses Spring Python’s SpringJavaConfig parser.

    if __name__ == "__main__":
        from springpython.context import ApplicationContext
        from springpython.config import SpringJavaConfig
        ctx = ApplicationContext(SpringJavaConfig("javaBeans.xml"))
        service = ctx.get_object("wikiService")
        service.calculateWikiStats()

    We just need to compile the java code, and then run our script using jython.

    gregturn@startrek:~$ javac *.java
    gregturn@startrek:~$ jython javabeans.py
    You are passing through a pure Java WikiService...
    MySQL: You are calling for some statistics.
    gregturn@startrek:~$

    Okay, we’re off to a good start. We have tapped a running java system. For our next step, let’s write a pure python version of the data access code and put it into Py.py.

    import DataAccess
     
    class MySqlDataAccess(DataAccess):
        def statistics(self):
            print "PyMySQL: You are calling for some statistics."
     
    class StubDataAccess(DataAccess):
        def statistics(self):
            print "PyStub: You are calling for some statistics."

    Now, to really crank things up a bit, let’s migrate from the Spring Java XML configuration over to Spring Python’s pure Python container.

    from springpython.config import PythonConfig, Object
    from Py import MySqlDataAccess
    import WikiService
     
    class WikiProductionAppConfig(PythonConfig):
        def __init__(self):
            PythonConfig.__init__(self)
     
        @Object
        def data_access(self):
            return MySqlDataAccess()
     
        @Object
        def wiki_service(self):
            results = WikiService()
            results.dataAccess = self.data_access()
            return results
     
    if __name__ == "__main__":
        from springpython.context import ApplicationContext
        ctx = ApplicationContext(WikiProductionAppConfig())
        service = ctx.get_object("wiki_service")
        service.calculateWikiStats()

    The top half of our mixed.py script contains an IoC container, except there is no XML whatsoever. Instead, its raw python. You can see how we are also using our python version of MySqlDataAccess.

    gregturn@startrek:~$ jython mixed.py
    You are passing through a pure Java WikiService...
    PyMySQL: You are calling for some statistics.
    gregturn@startrek:~$

    This shows that we are still using the pure java WikiService class, and it calls into our pure python MySqlDataAccess.

    Another useful feature that Spring Python provides is easy access to Pyro, the Python Remote Objects library. This library is for making RPC calls from Python-to-Python. Spring Python makes it easy to link clients and services together with Pyro.

    First, let’s take our wiki service, and export it with a server script.

    from springpython.config import PythonConfig, Object
    from springpython.remoting.pyro import *
     
    from Py import MySqlDataAccess
    import WikiService
     
    class WikiProductionAppConfig(PythonConfig):
        def __init__(self):
            PythonConfig.__init__(self)
     
        @Object
        def data_access(self):
            return MySqlDataAccess()
     
        @Object
        def wiki_service(self):
            results = WikiService()
            results.dataAccess = self.data_access()
            return results
     
        @Object
        def exported_wiki_service(self):
            return PyroServiceExporter(service=self.wiki_service(), service_name="wiki", service_port=9000)
     
    if __name__ == "__main__":
        from springpython.context import ApplicationContext
        print "Starting up exported WikiService..."
        ctx = ApplicationContext(WikiProductionAppConfig())

    We made some slight tweaks to the IoC container by adding exported_wiki_service. It targets wiki_service, and links it with a name and port to expose it as a Pyro service. Spring Python by default will instantiate every object, so in this case, it creates the PyroProxyExporter. Because this isn’t the caller, we don’t need to fetch anything from the context.

    Next, let’s code a client to call our service.

    from springpython.config import PythonConfig, Object
    from springpython.remoting.pyro import *
     
    class WikiProductionAppConfig(PythonConfig):
        def __init__(self):
            PythonConfig.__init__(self)
     
        @Object
        def wiki_service(self):
            results = PyroProxyFactory()
            results.service_url="PYROLOC://localhost:9000/wiki"
            return results
     
    if __name__ == "__main__":
        from springpython.context import ApplicationContext
        ctx = ApplicationContext(WikiProductionAppConfig())
        service = ctx.get_object("wiki_service")
        service.calculateWikiStats()

    Now, let’s start up the server.

    gregturn@startrek:~$ jython mixed_with_pyro_server.py &
    [1] 4953
    Starting up exported WikiService...

    The script is backgrounded, because it is running a Pyro daemon advertising our service. Now, let’s launch the client script.

    gregturn@startrek:~$ jython mixed_with_pyro_client.py
    You are passing through a pure Java WikiService...
    PyMySQL: You are calling for some statistics.
    gregturn@startrek:~$

    As you can see, our client makes remote to the exported WikiService, which happens to be a pure java service. The java service then calls our python version of MySqlDataAccess to do its statistics call. This goes to show how easy Spring Python makes it mix and match Java and Python.

    VN:F [1.8.1_1037]
    Rating: 4.5/5 (2 votes cast)
    VN:F [1.8.1_1037]
    Rating: +1 (from 1 vote)
    Share and Enjoy:
    • Digg
    • Sphinn
    • del.icio.us
    • Facebook
    • Mixx
    • Google Bookmarks
    • Reddit
    • LinkedIn

    September 24, 2009

    Welcome Sven Wilhelm!

    Filed under: news — gregturn @ 8:22 am

    I wanted to introduce another team member: Sven Wilhelm. We just granted him commit privileges this week. Sven has been using Spring Python as a core piece of his team’s system. He has been doing a bit of work on making Spring Python work with Jython (which I’m VERY interested in!), as well as working on a Spring Python Ldap module. With Sven on the team, we will be able to make these parts available to you as well.

    Sven, thanks for joining the Spring Python team!

    VN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
    Share and Enjoy:
    • Digg
    • Sphinn
    • del.icio.us
    • Facebook
    • Mixx
    • Google Bookmarks
    • Reddit
    • LinkedIn
    Next Page »