bus-sdk-python
This library provides a Python SDK for the eLife Sciences Bus.
Dependencies
- Python >=3.5
Installation
pip install elife_bus_sdk
AWS Credentials
To use any of the AWS provided services through this library, you will need to provide credentials in a way that is supported here.
Publisher
Current supported:
Configuration:
from elife_bus_sdk import get_publisher
config = {
'region': 'us-east-2',
'subscriber': '00000000000',
'name': 'profile',
'env': 'dev'
}
publisher = get_publisher(config=config, pub_type='sns')
print(publisher.arn)
>>> 'arn:aws:sns:us-east-2:00000000000:profile--dev'
Publish:
from elife_bus_sdk.events import Event
publisher.publish(Event(foo='bar', some='fields'))
Queue
Current supported:
Configuration:
from elife_bus_sdk import get_queue
config = {
'queue_name': 'some_queue',
}
message_queue = get_queue(config=config, pub_type='sqs')
Poll for messages:
for msg in message_queue.poll():
print(msg)
Check if a queue is polling:
message_queue.is_polling()
Stop a queue from polling (normally running in another thread):
message_queue.stop_polling()
Receive message(s):
msg = message_queue.dequeue()
Send message:
message_queue.enqueue('test message')
Local Testing
To test the aws
services locally you can setup goaws and pass the local endpoint_url
value to your configuration.
Example:
from elife_bus_sdk import get_queue
dev_config = {
'endpoint_url': 'http://localhost:4100',
'queue_name': 'test1',
}
message_queue = get_queue(config=dev_config, q_type='sqs')
Tests
You can run the full automated test suite from the base folder with:
$ ./project_tests.sh