Flask extension to defer task execution under after request teardown
Project description
Flask-Defer
=========
.. image:: https://badge.fury.io/py/flask-defer.svg
:target: https://badge.fury.io/py/flask-defer
.. image:: https://travis-ci.org/brettlangdon/flask-defer.svg?branch=master
:target: https://travis-ci.org/brettlangdon/flask-defer
Easily register a function to execute at the end of the current request.
Installation
~~~~~~~~~~~~
.. code:: bash
pip install Flask-Defer
Usage
~~~~~
Passing a function and it's arguments to `flask_defer.after_request` will register that function to execute when the Flask request has ended.
If a call to `flask_defer.after_request` happens outside of a request context then the function will be executed immediately.
.. code:: python
from flask import Flask
from flask_defer import FlaskDefer, after_request
app = Flask(__name__)
FlaskDefer(app)
def defer_me(name, say_hello=False):
if say_hello:
print 'Saying hello to, {name}'.format(name=name)
@app.route('/')
def index():
print 'Start of request method'
# Defer `defer_me` until after the current request has finished
after_request(defer_me, 'name', say_hello=True)
print 'Ending request method'
return 'Thanks!'
if __name__ == '__main__':
app.run()
.. code:: bash
$ python example.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Start of request method
Ending request method
Saying hello to, name
127.0.0.1 - - [28/Nov/2016 15:41:39] "GET / HTTP/1.1" 200 -
=========
.. image:: https://badge.fury.io/py/flask-defer.svg
:target: https://badge.fury.io/py/flask-defer
.. image:: https://travis-ci.org/brettlangdon/flask-defer.svg?branch=master
:target: https://travis-ci.org/brettlangdon/flask-defer
Easily register a function to execute at the end of the current request.
Installation
~~~~~~~~~~~~
.. code:: bash
pip install Flask-Defer
Usage
~~~~~
Passing a function and it's arguments to `flask_defer.after_request` will register that function to execute when the Flask request has ended.
If a call to `flask_defer.after_request` happens outside of a request context then the function will be executed immediately.
.. code:: python
from flask import Flask
from flask_defer import FlaskDefer, after_request
app = Flask(__name__)
FlaskDefer(app)
def defer_me(name, say_hello=False):
if say_hello:
print 'Saying hello to, {name}'.format(name=name)
@app.route('/')
def index():
print 'Start of request method'
# Defer `defer_me` until after the current request has finished
after_request(defer_me, 'name', say_hello=True)
print 'Ending request method'
return 'Thanks!'
if __name__ == '__main__':
app.run()
.. code:: bash
$ python example.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Start of request method
Ending request method
Saying hello to, name
127.0.0.1 - - [28/Nov/2016 15:41:39] "GET / HTTP/1.1" 200 -
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
Flask-Defer-1.1.0.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file Flask-Defer-1.1.0.tar.gz
.
File metadata
- Download URL: Flask-Defer-1.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 145206689aeba443d672832b4d0d81d7a89e61c13e2193974fee68d8644db1d7 |
|
MD5 | 683c511acae0352724fc2187327fba93 |
|
BLAKE2b-256 | 7416c918eb56e64b2649118cc5cb716e069b6714654e88f6df6ea007b315a5a7 |
File details
Details for the file Flask_Defer-1.1.0-py2-none-any.whl
.
File metadata
- Download URL: Flask_Defer-1.1.0-py2-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b8ffcfa329addc39052209453d4a1b13642f702e5f5ff8fd1cfac00024c3ce8 |
|
MD5 | f69c7bc7fabacbc20f53b7a37f687268 |
|
BLAKE2b-256 | 874f8da5279a74a9a10be08e3fa1e5795e89e388189bd3ebd0015b87fcfc8429 |