Amazon provides a Python SDK called Boto3 for interacting with AWS services, including S3, where the DataCite Monthly Data File is stored.
Boto3 provides different interfaces, high-level Resource objects which provide an object-oriented API, and Client
objects which provide a lower-level API access pattern.
Examples for both are provided here, alongside utility files that can help automate the provision of the necessary AWS credentials for accessing the DataCite Monthly Data File.
NB: This example code is provided "as-is" and is offered without any guarantee. It is a minimal implementation and does not contain robust error handling or logging.
The utility function for requesting AWS credentials from the DataCite REST API requires the requests package.
The utility functions for interacting with AWS require the boto3 and botocore packages.
get_datafile_credentials.py provides a function that takes your DataCite credentials and returns a tuple containing the three credentials required to access the S3 bucket: the Access Key, the Secret Key, and the Session Token.
This file, or the function within it, can be added directly to your project to provide easy retrieval of the credentials , which you can then integrate into your Boto3 usage.
get_aws_objects.py provides functions to return configured Boto3 objects that are already set up with the required AWS credentials. The available objects are:
- an instantiated Boto3 Session, not linked to any specific AWS service
- an instantiated S3 Bucket Resource, providing an object-oriented interface to the Monthly Data File bucket
- an instantiated S3 Client, providing low-level access to the S3 API
Which of these different objects to use depends on your intended use case and any other AWS usage already existing in your codebase. example_with_resource.py and example_with_client.py demonstrate potential usages of the latter two object types, intended to be used as a rough example of implementation patterns.
DataCite Monthly Data File readme
DataCite Monthly Data File structure
Main AWS Boto3 documentation
Boto3: Downloading files from S3
Boto3: List objects in a Bucket