Skip to main content

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.

Metadata

Release files for flask-appconfigure 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-appconfigure 1.0.1
File Size Uploaded
flask_appconfigure-1.0.1.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-appconfigure 1.0.1
File Interpreter ABI Platform
flask_appconfigure-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / flask_appconfigure-1.0.1.tar.gz

Download URL flask_appconfigure-1.0.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f7e8b0e253d72338787d14ac59fe72ea185efa609db274964012c9e7d27e8f59
BLAKE2b-256 checksum
How to use checksums
c3ce6979bf70d37afce19bcc2d44a3106d04b7041c3fc8e52a2ea84fcfffb806
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / flask_appconfigure-1.0.1-py3-none-any.whl

Download URL flask_appconfigure-1.0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d34f6b1dafcd77fa54061ac3a0167257d445906ab8bfe734bd0933d7857afee
BLAKE2b-256 checksum
How to use checksums
71d6410a70caea5b1acdb6c547620b1afff6ee6ea89b82d82f40e5e528e4f8ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page