Skip to main content

Flask with UltraJSON.

Project description

flask-orjson

PyPI version License

pip install flask-orjson

Flask with orjson.

https://github.com/ijl/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.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

flask_orjson-1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file flask_orjson-1.1.tar.gz.

File metadata

  • Download URL: flask_orjson-1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for flask_orjson-1.1.tar.gz
Algorithm Hash digest
SHA256 b95afaba732f3e2170d14f2b5299f6817c6d11ce1f18ccbd31ab38fadec3376e
MD5 7f1a627546f6b87686d39e8bb7afcf31
BLAKE2b-256 936019c7a7a61a8ea32b76dc4038d093eae5efd2ee771c48c271dfb35f50beae

See more details on using hashes here.

File details

Details for the file flask_orjson-1.1-py3-none-any.whl.

File metadata

  • Download URL: flask_orjson-1.1-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

Hashes for flask_orjson-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 70d9f948176d9da11d7acc7beae2f9e21a7209b4fb6f06964ec42f57b1fd9104
MD5 2ed8e21473eb7b98fdb675b6c97f1b73
BLAKE2b-256 a9582e22e1402e156f323e4ad8d39bd22da4478923e8adfd14d09d6b8d323101

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page