sciabarracom / nimbella-sdk-python

Nimbella SDK for Python serverless functions.

Home Page:https://nimbella.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nimbella SDK for Python

A Python package to interact with nimbella.com services.

Installation

pip install nimbella

Usage

This SDK provides access to the following cloud services on Nimbella.com:

Redis

The nimbella.redis() method returns a pre-configured Redis client for use in your application. See the Redis client library documentation for the methods provided.

import nimbella

# Redis
redis = nimbella.redis()
redis.set("key", "value")
value = redis.get("key")

Object Storage (GCP & S3)

The nimbella.storage() method returns a pre-configured object storage client. This client exposes a high-level storage API (details below) - which hides the underlying storage provider implementation. The storage client is automatically configured to use the storage service for the cloud it is running on - which is GCS on GCP and S3 on AWS.

import nimbella

# Storage
bucket = nimbella.storage()
filename = "test.txt"
file = bucket.file(filename)
file.save('Expected %s contents' % filename, 'text/plain')

The nimbella.storage() constructor takes a single parameter web to determine whether the storage bucket is for a website (nimbella.storage(web=True)) or files (nimbella.storage()). Website buckets can be used for store web content (e.g. HTML & JS files) to host static websites.

Object Storage API

# Storage API
class StorageProvider(web=False):    
    # External bucket URL
    @property
    def url() -> Union[str, None]:

    # Configure website for web storage buckets
    def setWebsite(mainPageSuffix, notFoundPage):

    # Remove all files from the bucket (using optional prefix)    
    def deleteFiles(force, prefix):

    # Upload new file from path to bucket destination.
    def upload(path, destination, contentType, cacheControl):

    # Return storage file instance from bucket
    def file(destination) -> StorageFile:

    # Return all storage files (with optional prefix) instance from bucket
    def getFiles(prefix) -> list:
      
# Storage File Class
class StorageFile():
    # Name of the bucket file
    @property
    def name() -> str:

    # key/value pairs for provider-specific object metadata
    @property
    def metadata() -> dict:

    # does file exist?
    def exists() -> bool:

    # delete file from bucket
    def delete() -> None:

    # update file contents from string or bytes with content-type
    def save(data: Union[str, bytes], contentType: str) -> None:

    # return file contents as bytes
    def download() -> bytes:

    # return pre-signed url from file for external access
    def signed_url(version: str, action: str, expires: int, contentType: str) -> str:

Support

We're always happy to help you with any issues you encounter. You may want to join our Slack community to engage with us for a more rapid response.

License

Apache-2.0. See LICENSE to learn more.

About

Nimbella SDK for Python serverless functions.

https://nimbella.com

License:Apache License 2.0


Languages

Language:Python 100.0%