Thursday, March 27, 2008

Twisted 8.0 released!

MASSACHUSETTS (DP) -- Version 8.0 of the Twisted networking framework has been released, Twisted Matrix Laboratories announced Wednesday.

Enslaved by his new robotic overlords, Master of the Release Christopher Armstrong presented the new package to the Internet on March 26th. Armstrong was unable to comment, because of a device worn around his neck preventing him from doing so, scientists say.

Secretary of Defense Jean-Paul Calderone was asked about concerns that French interference may have played a role in the delay of this release. "I find such speculation preposterous. Thomas Hervé is an upstanding member of the Labs and his loyalties lie with us. He is a fine addition to our team." Rumors in the community allege that Secretary Calderone is holding Hervé's cat ransom until the release is successfully distributed. Hervé was unavailable for comment.

This release comes shortly after the announcement by Chief of Public Affairs Duncan McGreggor that Twisted had joined the Software Freedom Conservancy. "We're happy to join the SFC, and we are now accepting sponsorship. The fact that we are now ruled by a cabal of robots should not put off potential donors. Our robotic overlords are running us at peak efficiency, so we can most effectively distribute The Love."

Asked about the version number jump in this release, Commander-in-Chief Glyph Lefkowitz had the following to say: "Our benefactors have found our previous dice-rolling version number scheme to be inadequate, and have deigned to propose to us a more... logical system of versioning."



Twisted 8.0 is a major feature release, with several new features and a great number of bug fixes. Some of the highlights follow.
  • The IOCP reactor is now much improved and many bugs have been resolved.
  • Twisted is now easy_installable.
  • Many improvements were made to Trial, Twisted's unit testing system.
  • A new memcache client protocol implementation was added.
  • So much more!
To see the full list of changes in its fifteen kilobytes of glory, see the release notes. We welcome you to download and enjoy, and please file any bugs you find and send comments to the mailing list.

Why the large version number bump? We've decided to switch to a time-based versioning scheme. "8.0" means the first release in 2008.

Thanks!

Sunday, March 16, 2008

Twisted Announces Membership in the Software Freedom Conservancy

At PyCon 2008 we were delighted to share some good news with the Python community: the announcement of the Twisted Software Foundation. Glyph had previously emailed the Twisted mail list, letting those close to the project know of this major event shortly after the paperwork was signed. Before we brought this before a more public audience, we wanted to give companies a chance to become "founding sponsors" -- and this is what has happened at PyCon. We're looking forward to issuing a formal press release about this (including info on the founding sponsors) and will have more details in the near future.

We would like to send a special thank-you out to those sponsors who made contributions immediately. In order of contribution, they are:

  • Chris Armstrong
  • Michel Pelletier
  • AdytumSolutions, Inc.
  • tummy.com
  • Drew Perttula
  • Glenn Tarbox
  • Ilya Novoselov

Read the initial announcement here. If the video for the announcement made at PyCon gets published somewhere, we will post an update.

Update: Thanks to feedback from Grig Gheorghiu, we now have two domains that direct to the TSF page:

Tuesday, February 26, 2008

The Twisted Show: Episode 2

Yesterday I had the chance to talk with Jack Moffitt and Christopher Zorn of Chesspark about their company, their vision, and how Twisted played an integral role in their application and helped them to meet their goals.

The interview is on the site and the feed is available here.

We're still experimenting with podcasting and feed enclosures, so please be patient with us! If you have any issues, the media files are available at archive.org.

Monday, February 25, 2008

Twisted Talks at PyCon 2008

There will be two Twisted-related talks at PyCon this year:

"Tahoe: A Robust Distributed Secure Filesystem" -- Brian Warner, of Twisted Foolscap fame, discusses his company's distributed file system, built on Twisted. Tahoe is free, secure, decentralized, fault-tolerant filesystem. This filesystem is encrypted and spread over multiple peers in such a way that it remains available even when some of the peers are unavailable, malfunctioning, or malicious.

"Adventures in Stackless Python/Twisted Integration" -- Andrew Francis will be discussing the Web Service Business Process Execution Language, particularly he integrated Stackless Python and Twisted.

Technorati Tags: , ,

Wednesday, February 20, 2008

RSS Flood Apology

Hey all,

A quick note to apologize for the RSS updates you'll be getting that are full of old news. I just finished sync'ing Twisted news to the labs blog (and tagging them with "news"). There weren't many items, so the pain of the RSS flood should be minimal. I offer apologies nonetheless :-)

The upshot of all this is that we now have a couple different RSS feeds for your viewing pleasure:
An RSS feed for our news items has been a long-standing request of the community, and we're glad to be able to finally offer this.

You can also view the news items in either of these three places:
You can expect more news, howtos, theses and other fascinating textual content on labs.twistedmatrix.com. Be sure to visit us often for your Twisted fix :-)

Sunday, February 17, 2008

Twisted's filepath Module

Glyph recently blogged about some of the buried treasure in Twisted, the filepath module in particular. Since working at Divmod, I've made use of this module quite a bit, and thought I'd share some of the features that I've found most useful (and intuitively nice to use).

Assuming you've got Twisted installed, let's fire up a python interpreter and import the FilePath class and instantiate it with /tmp:

