Overview
The MentionClient class provides a typed, synchronous interface for interacting with all Mention API endpoints. It includes full type hints, automatic request/response validation, retry logic, and context manager support.
Constructor
MentionClient(
access_token: str,
*,
base_url: str = "https://api.mention.net/api",
timeout: float = 30.0,
max_retries: int = 3,
retry_delay: float = 1.0,
) -> None
Parameters
OAuth2 access token for authentication
base_url
str
default:"https://api.mention.net/api"
Base URL for the Mention API
Request timeout in seconds
Maximum number of retry attempts for failed requests
Base delay between retries in seconds (uses exponential backoff)
Class Methods
from_config
@classmethod
def from_config(cls, config: MentionConfig) -> MentionClient
Create a client from a MentionConfig instance.
Parameters:
config (MentionConfig): Configuration object
Returns: Configured MentionClient instance
Public Methods
App Data
get_app_data
def get_app_data(self) -> AppData
Retrieve application data including available sources, languages, etc.
Returns: AppData object with application configuration
Account Methods
create_account
def create_account(
self,
name: str,
email: str,
password: str,
company: str | None = None,
language: str = "en",
timezone: str = "UTC",
) -> Account
Create a new account.
Returns: Created Account object
get_account
def get_account(self, account_id: str) -> Account
Retrieve account information.
Returns: Account object
get_account_me
def get_account_me(self) -> Account
Retrieve current user’s account information.
Returns: Account object for the authenticated user
update_account
def update_account(
self,
account_id: str,
name: str | None = None,
email: str | None = None,
company: str | None = None,
language: str | None = None,
timezone: str | None = None,
) -> Account
Update account information.
Returns: Updated Account object
delete_account
def delete_account(self, account_id: str) -> bool
Delete an account.
Returns: True if deletion was successful
Alert Methods
get_alerts
def get_alerts(self, account_id: str) -> AlertsResponse
Fetch all alerts for an account.
Returns: AlertsResponse containing list of alerts
get_alert
def get_alert(self, account_id: str, alert_id: str) -> Alert
Fetch a single alert by ID.
Returns: Alert object
create_alert
def create_alert(self, account_id: str, request: CreateAlertRequest) -> Alert
Create a new alert.
Returns: Created Alert object
update_alert
def update_alert(
self,
account_id: str,
alert_id: str,
request: UpdateAlertRequest,
) -> Alert
Update an existing alert.
Returns: Updated Alert object
delete_alert
def delete_alert(self, account_id: str, alert_id: str) -> bool
Delete an alert.
Returns: True if deletion was successful
pause_alert
def pause_alert(self, account_id: str, alert_id: str) -> bool
Pause an alert (stop monitoring).
Returns: True if pause was successful
unpause_alert
def unpause_alert(self, account_id: str, alert_id: str) -> bool
Unpause an alert (resume monitoring).
Returns: True if unpause was successful
Mention Methods
get_mentions
def get_mentions(
self,
account_id: str,
alert_id: str,
*,
limit: int = 100,
before_date: datetime | str | None = None,
not_before_date: datetime | str | None = None,
since_id: str | None = None,
source: str | None = None,
read: bool | None = None,
favorite: bool | None = None,
tone: str | None = None,
cursor: str | None = None,
) -> MentionsResponse
Fetch mentions for an alert with optional filtering.
Returns: MentionsResponse containing list of mentions
iter_mentions
def iter_mentions(
self,
account_id: str,
alert_id: str,
*,
limit: int = 100,
**kwargs: Any,
) -> Iterator[Mention]
Iterate over all mentions with automatic pagination.
Yields: Mention objects
get_mention
def get_mention(
self,
account_id: str,
alert_id: str,
mention_id: str,
) -> Mention
Fetch a single mention by ID.
Returns: Mention object
curate_mention
def curate_mention(
self,
account_id: str,
alert_id: str,
mention_id: str,
request: CurateMentionRequest,
) -> Mention
Update/curate a mention.
Returns: Updated Mention object
mark_all_mentions_read
def mark_all_mentions_read(self, account_id: str, alert_id: str) -> bool
Mark all mentions for an alert as read.
Returns: True if successful
get_mention_children
def get_mention_children(
self,
account_id: str,
alert_id: str,
mention_id: str,
) -> MentionsResponse
Fetch child mentions (replies, comments) of a mention.
Returns: MentionsResponse containing child mentions
stream_mentions
def stream_mentions(
self,
account_id: str,
alert_id: str,
*,
since: datetime | str | None = None,
) -> Iterator[Mention]
Stream mentions in real-time using long-polling.
Yields: Mention objects as they arrive
Task Methods
get_tasks
def get_tasks(self, account_id: str, alert_id: str) -> TasksResponse
Fetch all tasks for an alert.
Returns: TasksResponse containing list of tasks
get_mention_tasks
def get_mention_tasks(
self,
account_id: str,
alert_id: str,
mention_id: str,
) -> TasksResponse
Fetch all tasks for a specific mention.
Returns: TasksResponse containing list of tasks
get_task
def get_task(
self,
account_id: str,
alert_id: str,
mention_id: str,
task_id: str,
) -> Task
Fetch a single task by ID.
Returns: Task object
create_task
def create_task(
self,
account_id: str,
alert_id: str,
mention_id: str,
request: CreateTaskRequest,
) -> Task
Create a new task for a mention.
Returns: Created Task object
update_task
def update_task(
self,
account_id: str,
alert_id: str,
mention_id: str,
task_id: str,
request: UpdateTaskRequest,
) -> Task
Update an existing task.
Returns: Updated Task object
delete_task
def delete_task(
self,
account_id: str,
alert_id: str,
mention_id: str,
task_id: str,
) -> bool
Delete a task.
Returns: True if deletion was successful
Tag Methods
def get_tags(self, account_id: str, alert_id: str) -> TagsResponse
Fetch all tags for an alert.
Returns: TagsResponse containing list of tags
create_tag
def create_tag(
self,
account_id: str,
alert_id: str,
request: CreateTagRequest,
) -> Tag
Create a new tag for an alert.
Returns: Created Tag object
update_tag
def update_tag(
self,
account_id: str,
alert_id: str,
tag_id: str,
request: UpdateTagRequest,
) -> Tag
Update an existing tag.
Returns: Updated Tag object
delete_tag
def delete_tag(self, account_id: str, alert_id: str, tag_id: str) -> bool
Delete a tag.
Returns: True if deletion was successful
Share Methods
get_shares
def get_shares(self, account_id: str, alert_id: str) -> SharesResponse
Fetch all shares for an alert.
Returns: SharesResponse containing list of shares
get_share
def get_share(self, account_id: str, alert_id: str, share_id: str) -> Share
Fetch a single share by ID.
Returns: Share object
create_share
def create_share(
self,
account_id: str,
alert_id: str,
request: CreateShareRequest,
) -> Share
Create a new share for an alert.
Returns: Created Share object
update_share
def update_share(
self,
account_id: str,
alert_id: str,
share_id: str,
request: UpdateShareRequest,
) -> Share
Update an existing share.
Returns: Updated Share object
delete_share
def delete_share(self, account_id: str, alert_id: str, share_id: str) -> bool
Delete a share.
Returns: True if deletion was successful
Preferences Methods
get_preferences
def get_preferences(self, account_id: str, alert_id: str) -> AlertPreferences
Fetch preferences for an alert.
Returns: AlertPreferences object
update_preferences
def update_preferences(
self,
account_id: str,
alert_id: str,
request: UpdatePreferencesRequest,
) -> AlertPreferences
Update preferences for an alert.
Returns: Updated AlertPreferences object
Authors Methods
get_authors
def get_authors(
self,
account_id: str,
alert_id: str,
*,
limit: int = 100,
sort_by: str | None = None,
) -> AuthorsResponse
Fetch authors/influencers for an alert.
Returns: AuthorsResponse containing list of authors
Statistics Methods
get_stats
def get_stats(
self,
account_id: str,
alert_id: str | None = None,
*,
from_date: datetime | str | None = None,
to_date: datetime | str | None = None,
period: StatsPeriod = StatsPeriod.DAY,
) -> StatsResponse
Fetch statistics for an account or alert.
Returns: StatsResponse containing statistics data
Context Manager
close
Close the underlying HTTP client.
Context Manager Support
The MentionClient supports the context manager protocol for automatic resource cleanup:
with MentionClient(access_token="token") as client:
data = client.get_app_data()
# Client is automatically closed when exiting the context
Usage Examples
Basic Usage
from mention import MentionClient
client = MentionClient(access_token="your-token")
alerts = client.get_alerts("account-id")
for alert in alerts.alerts:
print(alert.name)
Using Configuration
from mention import MentionClient, MentionConfig
config = MentionConfig.from_env()
client = MentionClient.from_config(config)
As Context Manager
with MentionClient(access_token="token") as client:
data = client.get_app_data()