Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

695
Vistas
Optional query parameters in FastAPI

I don't understand optional query parameters in FastAPI. How is it different from default query parameters with a default value of None?

What is the difference between arg1 and arg2 in the example below where arg2 is made an optional query parameter as described in the above link?

@app.get("/info/")
async def info(arg1: int = None, arg2: int | None = None):
    return {"arg1": arg1, "arg2": arg2}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This is covered in the reference manual, albeit just as a small note:

async def read_items(q: Optional[str] = None):

FastAPI will know that the value of q is not required because of the default value = None.

The Optional in Optional[str] is not used by FastAPI, but will allow your editor to give you better support and detect errors.

(Optional[str] is the same as str | None pre 3.10 for other readers)

Since your editor might not be aware of the context in which the parameter is populated and used by FastAPI, it might have trouble understanding the actual signature of the function when the parameter is not marked as Optional. You may or may not care about this distinction.

over 4 years ago · Santiago Trujillo Denunciar

0

It depends on the way you see it, but my philosophy is:

Optional parameters are a bigger set that includes query parameters.

That is, query parameters take an input that is a value, while optional parameters are query parameters that can have no value (i.e. None).

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda