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
You can install the library via pip:
pip install py-spam-hunter-clientTo 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())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())Available in both async and sync clients:
AsyncSpamHunterClient.check(messages)— asynchronousSyncSpamHunterClient.check(messages)— synchronous
Parameters:
messages: A list ofMessageinstances to be checked.
Returns:
- A list of
CheckedMessageinstances with spam probability results.
Raises:
CheckException: Raised if the request fails or the API returns an error.
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'— RussianNone— for automatic detection
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 between0and1indicating spam likelihood.
Methods:
get_spam_probability() -> floatReturns the spam probability score for the message.