os2mo-fastapi-utils


Nameos2mo-fastapi-utils JSON
Version 1.3.4 PyPI version JSON
download
home_pagehttps://magenta.dk/
SummaryFastAPI utils for os2mo
upload_time2023-05-23 16:15:06
maintainer
docs_urlNone
authorMagenta
requires_python>=3.10,<4.0
licenseMPL-2.0
keywords os2mo-fastapi-utils os2mo fastapi utils
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--
SPDX-FileCopyrightText: Magenta ApS

SPDX-License-Identifier: MPL-2.0
-->

# OS2MO-FastAPI-Utils

Utility library with various reusable FastAPI components.


## Instrumentation Usage
Install into your project using `pip`:
```
pip install os2mo-fastapi-utils
```

Then import it inside a Python file:
```
from fastapi import FastAPI
from os2mo_fastapi_utils.tracing import setup_instrumentation

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

app = setup_instrumentation(app)
```


## Keycloak Autentication

The `auth` package in this module provides a Keycloak auth `Depends` coroutine
for FastAPI. Do (e.g.) the following to use this in FastAPI:
```
from fastapi import FastAPI, Depends
from structlog import get_logger

from os2mo_fastapi_utils.auth.exceptions import AuthenticationError
from os2mo_fastapi_utils.auth.oidc import get_auth_dependency
from os2mo_fastapi_utils.auth.oidc import get_auth_exception_handler
from myproject.models import MyToken

logger = get_logger()

auth = get_auth_dependency(
           host='keycloak',
           port=8081,
           realm='mo',
           token_url_path='service/token',
           token_model=MyToken
       )

app = FastAPI()
app.add_exception_handler(
    AuthenticationError,
    get_auth_exception_handler(logger)
)

@app.get("/")
async def root(token: Token = Depends(auth)):
    return {"message": "Hello World"}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://magenta.dk/",
    "name": "os2mo-fastapi-utils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "os2mo-fastapi-utils,os2mo,fastapi,utils",
    "author": "Magenta",
    "author_email": "info@magenta.dk",
    "download_url": "https://files.pythonhosted.org/packages/54/97/2a0d3f30a7a3375c84a70b23c402bced873da5d0117b1519fce65b6ad45f/os2mo_fastapi_utils-1.3.4.tar.gz",
    "platform": null,
    "description": "<!--\nSPDX-FileCopyrightText: Magenta ApS\n\nSPDX-License-Identifier: MPL-2.0\n-->\n\n# OS2MO-FastAPI-Utils\n\nUtility library with various reusable FastAPI components.\n\n\n## Instrumentation Usage\nInstall into your project using `pip`:\n```\npip install os2mo-fastapi-utils\n```\n\nThen import it inside a Python file:\n```\nfrom fastapi import FastAPI\nfrom os2mo_fastapi_utils.tracing import setup_instrumentation\n\napp = FastAPI()\n\n@app.get(\"/\")\nasync def root():\n    return {\"message\": \"Hello World\"}\n\napp = setup_instrumentation(app)\n```\n\n\n## Keycloak Autentication\n\nThe `auth` package in this module provides a Keycloak auth `Depends` coroutine\nfor FastAPI. Do (e.g.) the following to use this in FastAPI:\n```\nfrom fastapi import FastAPI, Depends\nfrom structlog import get_logger\n\nfrom os2mo_fastapi_utils.auth.exceptions import AuthenticationError\nfrom os2mo_fastapi_utils.auth.oidc import get_auth_dependency\nfrom os2mo_fastapi_utils.auth.oidc import get_auth_exception_handler\nfrom myproject.models import MyToken\n\nlogger = get_logger()\n\nauth = get_auth_dependency(\n           host='keycloak',\n           port=8081,\n           realm='mo',\n           token_url_path='service/token',\n           token_model=MyToken\n       )\n\napp = FastAPI()\napp.add_exception_handler(\n    AuthenticationError,\n    get_auth_exception_handler(logger)\n)\n\n@app.get(\"/\")\nasync def root(token: Token = Depends(auth)):\n    return {\"message\": \"Hello World\"}\n```\n",
    "bugtrack_url": null,
    "license": "MPL-2.0",
    "summary": "FastAPI utils for os2mo",
    "version": "1.3.4",
    "project_urls": {
        "Homepage": "https://magenta.dk/",
        "Repository": "https://git.magenta.dk/rammearkitektur/os2mo-fastapi-utils"
    },
    "split_keywords": [
        "os2mo-fastapi-utils",
        "os2mo",
        "fastapi",
        "utils"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c19ff6021731ece6ba1dbf7bc73a6198d9a0bb347db11c98547b8c8a7fb8f39",
                "md5": "ae68ff98fae92a097b559ae69d73a63c",
                "sha256": "61eccb69a7efa49d0506b360712061524a4400544323d5d73bb18def6aaf86e2"
            },
            "downloads": -1,
            "filename": "os2mo_fastapi_utils-1.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae68ff98fae92a097b559ae69d73a63c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 20332,
            "upload_time": "2023-05-23T16:15:03",
            "upload_time_iso_8601": "2023-05-23T16:15:03.910811Z",
            "url": "https://files.pythonhosted.org/packages/3c/19/ff6021731ece6ba1dbf7bc73a6198d9a0bb347db11c98547b8c8a7fb8f39/os2mo_fastapi_utils-1.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54972a0d3f30a7a3375c84a70b23c402bced873da5d0117b1519fce65b6ad45f",
                "md5": "4ffe60798a471427c478377dafd4a39b",
                "sha256": "a5758ce2120e3c9fddd581ff92266408505f5f1f0a69d5df97cfc2bbe3cbdc57"
            },
            "downloads": -1,
            "filename": "os2mo_fastapi_utils-1.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "4ffe60798a471427c478377dafd4a39b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 12636,
            "upload_time": "2023-05-23T16:15:06",
            "upload_time_iso_8601": "2023-05-23T16:15:06.696641Z",
            "url": "https://files.pythonhosted.org/packages/54/97/2a0d3f30a7a3375c84a70b23c402bced873da5d0117b1519fce65b6ad45f/os2mo_fastapi_utils-1.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-23 16:15:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "os2mo-fastapi-utils"
}
        
Elapsed time: 0.22002s