API¶
Anything documented here is part of the public API that flask-orjson provides, unless otherwise indicated. Anything not documented here is considered internal or private and may change at any time.
- class flask_orjson.OrjsonProvider(app)¶
A
JSONProvider
that uses the fast orjson library.- Parameters:
app (App)
- option: int | None = 2¶
Option flags to pass to
orjson.dumps
. Available flags are listed in the orjson docs. Multiple flags are combined using|
bitwise or.By default the
NAIVE_UTC
flag is enabled, which assumes the UTC timezone fordatetime
objects that do not have a timezone.
- static default(o)¶
Function to call to convert data in an unsupported type to a valid JSON type.
By default,
Decimal
, and classes with an__html__
method are supported, in addition to the extra types that orjson already supports.
- dumps(obj, *, option=None, default=None, **kwargs)¶
Serialize data as JSON.
- Parameters:
obj (Any) – The data to serialize.
option (int | None) – Option flags to pass to
orjson.dumps
. Available flags are listed in the orjson docs. Multiple flags are combined using|
bitwise or. Uses theoption
attribute if not given.default (Callable[[Any], Any] | None) – Function to call to convert data in an unsupported type to a valid JSON type. Uses the
default
attribute if not given.kwargs (Any) – Any other keyword arguments are silently ignored.
- Return type: