Package: nimbella
Nimbella SDK for PythonA Python package to interact withnimbella.comservices.Installationpip install nimbellaUsageThis SDK provides access to the following cloud services on Nimbella.com:RedisObject StorageRedisThenimbella.redis()method returns a pre-configured Redis client for use in your application. See theRedis client library documentationfor the methods provided.importnimbella# Redisredis=nimbella.redis()redis.set("key","value")value=redis.get("key")Object Storage (GCP & S3)Thenimbella.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 isGCSon GCP andS3 on AWS.importnimbella# Storagebucket=nimbella.storage()filename="test.txt"file=bucket.file(filename)file.save('Expected%scontents'%filename,'text/plain')Thenimbella.storage()constructor takes a single parameterwebto 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 APIclassStorageProvider(web=False):# External bucket URL@propertydefurl()->Union[str,None]:# Configure website for web storage bucketsdefsetWebsite(mainPageSuffix,notFoundPage):# Remove all files from the bucket (using optional prefix)defdeleteFiles(force,prefix):# Upload new file from path to bucket destination.defupload(path,destination,contentType,cacheControl):# Return storage file instance from bucketdeffile(destination)->StorageFile:# Return all storage files (with optional prefix) instance from bucketdefgetFiles(prefix)->list:# Storage File ClassclassStorageFile():# Name of the bucket file@propertydefname()->str:# key/value pairs for provider-specific object metadata@propertydefmetadata()->dict:# does file exist?defexists()->bool:# delete file from bucketdefdelete()->None:# update file contents from string or bytes with content-typedefsave(data:Union[str,bytes],contentType:str)->None:# return file contents as bytesdefdownload()->bytes:# return pre-signed url from file for external accessdefsigned_url(version:str,action:str,expires:int,contentType:str)->str:Embedded SQL supportYou can access embedded sql with:sql = nimbella.esql()Available methods are:sql.exec(sql, *arg)Excecute ansqlstatement. The statement is either a string inSQLor an id returned bysql.prep(a prepared statement).You can also pass multiple additionalargs, for parametric statementns.It returns an array of[lastId, changedRows]Values are significant where relevant (for insert or delete, but not for create for example).Example:# single statement
res = sql.exec("create table t(i int)")
# parametric statement
res = sql.exec("insert into t(i) values(?),(?),(?)",1,2,3)
# returns [3,3]sql.map(sql, *args [,limit=<n>])Execute ansqlstatement. The statement is either a string inSQLor an id returned bysql.prep(a prepared statement).You can also pass multiple additionalargs, for parametric statementns.It returns the result of an SQL query (like aSELECT) as an an array of dictionaries. Each dictionary is a record, where the keys are the fields and the values are the field values.The optional keyword argument is the maximum number of records returned, it will limit the size of the returned array to the first<n>Examples:sql.map("select * from t")
# returns [{"i":1},{"i":2},{"i":3}]
sql.map("select * from t where i >?",1)
# returns [{"i":2},{"i":3}]
sql.map("select * from t where i >?",1,limit=1)
# returns [{"i":2}]sql.arr(sql, *args [,limit=<n>])Execute ansqlstatement. The statement is either a string inSQLor an id returned bysql.prep(a prepared statement).You can also pass multiple additionalargs, for parametric statements.It returns the result of an SQL query (like aSELECT) as an an array of arrays. Each array includes the field values of a record.The optional keyword argument is the maximum number of records returned, it will limit the size of the returned array to the first<n>Examples:sql.map("select * from t")
# returns [[1],[2],[3]]
sql.map("select * from t where i >?",1)
# returns [[2],[3]]
sql.map("select * from t where i >?",1,limit=1)
# returns [[2]]prep(sql)You can prepare statements to save time from precompiling.ins =  sql.prep("insert into t(i) values(?)")
sel = sql.prep("select * from t where i>?")The returned value is a number and can be used to execute the statement withexec,mapandarr.# executing statement
res = sql.exec(ins,1)
# executing query
m = sql.map(sel,1,limit=1)When you do not need any more you can close the statement running prep again with the returned value.# closing prepared statements
sql.prep(ins)
sql.prep(sel)Note that you can prepare up to 10000 statement at the same time without closing them, otherwise you will get an errortoo many prepared statement. In the unfortunate accident you fill the prepared statement cache, you can clear it withprep("clean_prep_cache")SupportWe're always happy to help you with any issues you encounter. You may want tojoin our Slack communityto engage with us for a more rapid response.LicenseApache-2.0. SeeLICENSEto learn more.