{"id":46475911,"url":"https://github.com/surquest/python-fastapi-utils","last_synced_at":"2026-03-06T07:01:55.326Z","repository":{"id":65209962,"uuid":"587866568","full_name":"surquest/python-fastapi-utils","owner":"surquest","description":"Utilities for FastAPi as: Catcher + Middleware and Router","archived":false,"fork":false,"pushed_at":"2025-11-30T16:39:16.000Z","size":139,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-02T23:58:28.773Z","etag":null,"topics":["fastapi","google-cloud-logging","google-cloud-trace","middleware"],"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/surquest.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":"2023-01-11T19:18:06.000Z","updated_at":"2025-11-30T16:38:33.000Z","dependencies_parsed_at":"2024-02-08T14:44:40.459Z","dependency_job_id":"117871d8-9cf4-4cab-aecb-ac5a60ee1c8d","html_url":"https://github.com/surquest/python-fastapi-utils","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"c4b6465e8a93452b097abe4ac45570226d20a969"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/surquest/python-fastapi-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surquest%2Fpython-fastapi-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surquest%2Fpython-fastapi-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surquest%2Fpython-fastapi-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surquest%2Fpython-fastapi-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surquest","download_url":"https://codeload.github.com/surquest/python-fastapi-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surquest%2Fpython-fastapi-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30164885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T04:43:31.446Z","status":"ssl_error","status_checked_at":"2026-03-06T04:40:30.133Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["fastapi","google-cloud-logging","google-cloud-trace","middleware"],"created_at":"2026-03-06T07:01:48.071Z","updated_at":"2026-03-06T07:01:55.271Z","avatar_url":"https://github.com/surquest.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![GitHub](https://img.shields.io/github/license/surquest/python-fastapi-utils?style=flat-square)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/surquest-fastapi-utils?style=flat-square)\n![PyPI](https://img.shields.io/pypi/v/surquest-fastapi-utils)\n\n# Introduction\n\nThis project provides collection of utilities for smooth integration of FastAPI framework with Google Cloud Platform services as logging and tracing.\n\nThe key features of this project are:\n\n* Logging to Cloud Logging\n* Tracing to Cloud Logging\n* Error Reporting via Cloud Logging\n* Custom middleware for configuration of logging\n* Custom exception handlers treating HTTP and validation exceptions\n* Custom routes for documentation and favicon\n* Custom responses with statuses `success`, `warning` and `error` and standardized error messages\n\n# Quick Start\n\nThis section shows how to use the utilities provided by this project:\n\n```python\n\"\"\"File main.py with FastAPI app\"\"\"\nimport os\nfrom fastapi.exceptions import RequestValidationError\nfrom starlette.exceptions import HTTPException\nfrom fastapi import FastAPI, Request, Query\n\n# import surquest modules and objects\nfrom surquest.fastapi.utils.route import Route  # custom routes for documentation and FavIcon\nfrom surquest.fastapi.utils.GCP.tracer import Tracer\nfrom surquest.fastapi.utils.GCP.logging import Logger\nfrom surquest.fastapi.schemas.responses import Response\nfrom surquest.fastapi.utils.GCP.middleware import LoggingMiddleware\nfrom surquest.fastapi.utils.GCP.catcher import (\n    catch_validation_exceptions,\n    catch_http_exceptions,\n)\n\nPATH_PREFIX = os.getenv('PATH_PREFIX','')\n\napp = FastAPI(\n    title=\"Exchange Rates ETL\",\n    openapi_url=F\"{PATH_PREFIX}/openapi.json\"\n)\n\n# add middleware\napp.add_middleware(LoggingMiddleware)\n\n# exception handlers\napp.add_exception_handler(HTTPException, catch_http_exceptions)\napp.add_exception_handler(RequestValidationError, catch_validation_exceptions)\n\n# custom routes to documentation and favicon\napp.add_api_route(path=F\"{PATH_PREFIX}/\", endpoint=Route.get_documentation, include_in_schema=False)\napp.add_api_route(path=PATH_PREFIX, endpoint=Route.get_favicon, include_in_schema=False)\n\n# custom route to illustrate logging and tracing\n@app.get(F\"{PATH_PREFIX}/users\")\nasync def get_users(\n    age: int = Query(\n        default=18,\n        description=\"Minimal age of the user\",\n        example=30,\n\n    ),\n):\n\n    with Tracer.start_span(\"Generate users\"):\n\n        users = [\n            {\"name\": \"John Doe\", \"age\": 30, \"email\": \"john@doe.com\"},\n            {\"name\": \"Will Smith\", \"age\": 42, \"email\": \"will@smith.com\"}\n        ]\n\n        Logger.info('Found %s users', len(users), extra={\"users\": users})\n\n    with Tracer.start_span(\"Filtering users\"):\n\n        output = []\n        excluded = []\n        Logger.debug(F\"Filtering users by age \u003e {age}\")\n\n        for user in users:\n\n            if user[\"age\"] \u003e age:\n                output.append(user)\n            else:\n                excluded.append(user)\n\n        Logger.debug(\n            'Number of excluded users: %s', len(excluded),\n            extra={\"excluded\": excluded}\n        )\n\n    return Response.set(data=output)\n```\n\nThe endpoint `/users` will return the following standard response:\n\n```json\n{\n  \"info\": {\n    \"status\": \"success\"\n  },\n  \"data\": [\n    {\n      \"name\": \"John Doe\",\n      \"age\": 30,\n      \"email\": \"john@doe.com\"\n    },\n    {\n      \"name\": \"Will Smith\",\n      \"age\": 42,\n      \"email\": \"will@smith.com\"\n    }\n  ]\n}\n```\n\nand the logs will are available in Google Cloud Platform console within Stackdriver Logging:\n\n![Log Entries](https://github.com/surquest/python-fastapi-utils/blob/main/assets/img/logs.png?raw=true)\n\nas well as the traces are available in Google Cloud Platform console within Stackdriver Trace:\n\n![Trace](https://github.com/surquest/python-fastapi-utils/blob/main/assets/img/trace.png?raw=true)\n\n\n# Local development\n\nYou are more than welcome to contribute to this project. To make your start easier we have prepared a docker image with all the necessary tools to run it as interpreter for Pycharm or to run tests.\n\n\n## Build docker image\n```\ndocker build `\n     --tag surquest/fastapi/utils `\n     --file package.base.dockerfile `\n     --target test .\n```\n\n## Run tests\n```\ndocker run --rm -it `\n -v \"${pwd}:/opt/project\" `\n -e \"GOOGLE_APPLICATION_CREDENTIALS=/opt/project/credentials/keyfile.json\" `\n -w \"/opt/project/test\" `\n surquest/fastapi/utils pytest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurquest%2Fpython-fastapi-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurquest%2Fpython-fastapi-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurquest%2Fpython-fastapi-utils/lists"}