Skip to main content

Flask extension that ties boto3 clients and resources to the application context.

Project description

flask-botox

Flask extension that ties boto3 connectors to the application context. To be used with Python 3.7+.

Install

  • Via pip:

    $ pip install flask-botox
    
  • Locally with Poetry for development purposes:

    $ git clone https://github.com/jperras/flask-botox.git
    $ cd flask-botox
    $ poetry install
    

How-to

The main class flask_botox.Boto3 takes a Flask application as its contructor's parameter:

from flask import Flask
from flask_botox import Boto3
app = Flask(__name__)
app.config["BOTOX_SERVICES"] = ["s3", "ses", "sqs"]

botox = Boto3(app)

The application factory pattern for extensions is also valid:

from flask import Flask
from flask_botox import Boto3

botox = Boto3()

app = Flask(__name__)
app.config["BOTOX_SERVICES"] = ["s3", "ses", "sqs"]

botox.init_app(app)

Then boto3's clients and resources will be available as properties within the application context:

>>> with app.app_context():
        print(botox.clients)
        print(botox.resources)
{'s3': <botocore.client.S3 object at 0x..>}
{'s3': s3.ServiceResource()}

Configuration

Flask-botox uses several keys from a Flask configuration objects to customize its behaviour. Any of the AWS_* keys are not required; if they are not specified, then the usual boto3 configuration parameter rules will apply.

  • AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY : The AWS credentials. Note that it's not a good idea to put your secret access key in a configuration file, but it can be useful for e.g. testing purposes.
  • AWS_DEFAULT_REGION : The region, e.g. us-east-1, for the boto3 AWS services.
  • AWS_PROFILE : The AWS nanmed profile to use, if one is desired.
  • BOTOX_SERVICES : The name of the AWS resources you want to use, e.g. ['sqs', 's3', 'ses'].
  • BOTOX_OPTIONAL_PARAMS : Useful if you need to pass additional parameters to the client/resource connections, e.g. a custom endpoint_url for a particular service. The format is a dict where the top-level keys are the name of the services you're using and for each the value is a dict containing to keys args (contains the parameters as tuple) and kwargs (contains the parameters as a dict when they should be passed as keyword arguments).

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

flask-botox-0.1.1.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

flask_botox-0.1.1-py3-none-any.whl (5.5 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