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 krb5Verified import paths — ran on the pinned version, not inferred.
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.
Ensure your Python environment meets the minimum version requirement for the krb5 library you intend to use. Upgrade Python if necessary.
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.
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.
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.
Install the library using pip: `pip install krb5`.
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).
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.
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.