{"id":17933826,"url":"https://github.com/jacobsvante/prodapi","last_synced_at":"2025-03-24T06:33:37.271Z","repository":{"id":57454941,"uuid":"352987120","full_name":"jacobsvante/prodapi","owner":"jacobsvante","description":"A thin layer on top of FastAPI to add some production readiness features.","archived":false,"fork":false,"pushed_at":"2021-04-09T15:30:39.000Z","size":319,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-18T09:32:47.218Z","etag":null,"topics":[],"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/jacobsvante.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-30T12:07:15.000Z","updated_at":"2023-12-02T07:22:47.000Z","dependencies_parsed_at":"2022-09-04T10:42:07.251Z","dependency_job_id":null,"html_url":"https://github.com/jacobsvante/prodapi","commit_stats":null,"previous_names":["jmagnusson/prodapi"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobsvante%2Fprodapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobsvante%2Fprodapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobsvante%2Fprodapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobsvante%2Fprodapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacobsvante","download_url":"https://codeload.github.com/jacobsvante/prodapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221941517,"owners_count":16905311,"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-10-28T21:41:55.383Z","updated_at":"2024-10-28T21:41:56.052Z","avatar_url":"https://github.com/jacobsvante.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prodapi\n\n[![Continuous Integration Status](https://github.com/jmagnusson/prodapi/actions/workflows/ci.yml/badge.svg)](https://github.com/jmagnusson/prodapi/actions/workflows/ci.yml)\n[![Continuous Delivery Status](https://github.com/jmagnusson/prodapi/actions/workflows/cd.yml/badge.svg)](https://github.com/jmagnusson/prodapi/actions/workflows/cd.yml)\n[![Python Versions](https://img.shields.io/pypi/pyversions/prodapi.svg)](https://pypi.org/project/prodapi/)\n[![Code Coverage](https://img.shields.io/codecov/c/github/jmagnusson/prodapi?color=%2334D058)](https://codecov.io/gh/jmagnusson/prodapi)\n[![PyPI Package](https://img.shields.io/pypi/v/prodapi?color=%2334D058\u0026label=pypi%20package)](https://pypi.org/project/prodapi)\n\nA thin layer on top of [FastAPI](https://fastapi.tiangolo.com/) with the following features:\n\n- Integrates with [FastAPI-Security](https://jmagnusson.github.io/fastapi-security/) to add a custom route `/users/me` (path is overridable)\n- Easily add CORS to your app by calling `app.with_basic_cors()`\n- Add health routes to the app via `app.with_health_routes()`. Adds a liveness route at `/__is-alive` and a readiness route at `/__is-ready` (both paths can be overridden). Useful together with [Kubernetes liveness and readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) for example.\n- And, thanks to FastAPI, all routes are automatically added to the API documentation\n\n## Installation\n\n```\npip install prodapi\n```\n\n## Example\n\n```python\nfrom prodapi import ProdAPI, ApiRouter, FastAPISecurity\n\n# First let's set up security, via FastAPI-Security\n\nsecurity = FastAPISecurity()\n\n# Set up HTTP Basic Auth\nsecurity.init_basic_auth([\n    {\"username\": \"johndoe\", \"password\": \"123\"},\n    {\"username\": \"janedoe\", \"password\": \"abc123\"},\n])\n\n# Set up OAuth2 and OIDC\n# NOTE: There is also `init_oauth2_through_jwks` in case OIDC is not available\nsecurity.init_oauth2_through_oidc(\n    \"https://my-auth0-tenant.eu.auth0.com/.well-known/openid-configuration\",\n)\n\n# Make sure that basic auth user `jane` and OAuth2 user\n# `p56OnzZb8KrWC9paxCyv8ylyB2flTIky@clients` gets all permissions automatically.\n# NOTE: For basic auth you have to set up permissions this way, for OAuth2 permissions\n#       will be automatically extracted from the incoming JWT token (via the key\n#       `permissions`, which might only be implemented for Auth0)\nsecurity.add_permission_overrides({\n    \"jane\": [\"*\"],\n    \"p56OnzZb8KrWC9paxCyv8ylyB2flTIky@clients\": [\"*\"],\n)\n\n# Now we're ready to create the app\n# NOTE: ProdAPI is just a thin layer on top of `fastapi.FastAPI`\napp = ProdAPI()\n\n# CORS - Allow any origins, methods and headers. Don't expose any headers.\napp.with_basic_cors()\n\n# Add routes `/__is-alive` and `/__is-ready`. Useful together with Kubernetes or similar\n# URL paths are configurable.\napp.with_health_routes()\n\n# Enable `/users/me` route to get info about the user. URL path is configurable.\napp.with_user_routes(security)\n\n# Create our app specific API router and our routes\nproducts_router = ApiRouter()\n\n@products_router.get(\"/products\")\ndef list_products():\n    return []\n\napp.include_router(products_router)\n\n# And we're done! Now just use uvicorn or similar to deploy.\n\n```\n\n## TODO\n1. Create cli utility (using [tiangolo typer](https://github.com/tiangolo/typer)?), which can generate:\n    1. A stub project using `prodapi`\n    1. Frontend (React?)\n    1. docker-compose.yml and Dockerfile\n    1. Kubernetes deployment files\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacobsvante%2Fprodapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacobsvante%2Fprodapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacobsvante%2Fprodapi/lists"}