-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d086d4
commit 3b5a778
Showing
1 changed file
with
92 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
"tags": [] | ||
}, | ||
"source": [ | ||
"**Author:** [Firstname Lastname]()" | ||
"**Author:** [SaiKiran M](www.linkedin.com/in/msaikiran9)" | ||
] | ||
}, | ||
{ | ||
|
@@ -63,7 +63,7 @@ | |
"tags": [] | ||
}, | ||
"source": [ | ||
"**Description:** This notebook will demonstrate how to use the Appwrite Python SDK to create a authentication and have options to `create_user`, `delete_user`, `list_all_users` as individual routines. It is usefull for organizations that need to manage user authentication." | ||
"**Description:** This notebook will demonstrate how to use the Appwrite Python SDK to create a authentication and have options to `create_user`, `delete_user`, `list_all_users` as individual routines. It is useful for organizations that need to manage user authentication." | ||
] | ||
}, | ||
{ | ||
|
@@ -74,7 +74,9 @@ | |
"tags": [] | ||
}, | ||
"source": [ | ||
"**References:**\n- [Appwrite Python SDK](https://github.com/appwrite/sdk-for-python)\n- [Appwrite Documentation](https://appwrite.io/docs)" | ||
"**References:**\n", | ||
"- [Appwrite Python SDK](https://github.com/appwrite/sdk-for-python)\n", | ||
"- [Appwrite Documentation](https://appwrite.io/docs)" | ||
] | ||
}, | ||
{ | ||
|
@@ -107,8 +109,17 @@ | |
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "import appwrite", | ||
"outputs": [] | ||
"outputs": [], | ||
"source": [ | ||
"try:\n", | ||
" import naas\n", | ||
" from appwrite.client import Client\n", | ||
" from appwrite.services.users import Users\n", | ||
"except ImportError:\n", | ||
" !pip install appwrite\n", | ||
" from appwrite.client import Client\n", | ||
" from appwrite.services.users import Users" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
|
@@ -118,7 +129,10 @@ | |
"tags": [] | ||
}, | ||
"source": [ | ||
"### Setup variables\n- `endpoint`: Appwrite endpoint URL\n- `project`: Appwrite project ID\n- `key`: Appwrite secret key" | ||
"### Setup variables\n", | ||
"- `endpoint`: Appwrite endpoint URL\n", | ||
"- `project`: Appwrite project ID\n", | ||
"- `key`: Appwrite secret key" | ||
] | ||
}, | ||
{ | ||
|
@@ -129,8 +143,12 @@ | |
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "endpoint = \"https://appwrite.io/v1\"\nproject = \"5f5d7e7c2c7d3\"\nkey = \"5f5d7e7c2c7d3\"", | ||
"outputs": [] | ||
"outputs": [], | ||
"source": [ | ||
"endpoint = naas.secret.get(name=\"endpoint\")\n", | ||
"project = naas.secret.get(name=\"project\")\n", | ||
"key = naas.secret.get(name=\"key\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
|
@@ -173,8 +191,34 @@ | |
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "# Initialize Appwrite client\nclient = appwrite.Client()\nclient.set_endpoint(endpoint)\nclient.set_project(project)\nclient.set_key(key)\n# Create user\nclient.users.create(\"John\", \"Doe\", \"[email protected]\", \"password\")", | ||
"outputs": [] | ||
"outputs": [], | ||
"source": [ | ||
"# Initialize Appwrite client\n", | ||
"client = Client()\n", | ||
"client.set_endpoint(endpoint)\n", | ||
"client.set_project(project)\n", | ||
"client.set_key(key)\n", | ||
"# Create user\n", | ||
"user_data = {\n", | ||
" 'userId': 'john-_doe123',\n", | ||
" 'email': '[email protected]',\n", | ||
" 'password': 'password',\n", | ||
" 'name': 'John Doe',\n", | ||
"}\n", | ||
"users=Users(client)\n", | ||
"try: #users.create take (username, email, mobileno, password) as arguments.\n", | ||
" user_details = users.create('msaik12', '[email protected]','+1234456666' ,'password')\n", | ||
" print(\"User Created!\")\n", | ||
" print(\"User Details:\")\n", | ||
" print(f\"User ID: {user_details['$id']}\")\n", | ||
" print(f\"Name: {user_details['name']}\")\n", | ||
" print(f\"Email: {user_details['email']}\")\n", | ||
" print(f\"Phone: {user_details['phone']}\")\n", | ||
" print(f\"Registration Date: {user_details['registration']}\")\n", | ||
" print(f\"Status: {'Active' if user_details['status'] else 'Inactive'}\")\n", | ||
"except: #make sure to provide different username everytime creating the user!\n", | ||
" print(\"User not created !\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
|
@@ -206,8 +250,16 @@ | |
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "# Initialize Appwrite client\nclient = appwrite.Client()\nclient.set_endpoint(endpoint)\nclient.set_project(project)\nclient.set_key(key)\n# Delete user\nclient.users.delete(\"[email protected]\")", | ||
"outputs": [] | ||
"outputs": [], | ||
"source": [ | ||
"#We already initialised the Appwrite client in the above cells\n", | ||
"# Delete user that's created above.\n", | ||
"try:\n", | ||
" users.delete(\"msaik12\")\n", | ||
" print('user deleted !')\n", | ||
"except:\n", | ||
" print(\"user not deleted / doesn't exist !!!\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
|
@@ -239,8 +291,21 @@ | |
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "# Initialize Appwrite client\nclient = appwrite.Client()\nclient.set_endpoint(endpoint)\nclient.set_project(project)\nclient.set_key(key)\n# List all users\nclient.users.list()", | ||
"outputs": [] | ||
"outputs": [], | ||
"source": [ | ||
"# List all users\n", | ||
"x=users.list()\n", | ||
"users = x.get('users', [])\n", | ||
"for user in users:\n", | ||
" print('User Details:')\n", | ||
" print(f'User ID: {user[\"$id\"]}')\n", | ||
" print(f'Name: {user[\"name\"]}')\n", | ||
" print(f'Email: {user[\"email\"]}')\n", | ||
" print(f'Phone: {user[\"phone\"]}')\n", | ||
" print(f'Registration Date: {user[\"registration\"]}')\n", | ||
" print(f'Status: {\"Active\" if user[\"status\"] else \"Inactive\"}')\n", | ||
" print('---')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
|
@@ -272,8 +337,18 @@ | |
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "# Display result\nprint(client.users.list())", | ||
"outputs": [] | ||
"outputs": [], | ||
"source": [ | ||
"for user in users:\n", | ||
" print('User Details:')\n", | ||
" print(f'User ID: {user[\"$id\"]}')\n", | ||
" print(f'Name: {user[\"name\"]}')\n", | ||
" print(f'Email: {user[\"email\"]}')\n", | ||
" print(f'Phone: {user[\"phone\"]}')\n", | ||
" print(f'Registration Date: {user[\"registration\"]}')\n", | ||
" print(f'Status: {\"Active\" if user[\"status\"] else \"Inactive\"}')\n", | ||
" print('---')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
|
@@ -315,4 +390,4 @@ | |
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} | ||
} |