Questions tagged [fastapi]

FastAPI stands out as a cutting-edge web framework that harnesses the power of Python 3.6+ and leverages standard Python type hints to ensure lightning-fast performance. Built with speed in mind, it excels at crafting APIs for an array of applications.

What is the best way to insert a list of objects from a BaseModel class into a database using SQL Alchemy and FastApi?

I am looking to dynamically insert rows into a table named "computers" for some of its columns, with the column names not known in advance hence the need for dynamic insertion. To achieve this, I have created a BaseModel class called "ColumnIn" that consi ...

Utilizing aioprometheus and FastAPI to integrate metrics with external services

I'm currently working on integrating metrics for external services using aioprometheus within a FastAPI application. Below is an example showcasing my approach in a simplified manner. Let's consider a wrapper App class like this: from aioprometheus import ...

Dealing with Media Recorder File Types in FastAPI WebSockets - Trouble with Video File Integrity问题

Currently, I am working on a project that involves using FastAPI to manage WebSocket connections for receiving video blobs from a Media Recorder. The main objective is to divide the video into parts with a size limit of 5 MB and save each part as a separat ...

Experimenting with FastAPI's TestClient results in a 422 response code for specific

Hey there, I'm currently facing an issue while testing my code. I am working with FastAPI and pydantic's BaseModel. # Model class Cat(BaseModel): breed: str location_of_origin: str coat_length: int body_type: str pattern: str ...

How does utilizing app.on_event("startup") differ from simply including additional lines in the main.py file within a fastapi application?

I'm feeling a bit puzzled about the purpose of using a @app.on_event("startup") statement. (doc: ) Is there a benefit to encapsulating the code within a @app.on_even("startup") block instead of just placing it at the beginning of ...

Is there a way to showcase a Matplotlib graph using FastAPI/Nextjs without needing to save the chart on the local machine

For my website, I am utilizing a Nextjs frontend along with a FastAPI backend. On the frontend, there is an input form for capturing an 'ethereum address'. Using this address, a matplotlib chart displaying 'ethereum balance over time' is generated on the b ...

Can you explain the concept of true rps specifically in regards to locust

I wonder about the number of actual requests per second my service receives during a locust load test. If there are 50 users and it shows 6 RPS, does that mean I am receiving 300 requests per second? ...

The issue persists with FastAPI CORS when trying to use wildcard in allow origins

A simplified representation of my code utilizing two different approaches. from fastapi import FastAPI middleware = [ Middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=False, allow_methods=["*"], ...

Angular ngFor does not display the JSON response from the API (GET request)

I'm attempting to retrieve a JSON response from my API and display the values on my Angular page using ngFor. Although I don't have any build errors, the values are not being displayed on the page. They only appear in the console when using console.log(), ...

A foolproof method for safeguarding the JWT secret key utilized for encoding and decoding token information

I have a Python application in the works with FastApi, utilizing JWT and OAuth2 password flow for user authentication. Following their documentation, upon user login, a token is issued using the HS256 algorithm along with a specific user secret key. This t ...

Encountering a CORS issue specifically on the client side of a Next.js application when interacting with an API gateway

I've been struggling with this issue for a week now and can't seem to fully describe it. I have a FastAPI server running as a Lambda connected to API Gateway. https://i.stack.imgur.com/S5Zx9.png Both FastAPI and API Gateway have CORS enabled, b ...

Encountering a 500 error while trying to make a POST request with FastAPI on Vercel

I am currently utilizing React on the frontend and Fastapi on the backend main.py from typing import Union from fastapi import FastAPI from fastapi.encoders import jsonable_encoder from fastapi.middleware.cors import CORSMiddleware from pydantic import ...

Python fastAPI and MongoDB environment allows the return of a tuple in the BaseModel list

Currently, my setup includes env with python311, pydantic, fastapi, and mongod. return membercollection(members=await c_members.find(queryparam).to_list(1000)) This code snippet retrieves the following information: members=[membermodel(id='65b3908a77efb45 ...

Guide on building a FastAPI endpoint that can handle both Form and JSON body in one request

Is it possible to design an endpoint in FastAPI that can handle both (multipart) Form data and JSON body? How can I make the endpoint recognize the type of data it is receiving? ...

Is it possible to include a hyphen (-) in a query parameter name when using FastAPI?

Let's explore a sample application: from typing import Annotated import uvicorn from fastapi import FastAPI, Query, Depends from pydantic import BaseModel app = FastAPI() class Input(BaseModel): a: Annotated[str, Query(..., alias="your_name&qu ...

Uploading a file to FastAPI server with CURL: Step-by-step guide

I am in the process of configuring a FastAPI server that is capable of accepting a single file upload from the command line through the use of curl. To guide me, I am following the FastAPI Tutorial located at: from typing import List from fastapi import ...