{"repo":"JasperSui/fastapi-injectable","free":true,"listed":false,"github":"https://github.com/JasperSui/fastapi-injectable","clone":"git clone https://github.com/JasperSui/fastapi-injectable.git","description":"A seamless solution for using FastAPI's dependency injection system outside of route handlers, enabling painless reuse of dependencies in CLI tools, background tasks, and other non-HTTP contexts.","language":"Python","stars":295,"topics":["background-tasks","celery","clean-architecture","cli","dependency-injection","depends","di","dramatiq","fastapi","testing"],"license":"MIT","category":"cli-tools","readme_excerpt":"Use FastAPI's Depends() anywhere — in CLI tools, background workers, scheduled jobs, and more. Stop rewriting your dependency logic. Start reusing it. --- Installation : pip install fastapi-injectable Using mypy ? Enable the bundled plugin so @injectable calls type-check correctly — add plugins = [\"fastapi injectable.mypy\"] to your mypy config (see Type Hinting). The plugin is mypy -only; pyright /Pylance users still see call-arg errors. Documentation : https://fastapi-injectable.readthedocs.io/en/latest/ --- Why fastapi-injectable? If you use FastAPI, you've built your app around Depends() . But the moment you need those same dependencies in a CLI command , background worker , Celery task , or scheduled job — you're stuck. You end up: - Duplicating dependency logic outside of routes - Introducing a second DI framework alongside FastAPI's - Refactoring hundreds of existing dependency functions fastapi-injectable fixes this with a single decorator. Your existing Depends() functions just work — everywhere. Born from a real need: This project solves FastAPI#1105 — a 4+ year old issue requesting Depends() outside routes. Quick Start ⚠️ Calling this in a loop (worker, consumer, cron)? Resolved dependencies are cached in a process-global cache that persists across calls — a naïve loop reuses the same instances for the whole process and never runs generator cleanup, leaking resources. Reset state per iteration with injectable scope() , or with clear dependency cache() + cleanup all ","default_branch":null,"files":null,"tree":[],"storefront":"/r/JasperSui","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/JasperSui/fastapi-injectable/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}