{"id":13424673,"url":"https://github.com/DeanWay/fastapi-versioning","last_synced_at":"2025-03-15T18:35:43.084Z","repository":{"id":39614223,"uuid":"225489725","full_name":"DeanWay/fastapi-versioning","owner":"DeanWay","description":"api versioning for fastapi web applications","archived":false,"fork":false,"pushed_at":"2023-07-25T14:20:52.000Z","size":76,"stargazers_count":690,"open_issues_count":35,"forks_count":65,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-27T19:44:14.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DeanWay.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}},"created_at":"2019-12-02T23:40:07.000Z","updated_at":"2025-02-24T07:22:55.000Z","dependencies_parsed_at":"2024-01-03T02:29:55.308Z","dependency_job_id":"22b1c641-44d1-4cc8-b73c-db2ce3778010","html_url":"https://github.com/DeanWay/fastapi-versioning","commit_stats":{"total_commits":71,"total_committers":16,"mean_commits":4.4375,"dds":0.4084507042253521,"last_synced_commit":"18d480f5bb067088f157f235a673cb4c65ec77d5"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeanWay%2Ffastapi-versioning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeanWay%2Ffastapi-versioning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeanWay%2Ffastapi-versioning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeanWay%2Ffastapi-versioning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeanWay","download_url":"https://codeload.github.com/DeanWay/fastapi-versioning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243775913,"owners_count":20346285,"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":[],"created_at":"2024-07-31T00:00:57.619Z","updated_at":"2025-03-15T18:35:38.061Z","avatar_url":"https://github.com/DeanWay.png","language":"Python","readme":"# fastapi-versioning\napi versioning for fastapi web applications\n\n# Installation\n\n`pip install fastapi-versioning`\n\n## Examples\n```python\nfrom fastapi import FastAPI\nfrom fastapi_versioning import VersionedFastAPI, version\n\napp = FastAPI(title=\"My App\")\n\n\n@app.get(\"/greet\")\n@version(1, 0)\ndef greet_with_hello():\n    return \"Hello\"\n\n\n@app.get(\"/greet\")\n@version(1, 1)\ndef greet_with_hi():\n    return \"Hi\"\n\n\napp = VersionedFastAPI(app)\n```\n\nthis will generate two endpoints:\n```\n/v1_0/greet\n/v1_1/greet\n```\nas well as:\n```\n/docs\n/v1_0/docs\n/v1_1/docs\n/v1_0/openapi.json\n/v1_1/openapi.json\n```\n\nThere's also the possibility of adding a set of additional endpoints that\nredirect the most recent API version. To do that make the argument\n`enable_latest` true:\n\n```python\napp = VersionedFastAPI(app, enable_latest=True)\n```\n\nthis will generate the following additional endpoints:\n```\n/latest/greet\n/latest/docs\n/latest/openapi.json\n```\nIn this example, `/latest` endpoints will reflect the same data as `/v1.1`.\n\nTry it out:\n```sh\npip install pipenv\npipenv install --dev\npipenv run uvicorn example.annotation.app:app\n# pipenv run uvicorn example.folder_name.app:app\n```\n\n## Usage without minor version\n```python\nfrom fastapi import FastAPI\nfrom fastapi_versioning import VersionedFastAPI, version\n\napp = FastAPI(title='My App')\n\n@app.get('/greet')\n@version(1)\ndef greet():\n  return 'Hello'\n\n@app.get('/greet')\n@version(2)\ndef greet():\n  return 'Hi'\n\napp = VersionedFastAPI(app,\n    version_format='{major}',\n    prefix_format='/v{major}')\n```\n\nthis will generate two endpoints:\n```\n/v1/greet\n/v2/greet\n```\nas well as:\n```\n/docs\n/v1/docs\n/v2/docs\n/v1/openapi.json\n/v2/openapi.json\n```\n\n## Extra FastAPI constructor arguments\n\nIt's important to note that only the `title` from the original FastAPI will be\nprovided to the VersionedAPI app. If you have any middleware, event handlers\netc these arguments will also need to be provided to the VersionedAPI function\ncall, as in the example below\n\n```python\nfrom fastapi import FastAPI, Request\nfrom fastapi_versioning import VersionedFastAPI, version\nfrom starlette.middleware import Middleware\nfrom starlette.middleware.sessions import SessionMiddleware\n\napp = FastAPI(\n    title='My App',\n    description='Greet uses with a nice message',\n    middleware=[\n        Middleware(SessionMiddleware, secret_key='mysecretkey')\n    ]\n)\n\n@app.get('/greet')\n@version(1)\ndef greet(request: Request):\n    request.session['last_version_used'] = 1\n    return 'Hello'\n\n@app.get('/greet')\n@version(2)\ndef greet(request: Request):\n    request.session['last_version_used'] = 2\n    return 'Hi'\n\n@app.get('/version')\ndef last_version(request: Request):\n    return f'Your last greeting was sent from version {request.session[\"last_version_used\"]}'\n\napp = VersionedFastAPI(app,\n    version_format='{major}',\n    prefix_format='/v{major}',\n    description='Greet users with a nice message',\n    middleware=[\n        Middleware(SessionMiddleware, secret_key='mysecretkey')\n    ]\n)\n```\n","funding_links":[],"categories":["Third-Party Extensions","Python","Packages"],"sub_categories":["Developer Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeanWay%2Ffastapi-versioning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDeanWay%2Ffastapi-versioning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeanWay%2Ffastapi-versioning/lists"}