Install & Compatibility
Where this runs
tested against v3.2.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
muslpy 3.10–3.925 runs
installs and imports cleanly · install 0.0s · import 0.227s · 18.9MB
glibcpy 3.10–3.925 runs
installs and imports cleanly · install 1.7s · import 0.208s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Consumer
✓ from openid.consumer import consumer
✗ from openid.consumer.consumer import Consumer
The 'consumer' module itself holds the Consumer class. Direct import from the module is generally preferred.
Server
✓ from openid.server import server
✗ from openid.server.server import Server
Similar to Consumer, the 'server' module holds the Server class.
FileOpenIDStore
✓ from openid.store import filestore
✗ import openid.store.filestore.FileOpenIDStore
FileOpenIDStore is within the 'filestore' module of the 'store' package.
This quickstart demonstrates initiating an OpenID consumer authentication flow. It initializes a Consumer object with a file-based store (not for production) and attempts to begin an authentication request for a placeholder OpenID URL. In a real web application, the `auth_request.redirectURL` would be used to redirect the user's browser to the OpenID Provider.
import os
from openid.consumer import consumer
from openid.store import filestore
# Create a file store for nonces and associations (NOT suitable for production)
store_path = "openid_store"
os.makedirs(store_path, exist_ok=True)
store = filestore.FileOpenIDStore(store_path)
# Initialize the consumer
oid_consumer = consumer.Consumer(store)
# Example: Begin OpenID authentication (conceptual example for a web app flow)
# In a real web application, this would involve user input and HTTP redirects.
user_openid_url = "https://openid.example.com/user/alice" # Replace with an actual OpenID Provider URL
try:
# This call prepares an authentication request.
# The actual redirect to the OpenID Provider (OP) happens in a web framework.
auth_request = oid_consumer.begin(user_openid_url)
# Simulate the redirect URL generation (in a real app, this would be returned to the client)
return_to_url = 'http://localhost:8000/verify'
trust_root = 'http://localhost:8000'
print(f"OpenID authentication initiated for {user_openid_url}")
print(f"User should be redirected to: {auth_request.redirectURL(return_to_url, trust_root)}")
except consumer.DiscoveryFailure as e:
print(f"OpenID discovery failed for {user_openid_url}: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# For demonstration purposes, you might clean up the store directory
# import shutil
# shutil.rmtree(store_path)
Debug
Known issues
breakingThe `python-openid` library (for Python 2) is distinct from `python3-openid` (for Python 3). While the internal `openid` package namespace is largely consistent, direct dependencies or custom integrations built for Python 2's `python-openid` will require careful migration.fixEnsure you are installing `python3-openid` on PyPI for Python 3 projects. Review any direct imports or interactions with the library's internal structure that might have changed between Python 2 and Python 3 standard library behavior.
affects: All versions (migration from Python 2)
gotchaThe default `openid.store.filestore.FileOpenIDStore` is not suitable for production environments. It lacks support for concurrency, distributed systems, and often requires specific file permissions, making it unreliable for web applications.fixFor production, implement a custom store (inheriting from `openid.store.interface.OpenIDStore`) that uses a robust database (e.g., PostgreSQL, MySQL) or a distributed key-value store (e.g., Redis). Consider using existing community-contributed store implementations if available for your chosen backend.
affects: All versions
gotchaThe OpenID 1.x/2.0 protocol, which `python3-openid` implements, is an older standard. For new authentication needs, consider modern alternatives like OpenID Connect (OIDC), which is built on OAuth 2.0 and offers more features, better security practices, and broader adoption.fixEvaluate your project's authentication requirements carefully. If OpenID 2.0 is specifically required for integration with existing providers, this library is appropriate. For new implementations, research OpenID Connect libraries and providers instead.
affects: All versions (contextual)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'openid'
The 'python3-openid' package is not installed or is not accessible in the current Python environment.
fixInstall the library using pip: `pip install python3-openid`
AttributeError: module 'openid.consumer' has no attribute 'begin'
The 'begin' method is part of an instance of the `openid.consumer.Consumer` class, not directly accessible from the module itself.
fixFirst, instantiate the `Consumer` class: `consumer = openid.consumer.Consumer(store, request_params)`. Then, call the method on the instance: `auth_request = consumer.begin(identity_url, return_to_url, realm)`.
ValueError: The return_to URL must be under the realm's control.
The `return_to` URL specified in the OpenID authentication request is not within the domain or path controlled by the `realm` URL, violating OpenID security requirements.
fixEnsure the `return_to` URL is a sub-path or on the same domain as the `realm` URL, or adjust the `realm` to encompass the `return_to` URL's domain.
openid.yadis.discover.DiscoveryFailure: No OpenID information found.
The provided identity URL does not contain the necessary OpenID discovery information (e.g., `<link>` tags for OpenID 1.x or XRDS document for OpenID 2.0).
fixVerify that the identity URL is correct and points to a valid OpenID provider, and that the provider's page correctly publishes OpenID discovery metadata.
AttributeError: 'str' object has no attribute 'get'
This error typically occurs when the `query_args` parameter passed to `openid.consumer.Consumer.complete()` is expected to be a dictionary-like object (e.g., from a web request's GET/POST parameters), but a string or other non-dictionary type was provided.
fixEnsure `query_args` is a dictionary or a dictionary-like object containing the OpenID response parameters, commonly obtained from your web framework's `request.GET` or `request.POST`.
Upgrade
Version history
3.2.0latest on PyPI · released Jun 29, 2020
Audit
Dependencies
No dependency data recorded yet.