Skip to content

Opinionated Google Cloud Run Wrapper to run python services

Notifications You must be signed in to change notification settings

sbusso/flask-gcrun

Repository files navigation

Flask Google Run

This module provides the base elements to create a service with Flask and run on Google Run, it also includes a client to publish messages to a pubsub topic.

Usage

The minimum code to run a service:

from flaskgcrun import FlaskGCRun

class Service(FlaskGCRun):
    def handler(self, data):
        return data

app = Service(__name__)

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', 
            port=int(os.environ.get('PORT', 8080)))

handler is the required method to process data.

FlaskGCRun class provides utilities:

  • store
  • logging
  • pub/sub publisher

it's automatically handle decoding of messages and log excecution time.

The service will forward data returned by handler to downstream queues, if data is not None and if a list of downstream channels is provided either in the class constructor or with the DOWNSTREAM_CHANNELS environment variable.

Store utility

Store utility provides 3 methods to upload or retireive files:

  • upload_string
  • upload_blob
  • list_blobs

TODO

  • to disable pubsub
  • to return always OK
  • use ENV for everything + default

About

Opinionated Google Cloud Run Wrapper to run python services

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages