Skip to main content

Storage clients for different cloud providers

Project description

cloud-storage-clients

cloud-storage-clients is a Python library for having an unique interface over different cloud storage providers. It can be used to connect a python client to providers. This package is maintained by Picsellia.

This has been conceived for you to override classes. For example, override VaultRepository if you retrieve credentials in another way. You can create or override factories of client to add some additional parameters.

Installation

Add it to your poetry environment

poetry add cloud-storage-clients

Or use the package manager pip to install it.

pip install cloud-storage-clients

Usage

Basic client usage to retrieve a specific object name from an S3 bucket

from cloud_storage_clients.connector import Connector
from cloud_storage_clients.s3.client import S3Client

connector = Connector(client_type="s3", bucket="my-bucket")

client = S3Client(connector, {"access_key_id": "access-key", "secret_access_key": "secret-access-key" })

with open("/path/object-name.jpg", "wb") as file:
    response = client.get("object-name.jpg")
    file.write(response.content)

Pool Instanciation

from cloud_storage_clients.connector import Connector
from cloud_storage_clients.s3.factory import S3ClientFactory
from cloud_storage_clients.repositories.vault_adapter import DefaultVaultAdapter, TokenCredentials
from cloud_storage_clients.repositories.vault import VaultCredentialRepository
from cloud_storage_clients.pool import ClientPool

# Login to your Vault by creating a VaultAdapter and its repository
vault_adapter = DefaultVaultAdapter(
    url="http://localhost:7200",
    credentials=TokenCredentials(token="vault_token", unseal_key="unseal_key")
)
repository = VaultCredentialRepository(adapter=vault_adapter)

# Instantiate a ClientPool and add an S3ClientFactory for minio client_type
pool = ClientPool(default_repository=repository)
pool.register_factory("minio", factory=S3ClientFactory())

# Create a connector object
connector = Connector(client_type="minio", bucket="my-bucket")

# Use pool to instantiate a client that have its credentials in Vault
client = pool.get_client(connector)

# Generate a presigned url that an user without access to your bucket can download
presigned_url = client.get_download_url("object-name", 3600).url

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloud_storage_clients-0.2.0.tar.gz (12.7 kB view hashes)

Uploaded Source

Built Distribution

cloud_storage_clients-0.2.0-py3-none-any.whl (19.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page