--- id: flask-injector version: "0.15.0" license: BSD license_treatment: permissive maintenance: dormant --- # Flask-Injector — Adds Injector, a Dependency Injection framework, support to Flask. License: permissive · Maintenance: dormant · Downloads: 106.2K/mo ## 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 above — 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 pip install flask-injector uv add flask-injector 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 106.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags flask dependency injection, injector for flask, flask-injector, dependency injection framework flask, remove global objects flask, testable flask applications, flask request scoped dependencies, dependency-injection, testing-friendly [View on SkillFed](https://skillfed.io/packages/flask-injector) · [View on PyPI](https://pypi.org/project/flask-injector/)