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"}
Metadata
Release files for os2mo-fastapi-utils 1.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| os2mo_fastapi_utils-1.3.4.tar.gz | 12.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| os2mo_fastapi_utils-1.3.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.0 kB
Release files / os2mo_fastapi_utils-1.3.4.tar.gz
| Download URL | os2mo_fastapi_utils-1.3.4.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5758ce2120e3c9fddd581ff92266408505f5f1f0a69d5df97cfc2bbe3cbdc57
|
|
BLAKE2b-256 checksum How to use checksums |
54972a0d3f30a7a3375c84a70b23c402bced873da5d0117b1519fce65b6ad45f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.0 CPython/3.11.3 Linux/5.15.65+
|
Release files / os2mo_fastapi_utils-1.3.4-py3-none-any.whl
| Download URL | os2mo_fastapi_utils-1.3.4-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61eccb69a7efa49d0506b360712061524a4400544323d5d73bb18def6aaf86e2
|
|
BLAKE2b-256 checksum How to use checksums |
3c19ff6021731ece6ba1dbf7bc73a6198d9a0bb347db11c98547b8c8a7fb8f39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.0 CPython/3.11.3 Linux/5.15.65+
|