Registry / auth-security / webauthn

webauthn

JSON →
library3.0.0pypypi✓ verified 23d ago

The `webauthn` library provides a Pythonic implementation for integrating WebAuthn (Web Authentication API) into web applications, enabling strong, phishing-resistant, and passwordless authentication. It handles the server-side verification and generation of WebAuthn credentials, abstracting away the complexities of the FIDO2 protocol. The library is actively maintained with a relatively frequent release cadence, with the current version being 2.7.1, and supports Python 3.9 and newer.

pip install webauthn
INSTALL
IMPORT
SIG · WEBAUTHN
W
webauthn
auth-securitypythonv3.0.0
Install
3.1s avg
Import
620ms
Disk
39MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
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
installs and imports cleanly · install 0.0s · import 0.638s · 40.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 0.602s · 41MB
39MB installed
● package 39MB
Code
Verified usage

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

generate_registration_options
from webauthn import generate_registration_options
verify_registration_response
from webauthn import verify_registration_response
generate_authentication_options
from webauthn import generate_authentication_options
verify_authentication_response
from webauthn import verify_authentication_response
options_to_json_dict
from webauthn.helpers import options_to_json_dict
from webauthn.helpers.options_to_json_dict import options_to_json_dict
The helper is exposed directly under `webauthn.helpers`.

This quickstart demonstrates how to generate registration options, which is the first step in registering a new WebAuthn credential. It uses placeholder values for RP (Relying Party) and user details. In a real application, these would be dynamic and securely managed. The generated options are then sent to the client-side JavaScript for interaction with the user's authenticator.

import os from webauthn import generate_registration_options from webauthn.helpers.structs import PublicKeyCredentialUserEntity # Placeholder values (in a real app, these would come from your user management) RP_ID = "localhost" # Or your domain, e.g., "example.com" RP_NAME = "My Awesome App" USER_ID = os.environ.get('WEBAUTHN_USER_ID', 'test_user_id').encode('utf-8') USER_NAME = os.environ.get('WEBAUTHN_USER_NAME', 'testuser') USER_DISPLAY_NAME = os.environ.get('WEBAAUTHN_USER_DISPLAY_NAME', 'Test User') user_entity = PublicKeyCredentialUserEntity( id=USER_ID, name=USER_NAME, display_name=USER_DISPLAY_NAME, ) registration_options = generate_registration_options( rp_id=RP_ID, rp_name=RP_NAME, user_entity=user_entity, challenge=os.urandom(16) # A new random challenge for each registration attempt ) print("Generated WebAuthn Registration Options:") print(registration_options) # In a real application, you would serialize these options (e.g., to JSON) # and send them to the client-side JavaScript for WebAuthn API calls.
Debug
Known issues
breakingThe minimum supported Python version was bumped to Python 3.9. Users on older Python versions (3.8 or below) will need to upgrade their Python environment to use `webauthn>=2.3.0`.
fix
Upgrade your Python environment to 3.9 or higher. For example, `pyenv install 3.9.18 && pyenv global 3.9.18`.
affects: >=2.3.0
gotchaSupport for ML-DSA (Post-Quantum Cryptography) public keys for authenticators was introduced, but it requires an optional dependency (`dilithium-py`). If you intend to support PQC-enabled authenticators, this dependency must be explicitly installed.
fix
Install the optional dependency: `pip install 'webauthn[pqc]'` or `pip install dilithium-py`.
affects: >=2.8.0-alpha1
gotchaThe `webauthn.helpers.options_to_json_dict` helper introduced a `bytes_encoder` argument. If not specified, `bytes` values are Base64URL encoded by default. Custom encoding logic might be required for specific client-side interoperability or if your application expects a different serialization format for byte arrays.
fix
Review your serialization needs. If a custom encoding is required, pass a `Callable[[bytes], Any]` to the `bytes_encoder` argument when calling `options_to_json_dict`.
affects: >=2.7.0
gotchaType annotations for bare `dict`s were replaced with `Dict[str, Any]` for stricter type checking. While this doesn't break runtime behavior, it might cause issues with type checkers (e.g., MyPy) in projects with strict configurations.
fix
Update your code to use `Dict[str, Any]` or other specific `dict` type hints where appropriate when interacting with the library's types, or adjust your type checker's configuration if necessary.
affects: >=2.7.1
Upgrade
Version history
3.0.0latest on PyPI · released Jun 29, 2026
Audit
Dependencies
dilithium-pyoptionalOptional dependency for supporting ML-DSA (Post-Quantum Cryptography) public keys for authenticators with PQC capabilities.
Agent activity
35 hits · last 30 days
node
30
OpenAI (training)
1
Resources
webauthn — pip install webauthn · libregistry