{"id":15527286,"url":"https://github.com/dotx12/fastapi-gateway","last_synced_at":"2026-03-11T21:12:10.497Z","repository":{"id":57428493,"uuid":"397659355","full_name":"dotX12/fastapi-gateway","owner":"dotX12","description":"⚙️ FastAPI gateway for microservices.","archived":false,"fork":false,"pushed_at":"2023-10-24T10:37:30.000Z","size":73,"stargazers_count":118,"open_issues_count":7,"forks_count":29,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T00:18:27.664Z","etag":null,"topics":["api","apigateway","fastapi","gateway","python","rest"],"latest_commit_sha":null,"homepage":"","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/dotX12.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2021-08-18T16:00:27.000Z","updated_at":"2025-04-06T05:49:10.000Z","dependencies_parsed_at":"2024-10-31T08:04:13.546Z","dependency_job_id":"ce0406ce-b083-4b37-9566-044fb1b391e8","html_url":"https://github.com/dotX12/fastapi-gateway","commit_stats":{"total_commits":41,"total_committers":4,"mean_commits":10.25,"dds":"0.36585365853658536","last_synced_commit":"f657718b6bae2bb83b9dbf1337255366b4be17b0"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotX12%2Ffastapi-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotX12%2Ffastapi-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotX12%2Ffastapi-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotX12%2Ffastapi-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotX12","download_url":"https://codeload.github.com/dotX12/fastapi-gateway/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131318,"owners_count":21052820,"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":["api","apigateway","fastapi","gateway","python","rest"],"created_at":"2024-10-02T11:05:23.552Z","updated_at":"2026-03-11T21:12:10.439Z","avatar_url":"https://github.com/dotX12.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://scrutinizer-ci.com/g/dotX12/fastapi-gateway/badges/quality-score.png?b=master\" alt=\"https://scrutinizer-ci.com/g/dotX12/fastapi-gateway/\"\u003e\n\u003cimg src=\"https://scrutinizer-ci.com/g/dotX12/fastapi-gateway/badges/code-intelligence.svg?b=master\" alt=\"https://scrutinizer-ci.com/g/dotX12/fastapi-gateway/\"\u003e\n\u003cimg src=\"https://scrutinizer-ci.com/g/dotX12/fastapi-gateway/badges/build.png?b=master\" alt=\"https://scrutinizer-ci.com/g/dotX12/fastapi-gateway/\"\u003e\n\u003cimg src=\"https://badge.fury.io/py/fastapi-gateway.svg\" alt=\"https://badge.fury.io/py/fastapi-gateway\"\u003e\n\u003cimg src=\"https://pepy.tech/badge/fastapi-gateway\" alt=\"https://pepy.tech/project/fastapi-gateway\"\u003e\n\u003cimg src=\"https://pepy.tech/badge/fastapi-gateway/month\" alt=\"https://pepy.tech/project/fastapi-gateway\"\u003e\n\u003cimg src=\"https://img.shields.io/github/license/dotX12/fastapi-gateway.svg\" alt=\"https://github.com/dotX12/fastapi-gateway/blob/master/LICENSE\"\u003e\n\n# ⚙️ fastapi-gateway is async single entry point for microservices.\n\n#### API Gateway performs many tasks: accepts, processes and distributes requests, controls traffic, monitors and controls access and security, caching, throttling.\n\nInitially, this project was created for myself, I needed to implement identification, authentication and authorization. In the future, there was a need to limit requests for each user on every endpoint, create API plans. There were a lot of microservices and to keep in each microservice the logic for limiting endpoints, security logic, logging etc. - meaningless. Therefore, all this functionality is located at a single entry point, which already implements all the necessary tasks with security, limiting, etc., while microservices now directly solve their tasks.\n\n## 💿 Installation\n\n```\npip install fastapi_gateway\n```\n\n## ❗️ Benchmark\n1.5k - 3k RPC.\n\n```\ngitshit@git ~ % wrk -t 4 -c 40 http://gateway.localtest.me:8003/gateway_endpoint/path_param/12\nRunning 10s test @ http://gateway.localtest.me:8003/gateway_endpoint/path_param/12\n  4 threads and 40 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency    30.11ms   33.65ms 312.55ms   95.98%\n    Req/Sec   395.03    218.80     0.89k    73.21%\n  15550 requests in 10.05s, 2.31MB read\nRequests/sec:   1547.81\nTransfer/sec:    235.81KB\n```\n\n## 💻 Example\n\n\u003cdetails\u003e \n\u003csummary\u003e\n\u003ccode\u003eExample of use (long code)\u003c/code\u003e\n\u003c/summary\u003e\n\u003cbr\u003e\n\n```python3\nfrom starlette import status\nfrom starlette.requests import Request\nfrom starlette.responses import Response\nfrom fastapi_gateway import route\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\nfrom fastapi import Depends\nfrom fastapi.security import APIKeyHeader\nfrom starlette import status\nfrom starlette.exceptions import HTTPException\n\napp = FastAPI(title='API Gateway')\nSERVICE_URL = \"http://microservice.localtest.me:8002\"\n\nAPI_KEY_NAME = \"x-api-key\"\n\napi_key_header = APIKeyHeader(\n    name=API_KEY_NAME,\n    auto_error=False\n)\n\n\ndef check_api_key(key: str = Depends(api_key_header)):\n    if key:\n        return key\n    raise HTTPException(\n        status_code=status.HTTP_401_UNAUTHORIZED,\n        detail=\"You didn't pass the api key in the header! Header: x-api-key\",\n    )\n\n\nclass FooModel(BaseModel):\n    example_int: int\n    example_str: str\n\n\n@route(\n    request_method=app.post,\n    service_url=SERVICE_URL,\n    gateway_path='/query_and_body_path/{path}',\n    service_path='/v1/query_and_body_path/{path}',\n    query_params=['query_int', 'query_str'],\n    body_params=['test_body'],\n    status_code=status.HTTP_200_OK,\n    tags=['Query', 'Body', 'Path'],\n    dependencies=[\n        Depends(check_api_key)\n    ],\n)\nasync def check_query_params_and_body(\n        path: int, query_int: int, query_str: str,\n        test_body: FooModel, request: Request, response: Response\n):\n    pass\n  ```\n\n\u003c/details\u003e\n\n#### See more examples here:  \n##### [Tests and instructions for launch](../master/tests)  \n##### [Souce code Gateway](../master/tests/fastapi_gateway_service)  \n##### [Souce code Microservice #1](../master/tests/fastapi_microservice)  \n\n ## 🪛 How to use?\n\n- **request_method** -  is a callable (like app.get, app.post, foo_router.patch and so on.).  \n- **service_url** - the path to the endpoint on another service (like \"https://microservice1.example.com\").  \n- **service_path** - the path to the method in microservice (like \"/v1/microservice/users\").  \n- **gateway_path** - is the path to bind gateway.  \nFor example, your gateway api is located here - *https://gateway.example.com* and the path to endpoint (**gateway_path**) - \"/users\" then the full way to this method will be - *https://gateway.example.com/users*\n- **override_headers** - Boolean value allows you to return all the headlines that were created by microservice in gateway.  \n- **query_params** - used to extract query parameters from endpoint and transmission to microservice\n- **form_params** -  used to extract form model parameters from endpoint and transmission to microservice\n- **param body_params** - used to extract body model from endpoint and transmission to microservice\n\n⚠️ - **Be sure to transfer the name of the argument to the router, which is in the endpoint func!**  \n\n```\nquery_params - List[Query]\nbody_params - List[Body]\nform_params - List[File, Form]\n ```\n\n\u003cdetails\u003e \n\u003csummary\u003e\n\u003ccode\u003eIn more detail how to transmit body, form and query (photo)\u003c/code\u003e\n\u003c/summary\u003e\n\u003cbr\u003e\n\u003cimg width=\"450\" height=\"456\" src=\"https://user-images.githubusercontent.com/64792903/130335866-82be1684-cd54-43d3-8e0e-4013176a352a.jpg\"\u003e\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotx12%2Ffastapi-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotx12%2Ffastapi-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotx12%2Ffastapi-gateway/lists"}