13 questions
1 vote
0 answers
85 views
Fatest way to convert float array to string in python
This question came up while I was saving a large number of model-inferred embeddings to plain text. To do so, I needed to convert lists of float embeddings into strings, and I found this conversion to ...
-1 votes
1 answer
133 views
Serializing a Complex python Class to JSON
In my project I analyze the questions of a given exam. Let's say each exam has 10 questions. For each question I compute some stuff and save it, using the constructor method of class QuestionData (...
1 vote
0 answers
1k views
Python's orjson raised JSONDecodeError: str is not valid UTF-8
I tried to load a .json file with standard JSON library. It works fine, but slowly: with open(file, 'r', encoding="utf-8") as jfile: lines = json.loads(jfile.read()) I tried to use the ...
7 votes
1 answer
7k views
How to read the request body using orjson library in FastAPI?
I am writing code to receive a JSON payload in FastAPI. Here is my code: from fastapi import FastAPI, status, Request from fastapi.responses import ORJSONResponse import uvicorn import asyncio import ...
5 votes
2 answers
4k views
Unable to install orjson 3.3.0 on macOS 12.2.1 with Apple M1 chip
I am trying to install orjson==3.3.0 on my MacBook Pro with Apple M1 Pro chip running macOS Monterey 12.2.1. Python version: 3.8.9 Command used: pip install orjson==3.3.0 Error: Collecting orjson==3.3....
1 vote
3 answers
3k views
Apache beam(2.32.0) installation fails
We have some issues deploying our GCP Dataflow pipeline. After some analysis, found that the latest version of apache-beam has some issues while installing. To replicate the issue I created a ...
1 vote
1 answer
2k views
How to JSONIFY a dict having a pydantic model
I am new to pydantic and am stuck. Below code is throwing error TypeError: Type is not JSON serializable: Person from pydantic import BaseModel,Extra from typing import Mapping, Optional, Any,List ...
32 votes
7 answers
74k views
How to resolve pydantic model is not JSON serializable [duplicate]
I am having below pydantic models. class SubModel(BaseModel): columns: Mapping key: List[str] required: Optional[List[str]] class Config: anystr_strip_whitespace: True ...
0 votes
2 answers
966 views
Why Http headers is being vanished when using ORJSONResponse() in fastAPI?
Http headers can be modified in fastAPI; however when I tried to use faster serializer (in this instance ORJSONResponse) in order to have faster response, all added or modified headers confusingly is ...
2 votes
2 answers
7k views
How to set response class in FastAPI?
Using orjson to serializing response has a remarkable effect on the speed of fastAPI restful services, specifically for very big objects. As I have read in the official documentation, we can use the ...
9 votes
2 answers
25k views
orjson and json dumps method not the same python3.8
I have switched to orjson since it is faster, but this has caused an issue I have had for a fair amount of time now but never thought anything of it. I finally decided to do tests and these were my ...
5 votes
1 answer
8k views
pip install fastapi[all] is failing due to a rust component?
Hi I'm trying to install fastapi, but it seems to be failing when im installing orjson Here is the full error code: Building wheel for orjson (PEP 517) ... error ERROR: Command errored out with ...
1 vote
3 answers
9k views
How do I setup rust toolchain for orjson python library build in an alpine docker image?
I have been struggling with this and I need some help. I am trying to create a docker image of my python app. My App uses orjson, the fast JSON library for python. Parts of this library is built ...