API Reference¶
Iniesta¶
iniesta.app
¶
-
class
_Iniesta
[source]¶ Initializes Iniesta with different methods. You should probably not use this. You should import just Iniesta.
from iniesta import Iniesta
-
property
initialization_type
¶
-
check_global_arn
(settings_object)[source]¶ - Parameters
settings_object (sanic.config.Config) –
- Return type
None
-
load_config
(settings_object)[source]¶ - Parameters
settings_object (sanic.config.Config) –
- Return type
None
-
unload_config
(settings_object)[source]¶ - Parameters
settings_object (sanic.config.Config) –
- Return type
None
-
property
iniesta.choices
¶
iniesta.messages
¶
-
class
MessageAttributes
(*args, **kwargs)[source]¶ Base class for
SQSMessage
andSNSMessage
because both messages uses message attributes.-
add_event
(value, *, raw=False)[source]¶ Adds the event to the message to be sent.
- Parameters
value (str) –
raw (bool) –
-
add_attribute
(attribute_name, attribute_value)[source]¶ Adds an attribute depending on value type.
- Raises
ValueError – If the value is not a supported type.
- Parameters
attribute_name (str) –
attribute_value (Any) –
- Return type
None
-
add_string_attribute
(attribute_name, attribute_value)[source]¶ Adds a string attribute to the message.
- Raises
ValueError – If the value is not a string.
- Parameters
attribute_name (str) –
attribute_value (str) –
- Return type
None
-
add_number_attribute
(attribute_name, attribute_value)[source]¶ Adds a number attribute to the message.
- Raises
ValueError – If the value is not an int or a float.
- Parameters
attribute_name (str) –
attribute_value (Union[int, float]) –
- Return type
None
-
SNS¶
iniesta.sns.client
¶
-
class
SNSClient
(topic_arn=None, *, region_name=None, endpoint_url=None)[source]¶ Initialize client with topic arn and endpoint url.
- Parameters
topic_arn – If you would like to initialize this client with a different topic. Defaults to
INIESTA_SNS_PRODUCER_GLOBAL_TOPIC_ARN
if not passed.region_name – Takes priority or defaults to
INIESTA_SNS_REGION_NAME
settings.endpoint_url – Takes priority or defaults to
INIESTA_SNS_ENDPOINT_URL
settings.
-
async classmethod
initialize
(*, topic_arn=None, region_name=None, endpoint_url=None)[source]¶ Class method to initialize the SNS Client and confirm the topic exists. We needed to do this because of asyncio functionality
- Parameters
topic_arn (Optional[str]) – If you would like to initialize this client with a different topic. Defaults to
INIESTA_SNS_PRODUCER_GLOBAL_TOPIC_ARN
if not passed.region_name (Optional[str]) – Takes priority or defaults to
BotoSession.aws.default_region
settings.endpoint_url (Optional[str]) – Takes priority or defaults to
INIESTA_SNS_ENDPOINT_URL
settings.
- Returns
An initialized instance of
cls
(SQSClient
).- Return type
SNSClient
-
list_subscriptions_by_topic
()[source]¶ The list of subscriptions attached to the current topic.
The subscription object is in the following format.
{ "SubscriptionArn": "string", "Owner": "string", "Protocol": "string", "Endpoint": "string", "TopicArn": "string" }
- Returns
list of subscriptions
- Return type
Iterator
-
async
get_subscription_attributes
(subscription_arn)[source]¶ Retrieves the attributes of the subscription from AWS.
Refer to https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#SNS.Client.get_subscription_attributes for more information.
- Parameters
subscription_arn (str) –
- Return type
dict
-
create_message
(*, event, message, version=1, raw_event=False, **message_attributes)[source]¶ A helper method to create a SNSMessage object.
- Parameters
event (str) – The event to publish (will be used to filter).
message (Any) – The message body to send with event.
version (int) – A version to publish. Defaults to 1.
message_attributes – Any attributes to include in the message. Refer to https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#SNS.Client.publish.
raw_event (bool) –
- Return type
iniesta.sns.message.SNSMessage
-
publish_event
(*, event, version=1, **message_attributes)[source]¶ Used for decorating a view function or view class method. This publishes the message with the event specified with the return of the decorated function or method. This only triggers if the response is with a status code of less than 300.
- Parameters
event (str) – Event value to be published.
version (int) – The version.
message_attributes – Any extra message_attributes to be attached to the event.
- Return type
Callable
iniesta.sns.message
¶
-
class
SNSMessage
(message='')[source]¶ A SNS Message object that will be serialized to send.
-
property
event
¶ The event this message is attached to. Returns
None
if event is not set.
-
property
message
¶ The message body.
-
property
size
¶ The size of this message.
-
property
subject
¶ Subject to be used when sending to email subscription.
-
property
message_structure
¶ The message structure.
-
async
publish
()[source]¶ Serializes this message and publishes this message to SNS.
- Returns
The response of the publish request to SNS.
- Return type
dict
-
classmethod
create_message
(client, *, event, message, version=1, raw_event=False, **message_attributes)[source]¶ A factory method to initialize an event message.
- Parameters
client (
SNSClient
) – The initialized SNSClientevent (str) – The event this message will publish.
message (Any) – The message body to publish.
version (int) – Version of the message.
raw_event (bool) – If the event should be passed in as itself.
message_attributes – Any message attributes
- Returns
Instantiated instance of self.
- Return type
SNSMessage
-
property
SQS¶
iniesta.sqs.client
¶
-
class
SQSClient
(*, queue_name=None, endpoint_url=None, region_name=None, retry_count=None, lock_timeout=None)[source]¶ -
async classmethod
initialize
(*, queue_name=None, endpoint_url=None, region_name=None)[source]¶ The initialization classmethod that should be first run before any subsequent SQSClient initializations.
- Parameters
queue_name (Optional[str]) – queue_name if want to initialize client with a different queue
endpoint_url (Optional[str]) –
region_name (Optional[str]) –
- Return type
SQSClient
-
async
confirm_subscription
(topic_arn)[source]¶ Confirms the correct subscriptions are in place in AWS SNS
- Parameters
topic_arn (str) – Topic to check subscriptions for.
- Raises
EnvironmentError – If the the queue is not found.
AssertionError – If the registered filters on AWS do not match current config filters.
- Return type
None
-
async
confirm_permission
()[source]¶ Confirms correct permissions are in place.
- Raises
ImproperlyConfigured – If the permissions were not found.
AssertionError – If the permissions are not correctly configured on AWS.
- Return type
None
-
async
handle_message
(message)[source]¶ Method that hold logic to handle a certain type of mesage
- Parameters
message (iniesta.sqs.message.SQSMessage) – Message to handle
- Raises
LockError – If lock could not be acquired for the message
Exception – General exception handler attaches the message and message handler
- Returns
Returns a tuple of the message and result of the handler
- Return type
tuple
-
handle_error
(exc)[source]¶ If an exception occured while handling the message, log the error.
- Parameters
exc (Exception) –
- Return type
None
-
async
handle_success
(client, message)[source]¶ Success handler for a message. Deletes the message from SQS.
- Parameters
client – aws sqs client
message (iniesta.sqs.message.SQSMessage) –
- Returns
Returns the response of the delete_message request.
- Return type
dict
-
classmethod
handler
(event=None)[source]¶ Decorator for attaching a message handler for an event or if None, a default handler.
- Parameters
event (Union[Callable, str, list, tuple]) –
- Return type
Callable
-
async classmethod
iniesta.sqs.message
¶
-
class
SQSMessage
(client, message)[source]¶ The Message object that will be used to send a message to SQS.
- Parameters
client (
SQSClient
) – The client that will be sending this message.message – The message to send. A json serializable value.
-
classmethod
from_sqs
(client, message)[source]¶ A helper method that unpacks everything from receive_message
- Parameters
client (
SQSClient
) – SQSClient instance from which the message came frommessage (Any) – The message from receive_message when polling SQS.
- Returns
A initialized SQSMessage instance.
- Return type
SQSMessage
-
property
delay_seconds
¶ The length of time in seconds to delay the message.
-
property
raw_body
¶ The raw body of the message.
-
property
body
¶ The body as a python object.
-
property
event
¶ The event that this message was received as.
-
property
message_attributes
¶ Any message attributes attached to this body. Refer to https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes