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 theboto3AWS 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 customendpoint_urlfor a particular service. The format is adictwhere the top-level keys are the name of the services you're using and for each the value is adictcontaining to keysargs(contains the parameters astuple) andkwargs(contains the parameters as adictwhen they should be passed as keyword arguments).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask-botox-0.1.1.tar.gz.
File metadata
- Download URL: flask-botox-0.1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Darwin/21.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38325263b26c5bd64ebe4d230264efb3e8d81294036b67ea2aa1207b4473b57e
|
|
| MD5 |
ea4c99f01121a56e2124406bd7df4257
|
|
| BLAKE2b-256 |
438548b8a579f0e22d80f9e4a8f911131c693cca986289a6096562087971a4e5
|
File details
Details for the file flask_botox-0.1.1-py3-none-any.whl.
File metadata
- Download URL: flask_botox-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Darwin/21.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fd70201e0984e1ed21d1aea2985a2a4134bb82e72bae6892d1a654ab72fc6de
|
|
| MD5 |
ce8de64f48cd6757c6e61cdd794a9d4a
|
|
| BLAKE2b-256 |
f31854df3b98a161fc8aa9dacace7b06202da7dc76914120568677444e285ac4
|