json response using the highperformance ujson library to serialize data to json read more about it in the fastapi docs for custom response html stream file othershttps fastapi tiangolo comadvancedcustomresponse json response using the highperformance orjson library to serialize data to json read more about it in the fastapi docs for custom response html stream file othershttps fastapi tiangolo comadvancedcustomresponse noqa noqa noqa noqa noqa noqa noqa pragma nocover type ignore pragma nocover type ignore json response using the high performance ujson library to serialize data to json read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response json response using the high performance orjson library to serialize data to json read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response
from typing import Any

from starlette.responses import FileResponse as FileResponse  
from starlette.responses import HTMLResponse as HTMLResponse  
from starlette.responses import JSONResponse as JSONResponse  
from starlette.responses import PlainTextResponse as PlainTextResponse  
from starlette.responses import RedirectResponse as RedirectResponse  
from starlette.responses import Response as Response  
from starlette.responses import StreamingResponse as StreamingResponse  

try:
    import ujson
except ImportError:  
    ujson = None  


try:
    import orjson
except ImportError:  
    orjson = None  


class UJSONResponse(JSONResponse):
    

    def render(self, content: Any) -> bytes:
        assert ujson is not None, "ujson must be installed to use UJSONResponse"
        return ujson.dumps(content, ensure_ascii=False).encode("utf-8")


class ORJSONResponse(JSONResponse):
    

    def render(self, content: Any) -> bytes:
        assert orjson is not None, "orjson must be installed to use ORJSONResponse"
        return orjson.dumps(
            content, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY
        )