Skip to main content

A client for SpamHunter API

Project description

📦 Spam Hunter Client

A Python client for the SpamHunter API to check messages for spam probability.
This package supports both synchronous and asynchronous usage.

📚 Documentation: https://spam-hunter.ru/documentation


🚀 Installation

You can install the library via pip:

pip install py-spam-hunter-client

⚡ Usage

🌀 Asynchronous Example

To use the asynchronous version of the API, create an AsyncSpamHunterClient instance and call check in an async context:

import asyncio
from py_spam_hunter_client import AsyncSpamHunterClient, Message

async def check_messages():
    spam_hunter = AsyncSpamHunterClient('Your API key')

    checked_messages = await spam_hunter.check(
        [
            Message('Who wants to make money? PM ME!', ['Hey, everybody.', 'Did you like the movie?'], 'en'),
            Message('Who wants to make money? PM ME!', ['Hey, everybody.', 'Did you like the movie?']),
            Message('Кто хочет заработать? В ЛС!', ['Привет всем.', 'Тебе понравился фильм?'], 'ru'),
            Message('Кто хочет заработать? В ЛС!', ['Привет всем.', 'Тебе понравился фильм?'])
        ]
    )

    for checked_message in checked_messages:
        print(checked_message.get_spam_probability())

asyncio.run(check_messages())

🔁 Synchronous Example

To use the synchronous version of the API, use SyncSpamHunterClient:

from py_spam_hunter_client import SyncSpamHunterClient, Message

spam_hunter = SyncSpamHunterClient('Your API key')

checked_messages = spam_hunter.check(
    [
        Message('Who wants to make money? PM ME!', ['Hey, everybody.', 'Did you like the movie?'], 'en'),
        Message('Who wants to make money? PM ME!', ['Hey, everybody.', 'Did you like the movie?']),
        Message('Кто хочет заработать? В ЛС!', ['Привет всем.', 'Тебе понравился фильм?'], 'ru'),
        Message('Кто хочет заработать? В ЛС!', ['Привет всем.', 'Тебе понравился фильм?'])
    ]
)

for checked_message in checked_messages:
    print(checked_message.get_spam_probability())

📘 API Reference

check(messages: List[Message]) -> List[CheckedMessage]

Available in both async and sync clients:

  • AsyncSpamHunterClient.check(messages) — asynchronous
  • SyncSpamHunterClient.check(messages) — synchronous

Parameters:

  • messages: A list of Message instances to be checked.

Returns:

Raises:

  • CheckException: Raised if the request fails or the API returns an error.

📩 Message Object

Represents a message submitted for spam analysis.

Constructor:

Message(
    text: str,
    contexts: List[str],
    language: Optional[str] = None,
    id: Optional[str] = None
)

Attributes:

  • id (str, optional): A custom identifier for the message.
  • text (str): The main content of the message.
  • contexts (List[str]): Previous messages or context (e.g., recent chat history).
  • language (str, optional): Language code:
    • 'en' — English
    • 'ru' — Russian
    • None — for automatic detection

🔢 CheckedMessage Object

Represents the result of a spam check returned by the API.

Attributes:

  • id (str, optional): The custom ID of the original message.
  • spam_probability (float): A float between 0 and 1 indicating spam likelihood.

Methods:

get_spam_probability() -> float

Returns the spam probability score for the message.

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

py_spam_hunter_client-3.1.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

py_spam_hunter_client-3.1.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file py_spam_hunter_client-3.1.3.tar.gz.

File metadata

  • Download URL: py_spam_hunter_client-3.1.3.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for py_spam_hunter_client-3.1.3.tar.gz
Algorithm Hash digest
SHA256 d775167d6bc8fb31c79c0327e858b06bdc75dc6f5ff2a38b4e899ec875015d10
MD5 e9eef36f7a8659bdf3d9ca9d22939ecc
BLAKE2b-256 817b8529ddb08f03bb5944603fd0aae952f2c551df01367f6aec64882c74d620

See more details on using hashes here.

File details

Details for the file py_spam_hunter_client-3.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for py_spam_hunter_client-3.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2a8fd89d5acf769f41721d99388f79ce8d3bae7721b766a3a300dd57cac2ca29
MD5 c971960307c58b90cc6d1baf469598b7
BLAKE2b-256 9e82b553193e0dc2c06b6412f6f2f965b3e2b698a1a4a0c99335016865119278

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