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. For creating a long-lived API client instance, it’s recommended that you use the validated_client() constructor method, which will automatically validate your API key with the Akismet web service. For example, to check a submitted forum post for spam:

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.

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.

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-24.5.1.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

akismet-24.5.1-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: akismet-24.5.1.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.0

File hashes

Hashes for akismet-24.5.1.tar.gz
Algorithm Hash digest
SHA256 7210f20e5a732ccf91e51424e49c9ec500b285ae920ad510cd3331e8309b6359
MD5 eee7953b0912b336c0747c228cd6920f
BLAKE2b-256 8ce8fb25ef8297644d69cac007fb57c5e45d43f438fb7196c6299feb82ebd98a

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: akismet-24.5.1-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.0

File hashes

Hashes for akismet-24.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92c345d61a249be74ef782217276ea752cd1dff274080bdbaf1bd48609111a92
MD5 ba3f21a279dc36123ce05aa7bee07d02
BLAKE2b-256 337493c36bb8bd19e2118adce20ebc87aae04f37ece599e91d9409842436ecea

See more details on using hashes here.

Provenance

Supported by

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