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.2.tar.gz
(14.3 kB
view details)
Built Distribution
File details
Details for the file flask_orjson-1.2.tar.gz
.
File metadata
- Download URL: flask_orjson-1.2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62811af5b7047bb7b600ac4c4ad8ea21ae24dac4aeca29bc1d5ef8116726c34d |
|
MD5 | abdcd41edcbf2cf993e1f60103bccfc1 |
|
BLAKE2b-256 | 292ccade47db3f3a1a58e54f276bbe951fa0ca5fd79dd5b8c29774a46868a5f7 |
File details
Details for the file flask_orjson-1.2-py3-none-any.whl
.
File metadata
- Download URL: flask_orjson-1.2-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dcfd0c38ab44778ebc4ab4a3fb14d449e693c97da51948c27c84ca674d7e058 |
|
MD5 | e57a55a20d055d813288715377717654 |
|
BLAKE2b-256 | 8d2d6e45f17a208eba5a9613ab516acee949ae2cde4e5f49e996d69d9af65f6a |