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.0.3.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

flask_orjson-1.0.3-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flask_orjson-1.0.3.tar.gz
Algorithm Hash digest
SHA256 63a4313265feb1b5b30d7e6c58a04b4a248c29c862788b5223ad28c18dac2975
MD5 cab457f9c03cea8c4351368f77a8e983
BLAKE2b-256 47963c1bf3c43b5d115a4d0501a700d2084bf740e1551922488b424191ea5b69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flask_orjson-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d5fc18cca87674cb9f5abd90211a28cfc10c6f871d6fa3b00fc5f424e758e42c
MD5 b2bfb6806bfd2e9f6e53ce3db320bcca
BLAKE2b-256 86ce23b78e5de534ddcdeea11d2552d52e4c262d18d264b32cc34e8f30e744f3

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