Better JSON support for Flask
Project description
Flask-JSON is a simple extension that adds better JSON support to Flask application.
Features:
Works on python 2.6, 2.7, 3.3+ and Flask 0.10+.
More ways to generate JSON responses (comparing to plain Flask).
Extended JSON encoding support.
Usage
Here is fast example:
from datetime import datetime
from flask import Flask
from flask_json import FlaskJSON, JsonError, json_response, as_json
app = Flask(__name__)
FlaskJSON(app)
@app.route('/get_time')
def get_time():
return json_response(time=datetime.utcnow())
@app.route('/get_time_and_value')
@as_json
def get_time_and_value():
return dict(time=datetime.utcnow(), value=12)
@app.route('/raise_error')
def raise_error():
raise JsonError(description='Example text.', code=123)
if __name__ == '__main__':
app.run()
Responses:
GET /get_time HTTP/1.1
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 60
{
"status": 200,
"time": "2015-04-14T13:17:16.732000"
}
GET /raise_error HTTP/1.1
HTTP/1.0 400 BAD REQUEST
Content-Type: application/json
Content-Length: 70
{
"code": 123,
"description": "Example text.",
"status": 400
}
Documentation
Documentation is available on Read the Docs.
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-JSON-0.3.5.tar.gz
(9.0 kB
view details)
Built Distribution
File details
Details for the file Flask-JSON-0.3.5.tar.gz
.
File metadata
- Download URL: Flask-JSON-0.3.5.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b641a2125cb6984e7eafc921c9bf70c214ea4faff9a0bb1a75a4ec5749f3e67c |
|
MD5 | d645b27e41a6bc4b12c83c607e5a7005 |
|
BLAKE2b-256 | 032f6576060fd5595a1624a2afca257acaebfd33f0f61153ea99a58cf9be15f9 |
File details
Details for the file Flask_JSON-0.3.5-py3-none-any.whl
.
File metadata
- Download URL: Flask_JSON-0.3.5-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0701576a2ddb78eb11fd74c143871e01205537c4a83dbc81cd3796ca68627f86 |
|
MD5 | a2c11d69912d5f60a75b4b4f16d59e14 |
|
BLAKE2b-256 | e953b447aaa17c7f41f9e1bcec7e476f86b6f7d097fda1111e77967067bde3d7 |