fa

fastapi-injectable – Use FastAPI Depends() anywhere even outside routes

Hacker News

fastapi-injectable – Use FastAPI Depends() anywhere even outside routes

Hey HN! I created fastapi-injectable to solve a common pain point in FastAPI: using Depends() outside of route handlers. This has been a long-standing issue in the FastAPI community with a discussion post around it. Install with: pip install fastapi-injectable The package lets you use FastAPI's dependency injection in: - CLI tools - Background workers - Test fixtures - Any non-HTTP context Basic example: from typing import Annotated from fastapi import Depends from fastapi_injectable import injectable class Database: def query(self) -> str: return "data" def get_db() -> Database: return Database() @injectable def process_data(db: Annotated[Database, Depends(get_db)]) -> str: return db.query() # Use it anywhere! result = process_data() print(result) # Output: 'data' This is a production-ready package for FastAPI developers who need to use dependency injection outside of HTTP routes. The common suggestion for handling dependencies outside FastAPI routes is to use separate DI frameworks like dependency-injector. However, this means: 1. Managing two different DI systems in your codebase 2. Learning another framework's patterns 3. Potentially duplicating dependency logic Currently, there's no package that extends FastAPI's native Depends() beyond routes. fastapi-injectable solves this by providing a clean API that lets you use FastAPI's dependency injection anywhere. Links: GitHub: https://github.com/your-username/fastapi-injectable Docs: https://fastapi-injectable.readthedocs.io PyPI: https://pypi.org/project/fastapi-injectable I'd love to hear your feedback and contributions to make this package better! Feel free to open issues or PRs if you have ideas for improvements.

Share card

Actual performance

1points
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Product HuntOn track for Day 1 leaderboard · Strong signals: user, context, using · Missing: mac, agents, macos
82%82% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Indie HackersFits the IH revenue-focused audience · Strong signals: created, para · Missing: supports, reddit linkedin, podcasting
81%81% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Strong signals: para · Missing: mobile apps, ios, personal
41%41% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Missing: plus, platform, intuitive
39%39% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: ide, io · Missing: https docs, excited, just released
26%26% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
14%14% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Ro
Routes – Typed bidirectional routes for OCaml/ReasonML34%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Routes – Typed bidirectional routes for OCaml/ReasonML

Hacker News1
Co
Cowboy-trails = Cowboy routes on steroids29%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Cowboy-trails = Cowboy routes on steroids

Hacker News2
Im
Imux – a tool for inverse multiplexing sockets over configurable routes35%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Imux – a tool for inverse multiplexing sockets over configurable routes

Hacker News2
Pl
Plubo Routes – WordPress routes made simple24%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Plubo Routes – WordPress routes made simple

Hacker News1
Cl
Clover – server routes augmented with Zod and OpenAPI45%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Clover – server routes augmented with Zod and OpenAPI

Hacker News2
SEARateGuide
SEARateGuide28%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Compare Remittance Routes Across Southeast Asia

Indie Hackers1ai
Ne
Next-Routes-Middleware – Extensible, customizable middleware for NextJS26%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Next-Routes-Middleware – Extensible, customizable middleware for NextJS

Hacker News2
Si
Singapore Bus Routes Explorer40%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Singapore Bus Routes Explorer

Hacker News2
SA
SANPO, a service for sharing photowalk routes59%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

SANPO, a service for sharing photowalk routes

Hacker News1
Recce
Recce41%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Navigation app for scouting cycling routes

Indie Hackers1content