This example demonstrates how to use the Zarban SDK to implement a user signup process. The example shows how to create a new user account by sending a signup request to the Zarban API.
Before running this example, make sure you have:
- Installed the Zarban SDK:
pip install zarban
- Access to the Zarban API (test environment)
import zarban.wallet.openapi_client as wallet
def signup_example():
# Create and configure the Configuration object
cfg = wallet.Configuration(
host="https://testwapi.zarban.io"
)
# Create an instance of the ApiClient with the configuration
api_client = wallet.ApiClient(configuration=cfg)
# Create an instance of the AuthApi using the api_client
auth_api = wallet.AuthApi(api_client)
# Prepare the signup request data
signup_request = wallet.SignUpRequest(
email="[email protected]",
password="yourSecuredPassword",
)
try:
# Call the signup API
api_response = auth_api.signup_with_email_and_password(signup_request)
print("Confirmation link sent successfully!")
print(f"Message: {api_response.messages}")
except wallet.ApiException as e:
print(f"Exception when calling auth_api->signup_with_email_and_password: {e}")
print(f"Error message: {e.body}")
if __name__ == "__main__":
signup_example()
-
Import Required Modules
import zarban.wallet.openapi_client as wallet
These imports provide the necessary classes and functions to interact with the Zarban API.
-
Configure the API Client
cfg = wallet.Configuration( host="https://testwapi.zarban.io" ) api_client = wallet.ApiClient(configuration=cfg)
Creates a configuration object with the API endpoint and initializes the API client.
-
Initialize the API Instance
auth_api = wallet.AuthApi(api_client)
Creates an instance of the AuthApi class using the configured client.
-
Prepare Signup Request
signup_request = wallet.SignUpRequest( email="[email protected]", password="yourSecuredPassword", )
Creates a signup request object with user credentials.
-
Make the API Call
api_response = auth_api.signup_with_email_and_password(signup_request)
Sends the signup request to the API and handles the response.
The example includes error handling using try/except blocks:
- On success: Prints a confirmation message and the response messages
- On failure: Catches
ApiException
and prints the error details
On successful signup:
Confirmation link sent successful!
Message: [Confirmation email details...]
On error:
Exception when calling DefaultApi->auth_signup_post: [Error details]
Error message: [Detailed error message]
- Replace
"[email protected]"
and"yourSecuredPassword"
with actual user credentials - The example uses the test API endpoint (
testwapi.zarban.io
). For production use, update the host accordingly - Ensure proper password security practices when implementing in production
- The API will send a confirmation email to the provided email address
Common errors that might occur:
- Invalid email format
- Password doesn't meet security requirements
- Email already registered
- Network connectivity issues
- API server errors