skillfed

Flask-Injector

Adds Injector, a Dependency Injection framework, support to Flask.

flask-injector v0.15.0 106.2K downloads/30d#12,666 on PyPI282
Permissive license BSD DORMANT released

What it is and what it does

Flask-Injector bridges the Injector dependency-injection framework into Flask applications. Instead of using Flask's global objects (like the global request context or extension singletons), you define dependencies in Injector modules and have them automatically injected into views, request handlers, template processors, and other Flask components. This eliminates the need for global state, making applications easier to test and reason about.

The package works by wrapping Flask's initialization and hooking into its request lifecycle. It binds Flask's core objects (the app, config, and request) into the Injector container at appropriate scopes (singleton for app and config, request-scoped for the current request), then resolves function parameters by type annotation. It integrates with Flask-RESTful, Flask-RestPlus, and Flask-RESTX resource constructors, and supports custom scopes for advanced use cases.

Use it for:

  • Build testable Flask applications by injecting mock dependencies instead of relying on global Flask objects during unit tests.
  • Manage database connections, caches, or service clients as request-scoped or singleton dependencies without global initialization.
  • Integrate Flask extensions through Injector modules instead of the typical global pattern.
  • Implement class-based views with constructor injection to avoid accessing globals in __init__ methods.
  • Decouple Flask route handlers from concrete implementations by injecting interfaces or abstract services.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Integrates dependency injection into Flask applications using the Injector framework, allowing you to inject dependencies into views, handlers, and other Flask components without relying on global objects.

Yes, with conditions. Flask-Injector is stable and well-suited for new Flask projects that prioritize testability and clean dependency management. However, the dormant maintenance status (last release 2023-07-27) means you should verify compatibility with your target Flask and Injector versions before committing. If your project requires active upstream support or frequent dependency updates, consider whether the risk of stale maintenance is acceptable. For established projects with fixed dependencies, it remains a solid choice.

Install

flask-injector on PyPI

pip

pip install flask-injector

uv

uv add flask-injector

poetry

poetry add flask-injector

Installing Flask-Injector

Before you install

Low install friction with a pure-Python wheel distribution. Maintenance is dormant—last release was 2023-07-27, but the package is marked Production/Stable and has 282 repository stars. Suitable for established projects that don't require active upstream development.

License in practice

Licensed under BSD (permissive), which allows commercial and private use with minimal restrictions. No notable licensing constraints for typical adoption.

Quickstart

pip install Flask-Injector

from flask import Flask
from flask_injector import FlaskInjector
from injector import inject

app = Flask(__name__)

@app.route('/example')
def example(some_dependency):
    return 'Injected'

def configure(binder):
    binder.bind(str, to='injected_value')

FlaskInjector(app=app, modules=[configure])
app.run()

Requires Flask 2.2.0 or greater and Injector 0.20.0 or greater; compatible with CPython 3.7+.

Verify before relying

  • Whether dormant maintenance (last commit 2024-05-08) poses compatibility risks with newer Flask or Injector versions.
  • Real-world performance impact of dependency injection overhead in high-throughput Flask applications.
  • Extent of community support or third-party maintenance if upstream development remains inactive.

Package facts

License BSD (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 3 — Flask, injector, typing
Maintenance dormant — 1,114 days since the last release
Last repo commit
First released
Downloads 106,151/month — #12,666 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: Flask_Injector-0.15.0-py2.py3-none-any.whl

Keywords: Dependency Injection, Flask

Development Status :: 5 - Production/StableFramework :: FlaskIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development :: LibrariesTopic :: Software Development :: TestingTopic :: Utilities

Tags

flask dependency injectioninjector for flaskflask-injectordependency injection framework flaskremove global objects flasktestable flask applicationsflask request scoped dependencies
dependency-injectiontesting-friendly

More Libraries packages