storage.blob

Module Contents

Classes

PemKind

Tracks the response of pem.readPemBlocksFromFile(key, *args)>

_SignatureMethod

Indicates where the url signing will be done through Google's

Blob

Attributes

HOST

PKCS1_MARKER

PKCS8_MARKER

PKCS8_SPEC

storage.blob.HOST = 'storage.googleapis.com'
storage.blob.PKCS1_MARKER = ('-----BEGIN RSA PRIVATE KEY-----', '-----END RSA PRIVATE KEY-----')
storage.blob.PKCS8_MARKER = ('-----BEGIN PRIVATE KEY-----', '-----END PRIVATE KEY-----')
storage.blob.PKCS8_SPEC
class storage.blob.PemKind(*args, **kwds)

Bases: enum.Enum

Tracks the response of pem.readPemBlocksFromFile(key, *args)>

Note that the specified method returns (marker_id, key_bytes), where marker_id is the integer index of the matching arg (or -1 if no match was found.

For example:

(marker_id, _) = pem.readPemBlocksFromFile(key, PKCS1_MARKER,
                                           PCKS8_MARKER)
if marker_id == -1:
    # "key" did not match either type or was invalid
if marker_id == 0:
    # "key" matched the zeroth provided marker arg, eg. PKCS1_MARKER
if marker_id == 1:
    # "key" matched the zeroth provided marker arg, eg. PKCS8_MARKER
INVALID
PKCS1 = 0
PKCS8 = 1
class storage.blob._SignatureMethod(*args, **kwds)

Bases: enum.Enum

Indicates where the url signing will be done through Google’s IAM API or through local signing with a PEM file, which is faster but requires that the provided token contains client_email and private_key data

PEM = 0
IAM_API = 1
class storage.blob.Blob(bucket, name, metadata)
Parameters:
property chunk_size: int
Return type:

int

async download(timeout=DEFAULT_TIMEOUT, session=None, auto_decompress=True)
Parameters:
  • timeout (int) –

  • session (Optional[requests.Session]) –

  • auto_decompress (bool) –

Return type:

Any

async upload(data, content_type=None, session=None)
Parameters:
  • data (Any) –

  • content_type (Optional[str]) –

  • session (Optional[requests.Session]) –

Return type:

Dict[str, Any]

async get_signed_url(expiration, headers=None, query_params=None, http_method='GET', iam_client=None, service_account_email=None, token=None, session=None)

Create a temporary access URL for Storage Blob accessible by anyone with the link.

Adapted from Google Documentation: https://cloud.google.com/storage/docs/access-control/signing-urls-manually#python-sample

Parameters:
  • expiration (int) –

  • headers (Optional[Dict[str, str]]) –

  • query_params (Optional[Dict[str, Any]]) –

  • http_method (str) –

  • iam_client (Optional[gcloud.aio.auth.IamClient]) –

  • service_account_email (Optional[str]) –

  • token (Optional[gcloud.aio.auth.Token]) –

  • session (Optional[requests.Session]) –

Return type:

str

static get_pem_signature(str_to_sign, private_key)
Parameters:
  • str_to_sign (str) –

  • private_key (str) –

Return type:

bytes

async static get_iam_api_signature(str_to_sign, iam_client, service_account_email, session)
Parameters:
  • str_to_sign (str) –

  • iam_client (gcloud.aio.auth.IamClient) –

  • service_account_email (Optional[str]) –

  • session (Optional[requests.Session]) –

Return type:

bytes