Skip to main content

Build status Code coverage Maintenance yes GitHub license Documentation Status

Flask-Execute

Flask-Execute is a plugin for simplifying the configuration and management of Celery alongside a Flask application. It also slightly changes the paradigm for registering and dispatching celery tasks, exposing an API similar to the concurrent.futures API for submitting tasks to a separate executor.

Other features of the plugin include:

  • Automatic spin-up of local workers, queues, schedulers, and monitoring tools via configuration.

  • Automatic application context wrapping for celery workers.

  • Simpler API for submitting tasks to workers that doesn’t require pre-registration of tasks.

  • Result object API similar to concurrent.futures.Future API.

  • Flask CLI wrapper around the celery command that automatically wraps celery commands with an application context.

Installation

To install the latest stable release via pip, run:

$ pip install Flask-Execute

Alternatively with easy_install, run:

$ easy_install Flask-Execute

To install the bleeding-edge version of the project (not recommended):

$ git clone http://github.com/bprinty/Flask-Execute.git
$ cd Flask-Execute
$ python setup.py install

Usage

To set up an application with the extension, you can register the application directly:

from flask import Flask
from flask_execute import Celery

app = Flask(__name__)
plugin = Celery(app)

Or, via factory pattern:

celery = Celery()
app = Flask(__name__)
celery.init_app(app)

Once the plugin has been registered, you can submit a task using:

def add(x, y):
  return x + y

future = celery.submit(add, 1, 2)

# wait for result (not required)
future.result(timeout=1)

# cancel result
future.cancel()

# add callback function
def callback():
  # do something ...
  return

future.add_done_callback(callback)

Note that this plugin does not require users to pre-register tasks via the @celery.task decorator. This enables developers to more easily control whether or not task execution happens within the current session or on a separate worker. It also makes the API similar to the API provided by Dask and concurrent.futures. Also note that the celery command-line tool for spinning up local workers is no longer necessary. If no workers are connected, this plugin will automatically spin them up the first time a celery.submit() call is made.

Once a task as been submitted, you can monitor the state via:

task_id = future.id

# later in code

future = celery.get(task_id)
print(future.state)

You can also manage state updates within tasks with a more Flask-y syntax:

from flask_execute import current_task

def add(a, b):
  current_task.update_state(state='PROGRESS')
  return a + b

This plugin will also manage the process of spinning up local workers bound to your application the first time a celery.submit() call is made (if configured to do so). Additionally, the plugin will automatically wrap celery cli calls with your flask application (using the factory method or not), so you can more easily interact with celery:

# start local celery cluster with workers, flower monitor, and celerybeat scheduler
~$ flask celery cluster

# start local worker
~$ flask celery worker

# check status of running workers
~$ flask celery status

# shutdown all celery workers
~$ flask celery control shutdown

# shutdown all celery workers
~$ flask celery control shutdown

If your application uses the factory pattern with a create_app function for registering blueprints and plugin, you can use the standard flask cli syntax for automatically wrapping celery commands with your application context:

# check status of running workers
~$ FLASK_APP=app:create_app flask celery status

For more in-depth discussion on design considerations and how to fully utilize the plugin, see the User Guide.

Documentation

For more detailed documentation, see the Docs.

Questions/Feedback

File an issue in the GitHub issue tracker.

Metadata

Release files for Flask-Execute 0.1.6

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-Execute 0.1.6
File Size Uploaded
Flask-Execute-0.1.6.tar.gz 339.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Execute 0.1.6
File Interpreter ABI Platform
Flask_Execute-0.1.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 358.5 kB

Release files / Flask-Execute-0.1.6.tar.gz

Download URL Flask-Execute-0.1.6.tar.gz
Size 339.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bedeba84d0b71d928cf420c224b30c038c1be718452b420d539de5bbe23f0136
BLAKE2b-256 checksum
How to use checksums
6a3981b7c4d35a3aa8ec36bdd984d07b96cb6f98065048d508007f4ff8a5c4f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Release files / Flask_Execute-0.1.6-py2.py3-none-any.whl

Download URL Flask_Execute-0.1.6-py2.py3-none-any.whl
Size 19.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
df0424f8fbde8a4241c419d76ae4743e84059ed45412c78ec76efe5e4a1d95e6
BLAKE2b-256 checksum
How to use checksums
419e173ac18da38248b0d2a5f90ebb89dfb5aad139f4f56385e1961ef265215c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.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