Python is known for its "batteries-included" nature. One of the batteries that gets too little attention, I think, the asynchat module.One of my pastimes is playing a certain web game, which features live chat. In a previous incarnation of the game, one of the players wrote a very useful "bot"--an automated pseudo-player that sat around in chat, and provided useful information when queried. She quit before the newest revision of the game was released, though, and some of the players were missing the bot.
So, I pulled out the asynchat module, launched Ethereal, and started reverse-engineering the chat protocol (source and some documentation are available, but the version I was talking to seems to be somewhat customized).
45 minutes later, I had a fully-functional bot. Another hour, and I had a nicely-factored module from which you could build a whole new ultra-wizzy chat client. (Teaching the bot all about the game took another eight hours, of course, but I don't think any libraries would help with that...)
Now the cooler-than-thou Pythonistas out there are probably saying, "Bah! Twisted Rules!". That's nice. Twisted may be sexy, but asynchat/asyncore has some advantages:
- It's simple. Two modules, under 1k lines of code (as opposed to a raft of modules and 80k lines of code). No surprises.
- It's documented, so I don't have to hang out in an IRC room or grovel through thousands of lines of code to figure out what's wrong.
- It's included with Python, so I know it's tested--no surprises when I try it on a new machine.
- It's written in everyday bog-standard Python, not its own framework on top of Python, so there's no prerequisite learning to do.
- I'm reasonably sure that it's not going to be drastically changed.