surveydata.dynamodbstorage module
Support for AWS DynamoDB survey data storage.
- class surveydata.dynamodbstorage.DynamoDBStorage(aws_region: str, table_name: str, id_field_name: str, partition_key_name: str = '', partition_key_value: str = '', aws_access_key_id: Optional[str] = None, aws_secret_access_key: Optional[str] = None, aws_session_token: Optional[str] = None)
Bases:
StorageSystem
AWS DynamoDB survey data storage implementation.
- __init__(aws_region: str, table_name: str, id_field_name: str, partition_key_name: str = '', partition_key_value: str = '', aws_access_key_id: Optional[str] = None, aws_secret_access_key: Optional[str] = None, aws_session_token: Optional[str] = None)
Initialize DynamoDB storage for survey data.
- Parameters
aws_region (str) – AWS region to use
table_name (str) – DynamoDB table name (must already exist)
id_field_name (str) – Field name for unique submission ID (e.g., “KEY”)
partition_key_name (str) – Partition key name for optional fixed partition (e.g., “FormID”)
partition_key_value (str) – Partition value for optional fixed partition (e.g., form ID)
aws_access_key_id (str) – AWS access key ID; if None, will use local config file and/or environment vars
aws_secret_access_key (str) – AWS access key secret; if None, will use local config file and/or environment vars
aws_session_token (str) – AWS session token to use, only if using temporary credentials
- The DynamoDB table should already exist with the primary key configured in one of two ways:
a fixed partition key with the name passed as partition_key_name, and the sort key with the name passed as id_field_name; or
a partition key with the name passed as id_field_name (and no sort key).
- attachments_supported() bool
Query whether storage system supports attachments.
- Returns
True if attachments supported, otherwise False
- Return type
bool
- get_attachment(attachment_location: str = '', submission_id: str = '', attachment_name: str = '') BinaryIO
Get submission attachment from storage.
- Parameters
attachment_location (str) – Attachment location string (as returned when attachment stored)
submission_id (str) – Unique submission ID (in lieu of attachment_location)
attachment_name (str) – Attachment filename (in lieu of attachment_location)
- Returns
Attachment as file-like object (though, note: it doesn’t support seeking)
- Return type
BinaryIO
Must pass either attachment_location or both submission_id and attachment_name.
- get_metadata(metadata_id: str) str
Get metadata string from storage.
- Parameters
metadata_id (str) – Unique metadata ID (should begin and end with __ and not conflict with any submission ID)
- Returns
Metadata string from storage, or empty string if no such metadata exists
- Return type
str
- get_metadata_binary(metadata_id: str) bytes
Get metadata bytes from storage.
- Parameters
metadata_id (str) – Unique metadata ID (should not conflict with any submission ID)
- Returns
Metadata bytes from storage, or empty bytes array if no such metadata exists
- Return type
bytes
- get_submission(submission_id: str) dict
Get submission data from storage.
- Parameters
submission_id (str) – Unique submission ID
- Returns
Submission data (or empty dictionary if submission not found)
- Return type
dict
- list_attachments(submission_id: str = '') list
List all attachments currently in storage.
- Parameters
submission_id (str) – Optional submission ID, to list only attachments for specific submission
- Returns
List of attachments, each as dict with name, submission_id, and location_string
- Return type
list
- list_submissions() list
List all submissions currently in storage.
- Returns
List of submission IDs
- Return type
list
- query_attachment(attachment_location: str = '', submission_id: str = '', attachment_name: str = '') bool
Query whether specific submission attachment exists in storage.
- Parameters
attachment_location (str) – Attachment location string (as returned when attachment stored)
submission_id (str) – Unique submission ID (in lieu of attachment_location)
attachment_name (str) – Attachment filename (in lieu of attachment_location)
- Returns
True if submission exists in storage; otherwise False
- Return type
bool
Must pass either attachment_location or both submission_id and attachment_name.
- query_submission(submission_id: str) bool
Query whether specific submission exists in storage.
- Parameters
submission_id (str) – Unique submission ID
- Returns
True if submission exists in storage; otherwise False
- Return type
bool
- store_attachment(submission_id: str, attachment_name: str, attachment_data: BinaryIO) str
Store submission attachment in storage.
- Parameters
submission_id (str) – Unique submission ID
attachment_name (str) – Attachment filename
attachment_data (BinaryIO) – File-type object containing the attachment data
- Returns
Location string for stored attachment
- Return type
str
- store_metadata(metadata_id: str, metadata: str)
Store metadata string in storage.
- Parameters
metadata_id (str) – Unique metadata ID (should begin and end with __ and not conflict with any submission ID)
metadata (str) – Metadata string to store
- store_metadata_binary(metadata_id: str, metadata: bytes)
Store metadata bytes in storage.
- Parameters
metadata_id (str) – Unique metadata ID (should begin and end with __ and not conflict with any submission ID)
metadata (bytes) – Metadata bytes to store
- store_submission(submission_id: str, submission_data: dict)
Store submission data in storage.
- Parameters
submission_id (str) – Unique submission ID
submission_data (dict) – Submission data to store
- submission_primary_key(submission_id: str) dict
Get submission primary key for specific submission.
- Parameters
submission_id (str) – Unique submission ID
- Returns
Primary key for submission
- Return type
dict