---
source: https://iinventedlight.com/library/notes/fastapi-dependencies.md
title: "Dependency injection with Depends 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, Dependencies - FastAPI, MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE); FastAPI docs, Classes as Dependencies - 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', 'dependency-injection', 'python']
sources:
  - id: S1
    title: "Dependencies - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/dependencies/
    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: "Classes as Dependencies - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/dependencies/classes-as-dependencies/
    accessed: 2026-11-04
    license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)"
---
# Dependency injection with Depends in FastAPI

**Answer:** FastAPI has a very powerful but intuitive Dependency Injection system. Although you use Depends in the parameters of your function the same way you use Body, Query, etc, Depends works a bit differently. (S1)

## Shared code

- This way you write shared code once and FastAPI takes care of calling it for your path operations. (S1)
- You don't have to create a special class and pass it somewhere to FastAPI to "register" it or anything similar. (S1)
- You just pass it to Depends and FastAPI knows how to do the rest. (S1)

## Any callable works

- A "callable" in Python is anything that Python can "call" like a function. (S2)
- In FastAPI, you could use a Python class as a dependency. (S2)
- What FastAPI actually checks is that it is a "callable" (function, class or anything else) and the parameters defined. (S2)
- If you pass a "callable" as a dependency in FastAPI, it will analyze the parameters for that "callable", and process them in the same way as the parameters for a path operation function. (S2)

## Claims
- id: C1
  claim: FastAPI has a dependency injection system.
  source: S1
  evidence: "FastAPI has a very powerful but intuitive Dependency Injection system."
- id: C2
  claim: Shared code is written once.
  source: S1
  evidence: "and then FastAPI takes care of calling the function with the correct parameters"
- id: C3
  claim: Classes can be dependencies.
  source: S2
  evidence: "you could use a Python class as a dependency."
- id: C4
  claim: FastAPI checks for a callable.
  source: S2
  evidence: "...is what FastAPI will actually use to know what is the dependency."

## Sources
- [S1] Dependencies - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/tutorial/dependencies/ . 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] Classes as Dependencies - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/tutorial/dependencies/classes-as-dependencies/ . 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).
