Skip to main content

A Python interface to the Akismet spam-filtering service.

Project description

CI status image

A Python interface to the Akismet spam-filtering service.

Two API clients are available from this library:

  • akismet.SyncClient is an Akismet API client which performs synchronous (blocking) HTTP requests to the Akismet web service.

  • akismet.AsyncClient is an Akismet API client which performs asynchronous (async/await/non-blocking) HTTP requests to the Akismet web service.

Aside from one being sync and the other async, the two clients expose identical APIs, and implement all methods of the Akismet web API.

To use this library, you will need to obtain an Akismet API key and register a site for use with the Akismet web service; you can do this at <https://akismet.com>. Once you have a key and corresponding registered site URL to use with it, place them in the environment variables PYTHON_AKISMET_API_KEY and PYTHON_AKISMET_BLOG_URL, and they will be automatically detected and used.

You can then construct a client instance and call its methods. It’s recommended that you always use a client construction method which will automatically validate your API key with the Akismet web service. You can do this by creating your client as a context manager, in which case the key is automatically validated on entering the with block:

import akismet

with akismet.SyncClient() as akismet_client:
    if akismet_client.comment_check(
        user_ip=submitter_ip,
        comment_content=submitted_content,
        comment_type="forum-post",
        comment_author=submitter_name
    ):
        # This piece of content was classified as spam; handle it appropriately.

Or using the asynchronous client:

import akismet

async with akismet.AsyncClient() as akismet_client:
    if await akismet_client.comment_check(
        user_ip=submitter_ip,
        comment_content=submitted_content,
        comment_type="forum-post",
        comment_author=submitter_name
    ):
        # This piece of content was classified as spam; handle it appropriately.

Or you can use the validated_client() constructor method, which will validate your key when constructing the client instance:

import akismet

akismet_client = akismet.SyncClient.validated_client()

if akismet_client.comment_check(
    user_ip=submitter_ip,
    comment_content=submitted_content,
    comment_type="forum-post",
    comment_author=submitter_name
):
    # This piece of content was classified as spam; handle it appropriately.

Or using the asynchronous client:

import akismet

akismet_client = await akismet.AsyncClient.validated_client()

if await akismet_client.comment_check(
    user_ip=submitter_ip,
    comment_content=submitted_content,
    comment_type="forum-post",
    comment_author=submitter_name
):
    # This piece of content was classified as spam; handle it appropriately.

You can also use either client class as a context manager. This does not require the validated_client() constructor, because your API key is validated on entering the with block.

See the documentation for full details.

The original version of this library was written by Michael Foord.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

akismet-25.10.0.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

akismet-25.10.0-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file akismet-25.10.0.tar.gz.

File metadata

  • Download URL: akismet-25.10.0.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.13.0

File hashes

Hashes for akismet-25.10.0.tar.gz
Algorithm Hash digest
SHA256 28032b6b4f7c679fe828290e46d2ad9c2d0a7d20ea0a514a35de5ee9f6e69458
MD5 35979e9704ffba4bfe64e79f2500d505
BLAKE2b-256 31a9a14028417e8b3a875b61ffd63f1b6d51048c0409fe2bed450701dec3a9a1

See more details on using hashes here.

File details

Details for the file akismet-25.10.0-py3-none-any.whl.

File metadata

  • Download URL: akismet-25.10.0-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.13.0

File hashes

Hashes for akismet-25.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e9fe9502bb5e7f345b3687fd867bbd0e826ad728b978a8948f9530927e89eb6
MD5 7b447b18b6720e1416ced267b344a2d0
BLAKE2b-256 9b34b86c5c299a6e20421a3ea169134cecfec3fe25e653ee215194e392200ebf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page