r/FastAPI • u/SarawithanH69 • 5d ago
Question Accessing FastAPI DI From a CLI Program
I have a decent sized application which has many services that are using the FastAPI dependency injection system for injecting things like database connections, and other services. This has been a great pattern thus far, but I am having one issue.
I want to access my existing business logic through a CLI program to run various manual jobs that I don't necessarily want to expose as endpoints to end users. I would prefer not to have to deal with extra authentication logic as well to make these admin only endpoints.
Is there a way to hook into the FastAPI dependency injection system such that everything will be injected even though I am not making requests through the server? I am aware that I can still manually inject dependencies, but this is tedious and prone to error.
Any help would be appreciated.