{"id":17254319,"url":"https://github.com/acwazz/fastapi-responseschema","last_synced_at":"2025-04-14T05:31:32.753Z","repository":{"id":51000922,"uuid":"517767612","full_name":"acwazz/fastapi-responseschema","owner":"acwazz","description":"☄️ Global response wrappers for FastAPI","archived":false,"fork":false,"pushed_at":"2024-11-01T18:41:50.000Z","size":1855,"stargazers_count":17,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T19:42:07.035Z","etag":null,"topics":["api-wrapper","backend","backend-development","fastapi","fastapi-extension","python"],"latest_commit_sha":null,"homepage":"https://acwazz.github.io/fastapi-responseschema/","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/acwazz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","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":"2022-07-25T17:53:31.000Z","updated_at":"2025-03-11T15:30:32.000Z","dependencies_parsed_at":"2024-01-03T10:46:23.693Z","dependency_job_id":"6803be18-a3e1-46ad-818f-4480d8448848","html_url":"https://github.com/acwazz/fastapi-responseschema","commit_stats":{"total_commits":86,"total_committers":3,"mean_commits":"28.666666666666668","dds":"0.41860465116279066","last_synced_commit":"291a8d8e178f72446bc455030d3ad3adc3557c74"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acwazz%2Ffastapi-responseschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acwazz%2Ffastapi-responseschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acwazz%2Ffastapi-responseschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acwazz%2Ffastapi-responseschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acwazz","download_url":"https://codeload.github.com/acwazz/fastapi-responseschema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248826592,"owners_count":21167718,"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-wrapper","backend","backend-development","fastapi","fastapi-extension","python"],"created_at":"2024-10-15T07:08:22.242Z","updated_at":"2025-04-14T05:31:32.453Z","avatar_url":"https://github.com/acwazz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ☄️ FastAPI Response Schema\n[![PyPI](https://img.shields.io/pypi/v/fastapi-responseschema)](https://pypi.org/project/fastapi-responseschema/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fastapi-responseschema)](https://pypi.org/project/fastapi-responseschema/) [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/acwazz/fastapi-responseschema)](https://github.com/acwazz/fastapi-responseschema/releases) [![Commits](https://img.shields.io/github/last-commit/acwazz/fastapi-responseschema)](https://github.com/acwazz/fastapi-responseschema/commit/master) [![Tests](https://github.com/acwazz/fastapi-responseschema/actions/workflows/test.yml/badge.svg)](https://github.com/acwazz/fastapi-responseschema/actions/workflows/test.yml)[![Lint](https://github.com/acwazz/fastapi-responseschema/actions/workflows/lint.yml/badge.svg)](https://github.com/acwazz/fastapi-responseschema/actions/workflows/lint.yml)\n\n\n## Overview\nThis package extends the [FastAPI](https://fastapi.tiangolo.com/) response model schema allowing you to have a common response wrapper via a `fastapi.routing.APIRoute`.\n\nThis library supports Python versions **\u003e=3.8** and FastAPI versions **\u003e=0.89.1**.\n\n\n## Getting started\n\n### Install the package\n```sh\npip install fastapi-responseschema\n```\n\nIf you are planning to use the pagination integration, you can install the package including [fastapi-pagination](https://github.com/uriyyo/fastapi-pagination)\n```sh\npip install fastapi-responseschema[pagination]\n```\n\n### Usage\n\n```py\nfrom typing import Generic, TypeVar, Any, Optional, List\nfrom pydantic import BaseModel\nfrom fastapi import FastAPI\nfrom fastapi_responseschema import AbstractResponseSchema, SchemaAPIRoute, wrap_app_responses\n\n\n# Build your \"Response Schema\"\nclass ResponseMetadata(BaseModel):\n    error: bool\n    message: Optional[str]\n\n\nT = TypeVar(\"T\")\n\n\nclass ResponseSchema(AbstractResponseSchema[T], Generic[T]):\n    data: T\n    meta: ResponseMetadata\n\n    @classmethod\n    def from_exception(cls, reason, status_code, message: str = \"Error\", **others):\n        return cls(\n            data=reason,\n            meta=ResponseMetadata(error=status_code \u003e= 400, message=message)\n        )\n\n    @classmethod\n    def from_api_route(\n        cls, content: Any, status_code: int, description: Optional[str] = None, **others\n    ):\n        return cls(\n            data=content,\n            meta=ResponseMetadata(error=status_code \u003e= 400, message=description)\n        )\n\n\n# Create an APIRoute\nclass Route(SchemaAPIRoute):\n    response_schema = ResponseSchema\n\n# Integrate in FastAPI app\napp = FastAPI()\nwrap_app_responses(app, Route)\n\nclass Item(BaseModel):\n    id: int\n    name: str\n\n\n@app.get(\"/items\", response_model=List[Item], description=\"This is a route\")\ndef get_operation():\n    return [Item(id=1, name=\"ciao\"), Item(id=2, name=\"hola\"), Item(id=3, name=\"hello\")]\n```\n\nTe result of `GET /items`:\n```http\nHTTP/1.1 200 OK\ncontent-length: 131\ncontent-type: application/json\n\n{\n    \"data\": [\n        {\n            \"id\": 1,\n            \"name\": \"ciao\"\n        },\n        {\n            \"id\": 2,\n            \"name\": \"hola\"\n        },\n        {\n            \"id\": 3,\n            \"name\": \"hello\"\n        }\n    ],\n    \"meta\": {\n        \"error\": false,\n        \"message\": \"This is a route\"\n    }\n}\n```\n\n\n## Docs\nYou can find detailed info for this package in the [Documentation](https://acwazz.github.io/fastapi-responseschema/).\n\n\n\n## Contributing\n\nContributions are very welcome!\n\n### How to contribute\nJust open an issue or submit a pull request on [GitHub](https://github.com/acwazz/fastapi-responseschema).\n\nWhile submitting a pull request describe what changes have been made.\n\nMore info on [Docs section](https://acwazz.github.io/fastapi-responseschema/contributing/)\n\n## Contributors Wall\n[![Contributors Wall](https://contrib.rocks/image?repo=acwazz/fastapi-responseschema)](https://github.com/acwazz/fastapi-responseschema/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facwazz%2Ffastapi-responseschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facwazz%2Ffastapi-responseschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facwazz%2Ffastapi-responseschema/lists"}