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
~~~~~
.. 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
~~~~~
.. 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.0.0.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file Flask-Defer-1.0.0.tar.gz
.
File metadata
- Download URL: Flask-Defer-1.0.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f61b1475d3374ccf60eb53533736ddb468f6d421032c79d64d946fcc9ab77843 |
|
MD5 | 470e33affb214c8a25e9c8e9241ab06e |
|
BLAKE2b-256 | 321daac569d64f070bad4b68e275397e086cd388e00c0feaf6b07fb82afb2d81 |
File details
Details for the file Flask_Defer-1.0.0-py2-none-any.whl
.
File metadata
- Download URL: Flask_Defer-1.0.0-py2-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e284aeb247f3bc9749a904d4baabc664f9cb845b59c61a1ef455b559ca1b41a6 |
|
MD5 | de6a795de3c679ebabe13c918b16a848 |
|
BLAKE2b-256 | a94636a5aac0839827a72d71c45dd992616dba2a5d34bba8fd1a31639ec5625a |