>>> from twisted.python.filepath import FilePath
>>> tmp = FilePath('/tmp')


Now let's test some basic operations:

>>> tmp.exists()
True
>>> bogus = tmp.child('bogus')
>>> bogus.exists()
False


Isn't that nice? I love not having to import and use the os.path.exists function; it's a method on the object representing a file or a path, as it should be. I also enjoy the convenience FilePath offers when it comes to creating paths:

>>> mydir = tmp.child('notbogus').child('anotherdir').child('mydir')
>>> mydir.exists()
False
>>> mydir.makedirs()
>>> mydir.restat()
>>> mydir.exists()
True


We had to call restat() so that the object would check the file system again (since we just made some changes). Now, for some files:

>>> for filename in ['test1.txt', 'test2.txt', 'test3.tst']:
... mydir.child(filename).touch()
...
>>> mydir.listdir()
['test1.txt', 'test2.txt', 'test3.tst']


And if you don't believe that, we can switch to shell:

lorien:oubiwann 20:51:58 $ ls -al /tmp/notbogus/anotherdir/mydir/
total 0
drwxr-xr-x 2 oubiwann wheel 170 Feb 17 20:51 .
drwxr-xr-x 3 oubiwann wheel 102 Feb 17 20:46 ..
-rw-r--r-- 1 oubiwann wheel 0 Feb 17 20:51 test1.txt
-rw-r--r-- 1 oubiwann wheel 0 Feb 17 20:51 test2.txt
-rw-r--r-- 1 oubiwann wheel 0 Feb 17 20:51 test3.tst


Reading and writing operations are the same as usual:

>>> myfile = mydir.child(filename)
>>> myfile.isdir()
False
>>> myfile.islink()
False
>>> myfile.isfile()
True
>>> fh = myfile.open('w+')
>>> fh.write('do the usual thing')
>>> fh.close()
>>> myfile.getsize()
18L
>>> myfile.open().read()
'do the usual thing'


But you can use shortcuts like this, too:

>>> myfile.getContent()
'do the usual thing'
>>> myfile.setContent('and now for somethibg completely different...')
>>> myfile.getContent()
'and now for somethibg completely different...'


Let's get the path and recheck the file size, just to make sure:

>>> myfile.path
'/tmp/notbogus/anotherdir/mydir/test3.tst'
>>> myfile.restat()
>>> myfile.getsize()
45L

Or, again from shell:

lorien:oubiwann 20:52:06 $ ls -al /tmp/notbogus/anotherdir/mydir/
total 8
drwxr-xr-x 2 oubiwann wheel 170 Feb 17 20:58 .
drwxr-xr-x 3 oubiwann wheel 102 Feb 17 20:46 ..
-rw-r--r-- 1 oubiwann wheel 0 Feb 17 20:51 test1.txt
-rw-r--r-- 1 oubiwann wheel 0 Feb 17 20:51 test2.txt
-rw-r--r-- 1 oubiwann wheel 45 Feb 17 20:58 test3.tst


Hmm... for some reason, I really like this file and want to keep it. What do I do?

>>> docs = FilePath('/Users/oubiwann/Documents')
>>> myfile.moveTo(docs.child('special_file.txt'))


That's it! Nice, eh? Of course, we're careful, so we check to make sure it happened:

>>> myfile.exists()
False
>>> newfile = docs.child('special_file.txt')
>>> newfile.exists()
True
>>> newfile.path
'/Users/oubiwann/Documents/special_file.txt'
>>> newfile.getsize()
45L
>>> newfile.getContent()
'and now for somethibg completely different...'


To see more, check out the source, or at least do dir(FilePath) to see what other goodies this class has to offer, and enjoy :-)

Technorati Tags: , ,

Wednesday, February 13, 2008

Simple Python Web Server

Corey Goldberg blogged about making simple web interfaces. I was going to comment with another example of a simple web server, but his blog kept spitting back errors, so I'll post it here instead.

Corey's code was based on BaseHTTPServer, here's another way to do this (as a Twisted tac file):

from twisted.web import server, resource
from twisted.application import internet, service

class Foo(resource.Resource):
def render(self, request):
return "hello world"

root = resource.Resource()
root.putChild("foo", Foo())

application = service.Application("Tiny Web")
internet.TCPServer(8080, server.Site(root)).setServiceParent(application)

Of course, it requires a bit more than just the standard library. ;) This has a couple extra nice features though - it does logging, for example, and it can be trivially daemonized, or run under the profiler or the debugger, or chrooted or as a different uid/gid. Plus the Foo resource can easily be relocated into a "real" program, since it is entirely distinct from the HTTP server part of the code.

There's an even simpler way to express this though, as an rpy instead of a tac:

from twisted.web.resource import Resource

class Foo(Resource):
def render(self, request):
return "hello world"

resource = Foo()

Just drop this into a directory and run a Twisted web server pointed at it (eg, twistd web --processor rpy=twisted.web.script.ResourceScript --path bar/). You can even change the code without restarting the server if you do it this way. rpys can be convenient for one-off hacks, but clearly it's not suitable for anything larger scale than that.