Flask Application Configurator
Project description
Flask Appconfigure
Flask Appconfigure is a simple and lightweight module which simplifies the concept of creating and configuring Flask Applications in an Object-Oriented Way.
Installation
You can install Flask Appconfigure from this Github repository with python3 setup.py install
,
or just install it directly from pypi with pip3 install flask-appconfigure
.
Get Started
BaseConfigurator
Flask Appconfigure uses the concept of Configurators. Each configurator should do exactly one configuration.
To create a custom configurator, simply subclass from BaseConfigurator
and implement the configure
method.
Inside the configure method, you have access to the Flask Application through self.app
:
from flask_appconfigure import BaseConfigurator
class DummyConfigurator(BaseConfigurator):
ExitOnError = False
def configure(self):
self.app.before_request(lambda: print("before request"))
To configure wether a raised exception should abort the whole configuration process or not, you can set the ExitOnError
attribute
of your own configurator to True
or False
. The default is True
.
ConfiguratorPool
To use your own configurators, you will need an instance of a ConfiguratorPool
. There you can add your configurators
in exactly the same order as they are then executed.
from flask_appconfigure import ConfiguratorPool, BaseConfigurator
class DummyConfigurator2(BaseConfigurator):
def configure(self, environment="dev"):
pass
pool = ConfiguratorPool()
pool.add_configurator(DummyConfigurator)
pool.add_configurator(DummyConfigurator2)
When configuring your Flask Application, the DummyConfigurator
gets executed first, then DummyConfigurator2
.
To pass further arguments to the configure
method of your configurator, you can use the optional arguments args
and kwargs
in ConfiguratorPool.add_configurator
.
pool.add_configurator(DummyConfigurator2, kwargs={"environment": "test"})
ApplicationFactory
The ApplicationFactory
brings all the pieces together and actually executes your configurators.
from flask_appconfigure import ApplicationFactory
factory = ApplicationFactory(pool)
app = factory.create_app(template_folder='my_template_folder')
You can also pass any parameters to the create_app function as you would to the flask.Flask()
constructor.
If no parameters are passed, the flask app is created using flask.Flask(__name__)
.
Alternatively, if you already have a flask.Flask
object and only need to configure it using your ConfigurationPool, you can
use the factory.configure_app(app)
method.
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
File details
Details for the file flask_appconfigure-1.0.1.tar.gz
.
File metadata
- Download URL: flask_appconfigure-1.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7e8b0e253d72338787d14ac59fe72ea185efa609db274964012c9e7d27e8f59 |
|
MD5 | 6dd39e3778d41153748b2be8d480b383 |
|
BLAKE2b-256 | c3ce6979bf70d37afce19bcc2d44a3106d04b7041c3fc8e52a2ea84fcfffb806 |
File details
Details for the file flask_appconfigure-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: flask_appconfigure-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d34f6b1dafcd77fa54061ac3a0167257d445906ab8bfe734bd0933d7857afee |
|
MD5 | 484d3a8030f690cb1bd371ff27053586 |
|
BLAKE2b-256 | 71d6410a70caea5b1acdb6c547620b1afff6ee6ea89b82d82f40e5e528e4f8ca |