Registry / auth-security / krb5
library0.10.0pypypiunverified

krb5 is a Python library that provides direct bindings to the MIT Kerberos 5 C API, enabling Python applications to interact with Kerberos for authentication and security services at a low level. The current version is 0.9.0, with regular releases (typically a few times a year) maintaining compatibility and extending its API coverage.

pip install krb5
INSTALL
IMPORT
SIG · KRB5
K
krb5
auth-securitypythonv0.10.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

krb5
import krb5
The primary module containing functions that mirror the C API (with the 'krb5_' prefix removed).
Krb5Error
from krb5.exceptions import Krb5Error
The custom exception class raised for Kerberos API errors.

This example demonstrates how to initialize a Kerberos context and parse a principal name using the krb5 library. It includes basic error handling for `Krb5Error` which wraps the underlying Kerberos C API errors. It's crucial to have system Kerberos development libraries installed for this to build and run successfully.

import krb5 from krb5.exceptions import Krb5Error import os try: # Initialize a Kerberos context ctx = krb5.init_context() print("Kerberos context initialized successfully.") # Example: Parse a principal name # Replace 'testuser@EXAMPLE.COM' with a valid principal in your Kerberos environment # or set KRB5_PRINCIPAL environment variable for example. principal_name = os.environ.get('KRB5_PRINCIPAL', 'host/localhost@REALM.TEST') # Using with statement ensures proper cleanup of the context and principal with ctx: with krb5.parse_name(ctx, principal_name) as principal: print(f"Parsed principal: {principal.name}") print(f"Principal Realm: {principal.realm}") except Krb5Error as e: print(f"Kerberos Error: {e.message} (Code: {e.error_code})") print("Ensure Kerberos is configured correctly and system libraries are installed.") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingPython version support is frequently updated. Version 0.9.0 requires Python 3.9+ (dropped 3.8 in v0.8.0). Prior versions 0.7.0 and 0.4.0 also dropped support for Python 3.7 and 3.6, respectively.
fix
Ensure your Python environment meets the minimum version requirement for the krb5 library you intend to use. Upgrade Python if necessary.
affects: >=0.4.0
breakingSince version 0.4.0, Cython is a mandatory build dependency. The source distribution (sdist) no longer includes the pre-compiled `.c` files, requiring Cython to be available during installation.
fix
Ensure Cython is installed in your build environment (`pip install Cython`) before installing krb5 from source. When using pip, this should be handled automatically by PEP 517 build isolation.
affects: >=0.4.0
gotchaThis library provides low-level bindings to the Kerberos C API. For higher-level, more Pythonic interactions with Kerberos (especially involving GSSAPI), `python-gssapi` is often a more suitable and recommended library.
fix
Evaluate whether your use case requires direct C API interaction or if a higher-level library like `python-gssapi` would better suit your needs for Kerberos authentication workflows.
affects: All
gotchaWhile v0.9.0 adds support for Python Free-Threading (PEP 779), the library has limited testing in this scenario and 'does not aim to be thread safe out of the box'.
fix
If using krb5 in a free-threading environment, be aware of potential thread safety issues and test thoroughly. Consider external synchronization if multiple threads interact with the library concurrently.
affects: >=0.9.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'krb5'
The `krb5` Python package is not installed in the current environment or its installation failed previously, preventing Python from finding the module.
fix
Install the library using pip: `pip install krb5`.
fatal error: krb5.h: No such file or directory
The Kerberos development headers and libraries (`krb5-devel` or `libkrb5-dev`) are not installed on the system, which are required to compile the `krb5` Python extension from source.
fix
Install the Kerberos development package for your operating system (e.g., `sudo apt-get install libkrb5-dev` on Debian/Ubuntu, `sudo yum install krb5-devel` on RHEL/CentOS/Fedora, `brew install krb5` on macOS).
'Cannot find KDC for realm'
This error (typically within a `krb5.Krb5Error` exception) indicates that the Kerberos client cannot locate a Key Distribution Center for the specified realm, often due to a missing or misconfigured `/etc/krb5.conf` file or network issues.
fix
Verify that `/etc/krb5.conf` exists and is correctly configured with the `[realms]` and `[domain_realm]` sections pointing to your KDC, and ensure the KDC host is reachable.
'Preauthentication failed'
This error (typically within a `krb5.Krb5Error` exception) means the provided principal name or password is incorrect, or the Kerberos account is locked, expired, or requires a different authentication mechanism.
fix
Double-check the principal name and password for accuracy. Ensure the Kerberos account is active and not locked. Verify that the KDC supports the requested preauthentication method.
Upgrade
Version history
0.10.0latest on PyPI · released Aug 24, 2026
Audit
Dependencies
CythonrequiredRequired as a build dependency for compiling the C extensions.
MIT Kerberos 5 development librariesrequiredRequires the system's Kerberos 5 C API implementation and its header files (e.g., libkrb5-dev on Debian/Ubuntu, krb5-devel on RHEL/CentOS) and a C compiler.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources