-
FastAPI is using Possible alternative maybe |
Beta Was this translation helpful? Give feedback.
Replies: 15 comments 1 reply
-
I would be in favor of recommending I recall the creator of To the extent that there is any difference in json encoding/decoding between json and orjson (or ujson and orjson), it would probably be best to document it. I'd be willing to review a PR making this change (including updates to the docs). (I'd leave the ultimate decision about merging to @tiangolo though.) |
Beta Was this translation helpful? Give feedback.
-
Yeah, I've been intending to do it for quite some time now... 😅 In fact, you can sort of do it right now (and since several versions ago). Here's my plan: I want to export everything from Starlette, to avoid confusions of the type "do I import this from FastAPI or from Starlette?", I've seen reports of that and even I've struggled with that. For example, FastAPI has its own With that, I want to have a response In fact, I added tests for creating custom responses (as part of a PR), testing specifically creating orjson responses: fastapi/tests/test_default_response_class.py Lines 9 to 13 in f803c77 And you can replicate creating that response class and using it. It's just 3 lines (you would remove the custom media_type ), but still, it should be provided by FastAPI (among all the other responses from Starlette).
app = FastAPI(default_response_class=ORJSONResponse) Also, as a side note, UJSON is not really used by default anywhere. It's optional, and you would have to use the |
Beta Was this translation helpful? Give feedback.
-
Well, that's elegant sir 🙇♂️ 👏 .
Then I don't understand why it's in requirements. It's written that it's an optional dependency for Pydantic, but it seems that Pydantic has already moved away from ujson here. Seems that their requirements nor setup.py don't have it anymore. |
Beta Was this translation helpful? Give feedback.
-
@hnykda the “all” set of requirements there includes everything necessary to make use of all documented features, including those that are optional. It is intended more for development/reference purposes than for use by consumers. |
Beta Was this translation helpful? Give feedback.
-
Ah, got it! Thanks. I believe this can be closed then. Personally, I would not reference any obsolete dependencies in my project even if they are optional (especially "future-looking" like Python 3.6+, latest libs, ...) . Reasons for that: helping the community to get rid dangerous/old/unmaintained libs and to avoid possibly repealing people who do not like to install stuff which are referencing such unmaintained projects. |
Beta Was this translation helpful? Give feedback.
-
Apparently, https://pypi.org/project/ujson/ and repo seems active again. Just mentioning this. Dunno which one is the better lib. |
Beta Was this translation helpful? Give feedback.
-
Nevermind, apparently |
Beta Was this translation helpful? Give feedback.
-
Just to mention, installing fastapi on windows platform (python 3.9) fails, since orjson neither provide the compatible wheel nor could be compiled. |
Beta Was this translation helpful? Give feedback.
-
On Debian stable installing orjson currently fails because it targets In this case running |
Beta Was this translation helpful? Give feedback.
-
@ahmadazizi, |
Beta Was this translation helpful? Give feedback.
-
Since Starlette dropped support for This require changes in #2335, since it re-adds |
Beta Was this translation helpful? Give feedback.
-
Regarding ujson, there is a security alert reported with moderate severity which is patched in 5.1.0. Fastapi 0.74.0 requires |
Beta Was this translation helpful? Give feedback.
-
Hello all, I did find a workaround which allows us to build images without the ujson. I am using the FastAPI is fantastic so far, thank you all for your hard work on this project. Here, roughly the steps I used:
Hope this helps someone until they scan make the permanent fix. Thank you, ~ melt |
Beta Was this translation helpful? Give feedback.
-
Are you sure the ujson is EOL? According to its repository, the last release was in mid-September, and the last commit was 3 weeks ago - the project seems to be quite alive. |
Beta Was this translation helpful? Give feedback.
-
Just as an update. This is what the pypi page says:
Additionally, I just want to mention that in my project, |
Beta Was this translation helpful? Give feedback.
Yeah, I've been intending to do it for quite some time now... 😅
In fact, you can sort of do it right now (and since several versions ago).
Here's my plan:
I want to export everything from Starlette, to avoid confusions of the type "do I import this from FastAPI or from Starlette?", I've seen reports of that and even I've struggled with that. For example, FastAPI has its own
HTTPException
.With that, I want to have a response
ORJSONResponse
exported fromfastapi.responses
, among Starlette's responses.In fact, I added tests for creating custom responses (as part of a PR), testing specifically creating orjson responses:
fastapi/tests/test_default_response_class.py
Lines 9 to 13 in f80…