{"id":16157720,"url":"https://github.com/leynier/fastapi-control","last_synced_at":"2025-03-18T20:30:54.832Z","repository":{"id":40486040,"uuid":"486856196","full_name":"leynier/fastapi-control","owner":"leynier","description":"FastAPI utility to implement class-based routing with controllers and dependency injection.","archived":false,"fork":false,"pushed_at":"2025-01-08T23:11:58.000Z","size":315,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T23:17:58.213Z","etag":null,"topics":["dependency-injection","fastapi","fastapi-controllers","fastapi-extension","kink","mit-license","opensource","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/fastapi-control","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leynier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-29T06:04:24.000Z","updated_at":"2025-01-08T23:11:55.000Z","dependencies_parsed_at":"2024-01-16T22:21:28.558Z","dependency_job_id":"45ccba45-9b66-4e48-9e2f-1892e5f21268","html_url":"https://github.com/leynier/fastapi-control","commit_stats":{"total_commits":30,"total_committers":3,"mean_commits":10.0,"dds":0.2666666666666667,"last_synced_commit":"835ec6011d6ea9f1870523a05340b5a30bbf1053"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leynier%2Ffastapi-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leynier%2Ffastapi-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leynier%2Ffastapi-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leynier%2Ffastapi-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leynier","download_url":"https://codeload.github.com/leynier/fastapi-control/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243950792,"owners_count":20373664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","fastapi","fastapi-controllers","fastapi-extension","kink","mit-license","opensource","python"],"created_at":"2024-10-10T01:50:25.589Z","updated_at":"2025-03-18T20:30:54.523Z","avatar_url":"https://github.com/leynier.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to FastAPI Control 👋\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)\n[![PyPI version fury.io](https://img.shields.io/pypi/v/fastapi-control.svg)](https://pypi.python.org/pypi/fastapi-control)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/fastapi-control.svg)](https://pypi.python.org/pypi/fastapi-control)\n[![Last commit](https://img.shields.io/github/last-commit/leynier/fastapi-control.svg?style=flat)](https://github.com/leynier/fastapi-control/commits)\n[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/leynier/fastapi-control)](https://github.com/leynier/fastapi-control/commits)\n[![Github Stars](https://img.shields.io/github/stars/leynier/fastapi-control?style=flat\u0026logo=github)](https://github.com/leynier/fastapi-control/stargazers)\n[![Github Forks](https://img.shields.io/github/forks/leynier/fastapi-control?style=flat\u0026logo=github)](https://github.com/leynier/fastapi-control/network/members)\n[![Github Watchers](https://img.shields.io/github/watchers/leynier/fastapi-control?style=flat\u0026logo=github)](https://github.com/leynier/fastapi-control)\n[![GitHub contributors](https://img.shields.io/github/contributors/leynier/fastapi-control)](https://github.com/leynier/fastapi-control/graphs/contributors)\n\nFastAPI utility to implement class-based routing with controllers and dependency injection.\n\n## Install\n\n```sh\npip install fastapi-control\n```\n\n## Usage\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_control import (\n    APIController,\n    add_controller,\n    add_controllers,\n    controller,\n    get,\n    inject,\n)\n\n\n# Optionally declares an abstraction\nclass GreeterAbstraction:\n    def greet(self):\n        raise NotImplementedError()\n\n\n# Implement the abstraction and make it available to the injection system\n# using the @inject decorator\n@inject(alias=GreeterAbstraction)\nclass GretterImplementation:\n    def greet(self):\n        return \"Hello, world!\"\n\n\n# It is also possible to implement without abstraction and make it available\n# to the injection system directly\n@inject()\nclass SpanishGretterImplementation:\n    def greet(self):\n        return \"Hola, mundo!\"\n\n\n@inject()\nclass NestedGretterImplementation:\n    # When the @inject decorator is used, the arguments of the __init__\n    # method are automatically injected (if the @inject decorator was used\n    # in the argument type declarations)\n    def __init__(self, spanish_gretter: SpanishGretterImplementation) -\u003e None:\n        self.gretter = spanish_gretter\n\n    def greet(self):\n        return self.gretter.greet()\n\n\n# With the @controller decorator and inheriting from APIController, we can\n# declare class-based routing (also called controller) and it has the same\n# parameters as FastAPI's APIRouter\n@controller(prefix=\"/home\")\nclass HomeController(APIController):\n    # When the @controller decorator is used, the arguments of the __init__\n    # method are automatically injected (if the @inject decorator was used\n    # in the argument type declarations)\n    def __init__(\n        self,\n        gretter: GreeterAbstraction,\n        spanish_gretter: SpanishGretterImplementation,\n        nested_gretter: NestedGretterImplementation,\n    ) -\u003e None:\n        self.gretter = gretter\n        self.spanish_gretter = spanish_gretter\n        self.nested_gretter = nested_gretter\n\n    # The @get decorator declares the method as a GET endpoint (there are\n    # also @post, @put, @delete, @patch decorators) and the behavior is the\n    # same as the corresponding FastAPI decorators.\n    @get(path=\"/greet\")\n    def get_greet(self):\n        return self.gretter.greet()\n\n    @get(path=\"/spanish_greet\")\n    def get_spanish_greet(self):\n        return self.spanish_gretter.greet()\n\n    @get(path=\"/nested_greet\")\n    def get_nested_greet(self):\n        return self.nested_gretter.greet()\n\n\napi = FastAPI()\n# Finally, it is necessary to add the controllers to the FastAPI instance\nadd_controllers(api)\n\n# If you want to have multiple FastAPI instances with different controllers,\n# you can use the add_controller method to add the desired controllers to\n# the desired FastAPI instance one by one.\nother_api = FastAPI()\nadd_controller(other_api, HomeController)\n```\n\n## Inspirations\n\nThis project is based on and inspired by the [NEXTX](https://github.com/adriangs1996/nextx.repository) and [FastApi-RESTful](https://github.com/yuval9313/FastApi-RESTful) projects.\n\nThe difference with [FastApi-RESTful](https://github.com/yuval9313/FastApi-RESTful) is that **FastAPI Control** implements an automatic dependency injection system independent of [FastAPI](https://fastapi.tiangolo.com).\n\nThe difference with [NEXTX](https://github.com/adriangs1996/nextx.repository) is that **FastAPI Control** only aims to solve the problem of class-based routes and automatic dependency injection, and uses the [kink](https://github.com/kodemore/kink) library for dependency injection which is still under maintenance while [NEXTX](https://github.com/adriangs1996/nextx.repository) uses [python-inject](https://github.com/ivankorobkov/python-inject) which has not been maintained since 2020.\n\nMany thanks to the creators and maintainers of those projects for providing inspiration and guidance for this one.\n\n## Authors\n\n👨🏻‍💻 **Leynier Gutiérrez González**\n\n* Website: [leynier.dev](https://leynier.dev)\n* LinkedIn: [@leynier](https://linkedin.com/in/leynier)\n* Github: [@leynier](https://github.com/leynier)\n* Twitter: [@leynier41](https://twitter.com/leynier41)\n\n## 🤝 Contributing\n\nContributions, issues and feature requests are welcome!\u003cbr /\u003eFeel free to check [issues page](https://github.com/leynier/fastapi-control/issues). You can also take a look at the [contributing guide](CONTRIBUTING.md).\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleynier%2Ffastapi-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleynier%2Ffastapi-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleynier%2Ffastapi-control/lists"}