Akismet.py

December 2, 2005

Akismet is the hot new spam-detector by the same people who brought you WordPress. In fact, it’s so hot and new that the only real way I’ve seen so far to interact with it has been the official plugin (in PHP) for WordPress.

Since the first draft of the API documentation was released earlier today, I thought I’d write up a quick Python module that will talk to it.

It’s a very light wrapper around the API’s functionality. I didn’t want to do anything fancy with this, so I didn’t bother with classes or the like.

To use it, put akismet.py somewhere where Python will see it. The do something like this: (akismet_example.py)

—–

import akismet

akismet.USERAGENT = "MyApplication/MyVersion"

my_api_key = "SOMETHING"

try:
  real_key = akismet.verify_key(my_api_key,"http://www.example.com")
  if real_key:
    is_spam = akismet.comment_check(my_api_key,"http://www.example.com",
      "127.0.0.1", "Mozilla/5.0 (...) Gecko/20051111 Firefox/1.5",
        comment_content="VIAGRA! LOTS OF VIAGRA!")
      if is_spam:
        print "Yup, that's spam alright."
      else:
        print "Hooray, your users aren't scum!"
except akismet.AkismetError, e:
    print e.response, e.statuscode

# If you're a good person, you can report false positives via
# akismet.submit_ham(), and false negatives via akismet.submit_spam(),
# using exactly the same parameters as akismet.comment_check().

—–

I’m not 100% sure of the pure Pythonic nature of the way I’m handling arguments… but it does seem to work.

Download: Akismet.py - Akismet_example.py

Note: To use it you’ll need a valid WordPress.com API key. Which is easy to get — you just just have to join WordPress.com, and you’ll find it in your admin interface, in the “Users” section.

Update: Fuzzyman has written another Python module to access Akismet, taking a more class-oriented approach than mine. So if you hate the minimalist implementation here… there is an alternative! (Okay, it’s not really minimalist — anything which defines Exceptions can’t be called minimalist, to my mind.)

8 Responses to “Akismet.py”

  1. « Akismet Says:

    [...] has written a cool library for using the Akismet API in Python. I expect over the holidays a few more implementations will come out as people have a little more time for hacking on fun projects. We’ve had a few more development rumblings on the spam-stopper mailing list, so if you have something finished be sure to let me know and I’ll be happy to blog about it. [...]

  2. Rauru Blog » Blog Archive » Akismet ã‚’ Perl ã?‹ã‚‰ä½¿ã?† Says:

    [...] Akismet ã‚’ WordPress 以外ã?‹ã‚‰ä½¿ã?†è©±ã?¯å®Œå…¨ã?« Valid ã?®ã‚ˆã?†ã?§ã?™ã€‚Python ã?‹ã‚‰å‘¼ã?³å‡ºã?™æ–¹æ³•ã?Œ kemayo.wordpress.comã?§è§£èª¬ã?•れã?¦ã?„ã?¦ã€?ã?•らã?«ã??れを Matt 自身も紹介ã?—ã?¦ã?¾ã?—ã?Ÿã€‚ [...]

  3. sharedpile Says:

    aaaaaaaaaaaaaaaaaaaaaa

  4. Evitar spam con Akismet - myspace - diseño web Says:

    [...] David Lynch’s Python library [...]

  5. hsoulard Says:

    How can I get “Akismet.py”? I click on the link and nothing happens.

  6. Akismet in Python and API docs « Akismet Says:

    [...] pm, December 1st, 2005 David Lynch has written a cool library for using the Akismet API in Python. I expect over the holidays a few more implementations will come out as people have a little more [...]

  7. kemayo Says:

    hsoulard: Sorry, I didn’t check my moderation queue for some time. The server I had the files parked on apparently went down for a week or two around when you asked your question, so I moved everything to Google Code.

  8. Antispam mon amour… ou comment intégrer Akismet sur vos projets | Korben's Blog Says:

    [...] David Lynch’s Python library [...]

Leave a Reply