Skip to main content

Flask-Executor

Build Status Coverage Status PyPI Version GitHub license

Sometimes you need a simple task queue without the overhead of separate worker processes or powerful-but-complex libraries beyond your requirements. Flask-Executor is an easy to use wrapper for the concurrent.futures module that lets you initialise and configure executors via common Flask application patterns. It's a great way to get up and running fast with a lightweight in-process task queue.

Installation

Flask-Executor is available on PyPI and can be installed with:

pip install flask-executor

Quick start

Here's a quick example of using Flask-Executor inside your Flask application:

from flask import Flask
from flask_executor import Executor

app = Flask(__name__)

executor = Executor(app)


def send_email(recipient, subject, body):
    # Magic to send an email
    return True


@app.route('/signup')
def signup():
    # Do signup form
    executor.submit(send_email, recipient, subject, body)

Contexts

When calling submit() or map() Flask-Executor will wrap ThreadPoolExecutor callables with a copy of both the current application context and current request context. Code that must be run in these contexts or that depends on information or configuration stored in flask.current_app, flask.request or flask.g can be submitted to the executor without modification.

Futures

You may want to preserve access to Futures returned from the executor, so that you can retrieve the results in a different part of your application. Flask-Executor allows Futures to be stored within the executor itself and provides methods for querying and returning them in different parts of your app::

@app.route('/start-task')
def start_task():
    executor.submit_stored('calc_power', pow, 323, 1235)
    return jsonify({'result':'success'})

@app.route('/get-result')
def get_result():
    if not executor.futures.done('calc_power'):
        return jsonify({'status': executor.futures._state('calc_power')})
    future = executor.futures.pop('calc_power')
    return jsonify({'status': done, 'result': future.result()})

Decoration

Flask-Executor lets you decorate methods in the same style as distributed task queues like Celery:

@executor.job
def fib(n):
    if n <= 2:
        return 1
    else:
        return fib(n-1) + fib(n-2)

@app.route('/decorate_fib')
def decorate_fib():
    fib.submit(5)
    fib.submit_stored('fibonacci', 5)
    fib.map(range(1, 6))
    return 'OK'

Documentation

Check out the full documentation at flask-executor.readthedocs.io!

Metadata

Release files for Flask-Executor 0.8.3

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-Executor 0.8.3
File Size Uploaded Provenance Actions
Flask-Executor-0.8.3.tar.gz 8.3 kB Without provenance Details for Flask-Executor-0.8.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Executor 0.8.3
File Interpreter ABI Platform Actions
Flask_Executor-0.8.3-py3-none-any.whl Python 3 none any Details for Flask_Executor-0.8.3-py3-none-any.whl

Total release size: 19.3 kB

Release files / Flask-Executor-0.8.3.tar.gz

Download URL Flask-Executor-0.8.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
705ccd7323e94334456e0143f39c1cf740914bfef6fe34df35833b185fd1d80b
BLAKE2b-256 checksum
How to use checksums
90377d98ea5c5b3fe955b89a8a683688f21b66b1ff763a4b92772f7bb1526a13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.2

Release files / Flask_Executor-0.8.3-py3-none-any.whl

Download URL Flask_Executor-0.8.3-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd6301729e82b46736635e458b8f2a9b3b1cef450801c079976eca4eba0bee58
BLAKE2b-256 checksum
How to use checksums
7f2c9d8773526d3b89c92bc8fe5baf28c7bc74258478ca8e70e22174506cf617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.2

Security for Flask-Executor 0.8.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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