FusionAuth Python Client Library
Python Client Library
The Python client library allows you to integrate FusionAuth with your Python application.
Source code:
PyPI Package:
To install the FusionAuth Python Client package run:
pip install fusionauth-client
The following code assumes FusionAuth is running on http://localhost:9011
and uses an API key 6b87a398-39f2-4692-927b-13188a81a9a3
, you will need to supply your own API key, and if you are not running FusionAuth locally, your host parameter may be different.
Here is an example of using the create_user
method to create, and then the retrieveUserByEmail
method to retrieve the User by email address.
from fusionauth.fusionauth_client import FusionAuthClient
# You must supply your API key and URL here
client = FusionAuthClient('6b87a398-39f2-4692-927b-13188a81a9a3', 'http://localhost:9011')
user_request = {
'sendSetPasswordEmail': False,
'skipVerification': True,
'user': {
'email': 'art@vandaleyindustries.com',
'password': 'password'
}
}
client_response = client.create_user(None, user_request)
# Create a User
if client_response.was_successful():
print(client_response.success_response)
else:
print(client_response.error_response)
# Retrieve a user by email address
client_response = client.retrieve_user_by_email('art@vandaleyindustries.com')
if client_response.was_successful():
print(client_response.success_response)
else:
print(client_response.error_response)
Usage Suggestions
FusionAuth client libraries are a thin wrapper around the REST API. Client libraries are typically used in two different ways.
First, they can be used to access the FusionAuth APIs in a familiar format, leveraging language features like auto-completion. When used for this, they can be helpful to script FusionAuth configuration, automate common tasks, and create copies of existing applications, groups and more.
To use the client libraries effectively in this way, it is helpful to review the source code of the client library and the API documentation, which contains the JSON structure. The API documentation is very thorough about the JSON objects it expects as part of the payload as well as what parameters are required when.
Second, client libraries can exchange a token to let a user to log in via the Authorization Code Grant. This is a secondary use of these libraries. This process is best done by using a language specific OAuth library, which will work with FusionAuth. Here is a community curated list of such libraries.
Client libraries do not currently provide higher level functionality such as token management. Here is an open issue detailing some requested higher level functionality. Please feel free to file an issue or upvote this one if you desire it.
You can always directly call the REST API if the client library functionality doesn’t work for you. All the client libraries use the REST API.
In general, the request object will either be string parameters or a complex object depending on the type of API call being made. Any request object will be mapped by the library to a JSON object required by the corresponding API method. Examining the API documents for the operations you’re trying to call will therefore be useful, especially if you are using language without static typing.
The response object will typically contain:
- a status corresponding to the HTTP status code returned by the API. It may also be -1 if no HTTP request was successfully made
- a JSON success object if the call succeeded.
- a JSON error object with an intelligible message if the status code is
4xx
or5xx
. - an exception object if there was no HTTP request sent or there was no reasonable response from the server.
Example Apps
- Anonymous user example - Create a shadow or anonymous user account before full registration
- Flask profile portal - A user profile portal built with Flask
- Python Django and Google sign-in - a Django web application with user registration and authentication via FusionAuth and Google
- Python Django quickstart - Python Django quickstart tutorial showing how to integrate FusionAuth with a Python Django application
- Python Flask quickstart - Python Flask quickstart tutorial showing how to integrate FusionAuth with a Python Flask application
- python JWT - JWT creation and decoding examples with the python python-jwt library
- QR Code Example - An example Python/Flask application that uses an OAuth Device Code Grant workflow to log a user in and get them access and refresh tokens across devices.
- Wifi Hotspot - Controlling a hotspot via FusionAuth
Upgrade Policy
Besides the releases made to keep track of the FusionAuth API as mentioned above, SDKs and Client Libraries may periodically receive updates with bug fixes, security patches, tests, code samples, or documentation changes.
These releases may also update dependencies, language engines, and operating systems, as we’ll follow the deprecation and sunsetting policies of the underlying technologies that the libraries use.
This means that after a language, framework, or operating system is deprecated by their own maintainer, our SDKs and Client Libraries that depend on it will also be deprecated by us, and will eventually be updated to use a newer version.