{"id":21351,"library":"flask-injector","title":"Flask-Injector","description":"Adds Injector, a Dependency Injection framework, support to Flask. Current version 0.15.0, maintained irregularly.","status":"active","version":"0.15.0","language":"python","source_language":"en","source_url":"https://github.com/alecthomas/flask_injector","tags":["flask","dependency-injection","injector","extensions"],"install":[{"cmd":"pip install flask-injector","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"note":"Flask extensions deprecated the flask.ext namespace in Flask 2.3.","wrong":"from flask.ext.injector import FlaskInjector","symbol":"FlaskInjector","correct":"from flask_injector import FlaskInjector"},{"note":"The @inject decorator is from the injector library, not flask-injector.","wrong":"from flask_injector import inject","symbol":"request","correct":"from injector import inject"}],"quickstart":{"code":"from flask import Flask, jsonify\nfrom flask_injector import FlaskInjector\nfrom injector import inject, singleton\n\nclass Greeter:\n    def greet(self, name: str) -> str:\n        return f'Hello, {name}!'\n\napp = Flask(__name__)\n\n@app.route('/')\n@inject\ndef home(greeter: Greeter):\n    return jsonify({'greeting': greeter.greet('World')})\n\ndef configure(binder):\n    binder.bind(Greeter, to=Greeter, scope=singleton)\n\nFlaskInjector(app=app, modules=[configure])\n\nif __name__ == '__main__':\n    app.run()","lang":"python","description":"Basic integration with Flask and Injector."},"warnings":[{"fix":"Replace 'from flask.ext.injector import FlaskInjector' with 'from flask_injector import FlaskInjector'.","message":"The 'flask.ext.injector' import pattern is deprecated and will break in Flask 2.3+. Use 'flask_injector' directly.","severity":"deprecated","affected_versions":"0.14.0+"},{"fix":"Always annotate parameters with the exact class type expected, not strings or unions.","message":"Injector uses static type hints for injection. If you omit type hints or use incorrect ones, injection may fail silently.","severity":"gotcha","affected_versions":"all"},{"fix":"Initialize FlaskInjector right after creating the Flask app and before returning it from the factory function.","message":"You must call FlaskInjector(app=app) before any request is handled. If called after route registration, dependencies may not be resolved inside views.","severity":"gotcha","affected_versions":"all"},{"fix":"Use a function with a binder parameter, or a class implementing configure().","message":"Injector 0.18+ changed the way modules are configured. If you use older patterns like 'modules=[lambda binder: binder.bind(...)]', this still works, but future versions may drop support.","severity":"breaking","affected_versions":"flask-injector 0.15.0 uses injector ~=0.12"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use 'from flask_injector import FlaskInjector' instead.","cause":"The flask.ext namespace is deprecated and removed in Flask 2.3.","error":"ImportError: cannot import name 'FlaskInjector' from 'flask.ext.injector'"},{"fix":"Import inject: from injector import inject","cause":"Importing @inject from flask_injector instead of injector.","error":"TypeError: 'module' object is not callable when using @inject"},{"fix":"Ensure FlaskInjector(app=app) is called after app creation and before first request.","cause":"FlaskInjector not initialized or app object not passed correctly.","error":"AssertionError: No application found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}