---
source: https://iinventedlight.com/library/notes/fastapi-path-query-params.md
title: "Path and query parameters in FastAPI"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE); prose restates or closely paraphrases cited source lines"
license_family: fastapi-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, Path Parameters - FastAPI, MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE); FastAPI docs, Query Parameters - FastAPI, MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: FastAPI"
tags: ['fastapi', 'python', 'http']
sources:
  - id: S1
    title: "Path Parameters - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/path-params/
    accessed: 2026-11-04
    license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)"
  - id: S2
    title: "Query Parameters - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/query-params/
    accessed: 2026-11-04
    license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)"
---
# Path and query parameters in FastAPI

**Answer:** The value of the path parameter item_id will be passed to your function as the argument item_id. When you declare other function parameters that are not part of the path parameters, they are automatically interpreted as "query" parameters. (S1, S2)

## Types give validation

- With the same Python type declaration, FastAPI gives you data validation. (S1)
- Notice that the error also clearly states exactly the point where the validation didn't pass. (S1)
- This will give you editor support inside of your function, with error checks, completion, etc. (S1)

## Query parameters

- The query is the set of key-value pairs that go after the ? in a URL, separated by & characters. (S2)
- As they are part of the URL, they are "naturally" strings. (S2)
- When you declare them with Python types, they are converted to that type and validated against it. (S2)
- As query parameters are not a fixed part of a path, they can be optional and can have default values. (S2)

## Claims
- id: C1
  claim: Path values are passed as function arguments.
  source: S1
  evidence: "item_id is declared to be an int."
- id: C2
  claim: Type declarations give validation.
  source: S1
  evidence: "FastAPI gives you data validation."
- id: C3
  claim: Non-path parameters are query parameters.
  source: S2
  evidence: "As query parameters are not a fixed part of a path"
- id: C4
  claim: Query parameters can be optional.
  source: S2
  evidence: "they can be optional and can have default values."

## Sources
- [S1] Path Parameters - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/tutorial/path-params/ . License: MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE). Accessed 2026-11-04.
- [S2] Query Parameters - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/tutorial/query-params/ . License: MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
