llama.com.s3 package

Tools for uploading to/downloading from AWS S3 APIs (including DigitalOcean’s S3-interface clone for DigitalOcean Spaces).

If using DigitalOcean spaces, for example, You will need to configure an access token for DigitalOcean spaces and set the key and secret as environmental variables DIGITALOCEAN_SPACES_KEY and DIGITALOCEAN_SPACES_SECRET, respectively (this should work for AWS S3 as well, though of course the link for generating the tokens will be different).

llama.com.s3.get_client(region_name='nyc3', endpoint_url='https://llama.nyc3.digitaloceanspaces.com', aws_access_key_id=None, aws_secret_access_key=None, **kwargs)

Get a boto3 client connecting to the given DigitalOcean Spaces/AWS S3 region and endpoint.

Parameters:
  • region_name (str, optional) – The server region. This is the geographical region in which your servers reside. Check your DigitalOcean or AWS account to find this.
  • endpoint_url (str, optional) – The endpoint URL for your specific Spaces/S3 instance. Again, check your account to find this.
  • aws_access_key_id (str, optional) – Your access key, generated on your account website. You can only view this when you create it, so if you lost track of an old version, just delete it and make new credentials. For DigitalOcean, you can do this here. If not provided, will default to the value of the DIGITALOCEAN_SPACES_KEY environmental variable, or None if it doesn’t exist (which will result in an authentication error).
  • aws_secret_access_key (str, optional) – The secret corresponding to your aws_access_key_id. Create this at the same time you create your aws_access_key_id (see notes above). If not provided, will default to the value of the DIGITALOCEAN_SPACES_SECRET environmental variable, or None if it doesn’t exist (which will result in an authentication error).
  • **kwargs – Extra keyword arguments to pass to boto3.session.Session.client.
Returns:

client – A client for interacting with the specified Spaces/S3 instance using the specified credentials. You can use this client to interact with the S3 API for file storage, retrieval, permissions modifications, etc. See boto3.session.Session.client for more details on the interface.

Return type:

boto3.session.Session.Client

llama.com.s3.upload_file(filename, key, bucket='llama', public=False, **kwargs)

Upload file to a DigitalOcean Spaces/AWS S3 bucket.

Parameters:
  • filename (str) – Local path to the file you wish to upload.
  • key (str) – The object key, analogous to a remote file path; the remote file will be available at /<bucket>/<key>. You can put slashes in the key, which will be treated as subdirectories on the DigitalOcean web file browser.
  • bucket (str, optional) – Name of the target bucket. For DigitalOcean Spaces, this is the naem of the directory in the root Spaces directory, e.g. bucket=llama will put everything under /llama/ remotely.
  • public (bool, optional) – is True, the file will be publicly-accessible.
  • **kwargs – Keyword arguments will be passed to get_client to initialize it, overriding its defaults. Use this to specify access credentials and upload target.
Returns:

url – If public is True, the remote URL at which the resource can be publicly accessed; otherwise, None.

Return type:

str or None