emailnator.sync package¶
Submodules¶
emailnator.sync.email_generator module¶
Synchronous interface for the Emailnator API wrapper.
This module defines the EmailGenerator class, which provides a blocking (synchronous) wrapper around the asynchronous AsyncEmailGenerator. It allows generating temporary email addresses and retrieving their messages without requiring an asynchronous runtime.
- Typical Usage example:
from emailnator.sync.email_generator import EmailGenerator gen = EmailGenerator() email = gen.generate_email() print(email) messages = gen.get_messages(email) print(messages) bulk = gen.generate_bulk_emails(“200”) print(bulk)
- class emailnator.sync.email_generator.EmailGenerator¶
Bases:
objectSynchronous wrapper for generating temporary email addresses and retrieving their associated messages.
This class provides a blocking interface to the asynchronous AsyncEmailGenerator, making it convenient to use in codebases that are not async-aware.
- _loop¶
Event loop used to execute asynchronous operations in a synchronous context.
- Type:
asyncio.AbstractEventLoop
- _async¶
Internal asynchronous generator instance responsible for performing the actual operations.
- Type:
- generate_bulk_emails(emails_number='100')¶
Generate multiple email addresses synchronously.
This method runs the asynchronous generate_bulk_emails coroutine from AsyncEmailGenerator in a blocking manner using the event loop.
- Parameters:
emails_number (Literal["100", "200", "300"], optional) – The number of email addresses to generate. Must be one of: “100”, “200”, or “300”. Defaults to “100”.
- Returns:
A list of newly generated email addresses.
- Return type:
list[str]
- Raises:
ValueError – If emails_number is invalid.
RuntimeError – If the async generator returns invalid or empty data.
- generate_email()¶
Generate a new email address synchronously.
This method runs the asynchronous generate_email coroutine from AsyncEmailGenerator in a blocking manner using the event loop.
- Returns:
A newly generated email address.
- Return type:
str
- Raises:
RuntimeError – If the underlying async generator fails to return
a valid email address. –
- get_message(email, message_id)¶
Retrieve a specific message for the given email synchronously.
This method runs the asynchronous get_message coroutine in the current event loop and returns its result as a string (typically the message HTML or raw text).
- Parameters:
email (str) – The email address from which to retrieve the message.
message_id (str) – The unique identifier of the message to fetch.
- Returns:
The message content, usually in HTML or plain text format.
- Return type:
str
- Raises:
ValueError – If email or message_id are invalid or empty.
RuntimeError – If the retrieved message is invalid or empty.
- get_message_from_sender(sender, email)¶
Retrieves the message content from a specific sender for the given email address.
- Parameters:
sender (str) – The email address or name of the sender. Must be a non-empty string.
email (str) – The target email address to fetch the message for. Must be a valid email format.
- Returns:
The message content if found, otherwise None.
- Return type:
str | None
- Raises:
ValueError – If sender or email are invalid.
RuntimeError – If the asynchronous client is not initialized or an error occurs while fetching the message.
- get_messages(email)¶
Retrieve messages for a given email address synchronously.
This method executes the asynchronous get_messages coroutine from AsyncEmailGenerator in a blocking manner using the event loop.
- Parameters:
email (str) – The email address to fetch messages for.
- Returns:
- A list of message objects, where each message is
represented as a dictionary containing fields such as ‘messageID’, ‘from’, ‘subject’, and ‘time’.
- Return type:
list[dict[str, str]]
- Raises:
ValueError – If the provided email is invalid.
RuntimeError – If message retrieval fails or the response is invalid.
- parse_message_from_sender(messages, sender)¶
Parses a list of messages and retrieves the content of the message sent by a specific sender.
- Parameters:
messages (list[dict[str, str]]) – A list of messages, where each message is a dictionary containing keys like ‘from’, ‘subject’, ‘time’, etc.
sender (str) – The email address or name of the sender to search for. Must be a non-empty string.
- Returns:
The message content if a message from the specified sender is found, otherwise None.
- Return type:
str | None
- Raises:
ValueError – If messages is empty or not a list of dictionaries, or if sender is invalid.
RuntimeError – If the asynchronous client is not initialized or an error occurs during parsing.
Module contents¶
- class emailnator.sync.EmailGenerator¶
Bases:
objectSynchronous wrapper for generating temporary email addresses and retrieving their associated messages.
This class provides a blocking interface to the asynchronous AsyncEmailGenerator, making it convenient to use in codebases that are not async-aware.
- _loop¶
Event loop used to execute asynchronous operations in a synchronous context.
- Type:
asyncio.AbstractEventLoop
- _async¶
Internal asynchronous generator instance responsible for performing the actual operations.
- Type:
- generate_bulk_emails(emails_number='100')¶
Generate multiple email addresses synchronously.
This method runs the asynchronous generate_bulk_emails coroutine from AsyncEmailGenerator in a blocking manner using the event loop.
- Parameters:
emails_number (Literal["100", "200", "300"], optional) – The number of email addresses to generate. Must be one of: “100”, “200”, or “300”. Defaults to “100”.
- Returns:
A list of newly generated email addresses.
- Return type:
list[str]
- Raises:
ValueError – If emails_number is invalid.
RuntimeError – If the async generator returns invalid or empty data.
- generate_email()¶
Generate a new email address synchronously.
This method runs the asynchronous generate_email coroutine from AsyncEmailGenerator in a blocking manner using the event loop.
- Returns:
A newly generated email address.
- Return type:
str
- Raises:
RuntimeError – If the underlying async generator fails to return
a valid email address. –
- get_message(email, message_id)¶
Retrieve a specific message for the given email synchronously.
This method runs the asynchronous get_message coroutine in the current event loop and returns its result as a string (typically the message HTML or raw text).
- Parameters:
email (str) – The email address from which to retrieve the message.
message_id (str) – The unique identifier of the message to fetch.
- Returns:
The message content, usually in HTML or plain text format.
- Return type:
str
- Raises:
ValueError – If email or message_id are invalid or empty.
RuntimeError – If the retrieved message is invalid or empty.
- get_message_from_sender(sender, email)¶
Retrieves the message content from a specific sender for the given email address.
- Parameters:
sender (str) – The email address or name of the sender. Must be a non-empty string.
email (str) – The target email address to fetch the message for. Must be a valid email format.
- Returns:
The message content if found, otherwise None.
- Return type:
str | None
- Raises:
ValueError – If sender or email are invalid.
RuntimeError – If the asynchronous client is not initialized or an error occurs while fetching the message.
- get_messages(email)¶
Retrieve messages for a given email address synchronously.
This method executes the asynchronous get_messages coroutine from AsyncEmailGenerator in a blocking manner using the event loop.
- Parameters:
email (str) – The email address to fetch messages for.
- Returns:
- A list of message objects, where each message is
represented as a dictionary containing fields such as ‘messageID’, ‘from’, ‘subject’, and ‘time’.
- Return type:
list[dict[str, str]]
- Raises:
ValueError – If the provided email is invalid.
RuntimeError – If message retrieval fails or the response is invalid.
- parse_message_from_sender(messages, sender)¶
Parses a list of messages and retrieves the content of the message sent by a specific sender.
- Parameters:
messages (list[dict[str, str]]) – A list of messages, where each message is a dictionary containing keys like ‘from’, ‘subject’, ‘time’, etc.
sender (str) – The email address or name of the sender to search for. Must be a non-empty string.
- Returns:
The message content if a message from the specified sender is found, otherwise None.
- Return type:
str | None
- Raises:
ValueError – If messages is empty or not a list of dictionaries, or if sender is invalid.
RuntimeError – If the asynchronous client is not initialized or an error occurs during parsing.