Flask with UltraJSON.
Project description
flask-orjson
pip install flask-orjson
Flask with orjson.
from dataclasses import dataclass
from datetime import datetime
from flask import Flask, request
from flask_orjson import ORJSON
orjson = ORJSON()
@dataclass
class NewDataClass:
hello: str = "world"
def create_app():
app = Flask(__name__)
orjson.init_app(app) # Sets ORJSON as the default JSON encoder
@app.route("/")
def index():
"""
Outputs a JSON response using the orjson library
https://github.com/ijl/orjson
"""
return {
"timestamp": 1556283673.1523004,
"task_uuid": "0ed1a1c3-050c-4fb9-9426-a7e72d0acfc7",
"task_level": [1, 2, 1],
"action_status": "started",
"action_type": "main",
"key": "value",
"another_key": 123,
"and_another": ["a", "b"],
"today": datetime.now(),
"dataclass": NewDataClass()
}
@app.post("/post")
def accept_json():
json = request.get_json()
return json
return app
if __name__ == "__main__":
app = create_app()
app.run(debug=True)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask_orjson-1.0.2.tar.gz
(11.5 kB
view details)
Built Distribution
File details
Details for the file flask_orjson-1.0.2.tar.gz
.
File metadata
- Download URL: flask_orjson-1.0.2.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 539296895e73bc32cc54c56f030db389b7141bcf27b0974b9454350c3492d633 |
|
MD5 | bdbda38901719bf4e57e6190698970bf |
|
BLAKE2b-256 | 2bad79b6f620e035a0c7e6e89f2ecd1c8ce7e1dc52cf8d9c2e43a1b2ca1996a6 |
File details
Details for the file flask_orjson-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: flask_orjson-1.0.2-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9013eacc76606074720de5de0e238e3648732fdbf260c176ab1896acb5fca4cc |
|
MD5 | 367e4e0543cd6854c038859d8fc80c9b |
|
BLAKE2b-256 | 51fe8629d88965e611f5d89de3a920ba5e8d4e24f31666d4540b3155703e1ed9 |