Skip to main content

FastAPI Keycloak Integration

Py3.9 Py3.10 Py3.11 Py3.12

Introduction

Welcome to fastapi-keycloak. This projects goal is to ease the integration of Keycloak (OpenID Connect) with Python, especially FastAPI. FastAPI is not necessary but is encouraged due to specific features. Currently, this package supports only the password and the authorization_code. However, the get_current_user() method accepts any JWT that was signed using Keycloak´s private key.

Docs

Docs are available at https://fastapi-keycloak.code-specialist.com/.

TLDR

FastAPI Keycloak enables you to do the following things without writing a single line of additional code:

  • Verify identities and roles of users with Keycloak
  • Get a list of available identity providers
  • Create/read/delete users
  • Create/read/delete roles
  • Create/read/delete/assign groups (recursive). Thanks to @fabiothz
  • Assign/remove roles from users
  • Implement the password or the authorization_code flow (login/callback/logout)

Contributions

We would like encourage anyone using this package to contribute to its improvement, if anything isn't working as expected or isn't well enough documented, please open an issue or a pull request. Please note that for any code contribution tests are required.

Testing

Tests are stored and executed in ./tests. To test the package, it is necessary to use the start_infra.sh script upfront, to set up Keycloak and Postgres. We do this to avoid artificial testing conditions that occur by mocking all the keycloak requests. The issue here is that we currently see no way to offer public testing opportunities without significant security issues, which is why you have to run these tests locally and provide a test_coverage.xml file. The test coverage is configured in the pytest.ini and will be created once the tests finished running (locally).

Original authors

Shoutout to the original authors of this project:

  • Yannic Schröer @yannicschroeer
  • Jonas Scholl @JonasScholl

This project was in the Code Specialist organization before being moved here.

Metadata

Release files for fastapi-keycloak 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-keycloak 1.1.1
File Size Uploaded
fastapi_keycloak-1.1.1.tar.gz 24.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-keycloak 1.1.1
File Interpreter ABI Platform
fastapi_keycloak-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 43.8 kB

Release files / fastapi_keycloak-1.1.1.tar.gz

Download URL fastapi_keycloak-1.1.1.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
81a3166257375de73b3ef8b9d7b402733c6c9401ce1f009464fba2e53d7a1cd4
BLAKE2b-256 checksum
How to use checksums
f71605ca4a6f85d66b523f048a24995102add4fad2e6ec2bd67cea707ff379b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2025.

Transparency log

Release files / fastapi_keycloak-1.1.1-py3-none-any.whl

Download URL fastapi_keycloak-1.1.1-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d36b6e2c790e8d1e496bb86a643394a635a21ff35953ae4470c1a767b66121d
BLAKE2b-256 checksum
How to use checksums
75f7d83ecea7f213df8f78cd8cbf31661cb296eca8fbd0feb1d558a56d064b55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2025.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page