Welcome to Flask-Kaccel’s documentation!¶
A Quick Flask-Kaccel Introduction¶
Flask-Kaccel allow you to use Nginx X-Accel features on Flask application.
Nginx¶
If you serve Flask behind Nginx, then you can delegate the file streaming to Nginx and get increased performance:
lower resources used by Python/Flask workers ;
faster download.
See Nginx X-accel documentation for details.
API¶
-
class
flask_kaccel.
Kaccel
(app=None)[source]¶ Class used to control the Kaccel integration to a Flask application.
You can use this by providing the Flask app on instantiation or by calling an
init_app()
method an instance object of Kaccel. Here an example of providing the application on instantiation:app = Flask(__name__) kaccel = Kaccel(app)
And here calling the
init_app()
method:kaccel = Kaccel() def init_app(): app = Flask(__name__) kaccel.init_app(app) return app
- Config
KACCEL_HOST
KACCEL_REDIRECT_PATH
KACCEL_FILES_PATH
KACCEL_BUFFER
KACCEL_CHARSET
KACCEL_CACHE_EXPIRES
KACCEL_LIMIT_RATE
-
filesize
(file_path)[source]¶ get file size in byte
- Parameters
file_path – fullpath
- Returns
return <integer> if success and None if fail.
-
filename
(file_path)[source]¶ get file name from full path.
- Parameters
file_path – fullpath
- Returns
return <string> if success and None if fail.
-
extension
(file_path)[source]¶ get extension from full path.
- Parameters
file_path – fullpath
- Returns
return <string> if success and None if fail.
-
mimetype
(file_path)[source]¶ get mime type from file
- Parameters
file_path – fullpath
- Returns
return <string> if success and return “application/octet-stream” if mime type not found.
-
send_from_directory
(filename)[source]¶ send file from directory using global configuration.
- Parameters
filename – file name
- Returns
return Request() object if success and None if fail.
-
send_file
(file_path, redirect=None, buffering=True, charset='utf-8', expires=None, limit=None)[source]¶ send file from directory using custom configuration.
- Parameters
file_path – fullpath.
redirect – redirect path, default=None
buffering – sets the proxy buffering for this connection, value=(True|False), default=True
charset – sets the charset of the file, default=”utf-8”
expires – sets when to expire the file in the internal NGINX cache, value=(None|int), default=None
limit – sets the rate limit for this single request. off means unlimited, value=(None|int), default=None
- Returns
return Request() object if success and None if fail.