def init_client(): # Initialize the Appwrite client client = Client() client.set_endpoint(os.getenv("APPWRITE_ENDPOINT")) client.set_project(os.getenv("APPWRITE_FUNCTION_PROJECT_ID")) client.set_key(os.getenv("APPWRITE_API_KEY")) return client
# Helper method to print green colored output. def print_green(prt): print("\033[32;1m" + str(prt) + "\033[0m") # Config # Read the docs at https://appwrite.io/docs to get more information # about API keys and Project IDs ENDPOINT = 'https://localhost/v1' PROJECT_ID = '<Project ID>' API_KEY = '<Secret API Key>' client = Client() client.set_endpoint(ENDPOINT) client.set_project(PROJECT_ID) client.set_key(API_KEY) collectionId = None userId = None # API Calls # - api.create_collection # - api.list_collection # - api.add_doc # - api.list_doc # - api.upload_file # - api.list_files
# Perform all your imports from appwrite.client import Client from appwrite.services.storage import Storage # Initialise the Appwrite client client = Client() client.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint client.set_project('5df5acd0d48c2') # Your project ID client.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key # Initialise the sttorage SDK with the client object storage = Storage(client) # Perform your task result = storage.list_files()
# For cloud vision API import cloudmersive_image_api_client from cloudmersive_image_api_client.rest import ApiException # Appwrite SDK from appwrite.client import Client from appwrite.services.storage import Storage FILENAME = "temp.jpg" # Triggered by the storage.files.create event payload = json.loads(os.environ["APPWRITE_FUNCTION_EVENT_DATA"]) fileID = payload["$id"] # Setup appwrite client client = Client() client.set_endpoint(os.environ["APPWRITE_ENDPOINT"]) client.set_project( os.environ["APPWRITE_FUNCTION_PROJECT_ID"]) # this is available by default client.set_key(os.environ["APPWRITE_API_KEY"]) # Get the image file storage = Storage(client) result = storage.get_file_preview(fileID) # Save the file to the container with open(FILENAME, "wb") as newFile: newFile.write(result) # Configure API key authorization: Apikey configuration = cloudmersive_image_api_client.Configuration()
from appwrite.client import Client from appwrite.services.foo import Foo from appwrite.services.bar import Bar from appwrite.services.general import General client = Client() foo = Foo(client) bar = Bar(client) general = General(client) client.add_header('Origin', 'http://localhost') client.set_self_signed() # Foo Tests print("GET:/v1/mock/tests/foo:passed") response = foo.post('string', 123, ['string in array']) print(response['result']) response = foo.put('string', 123, ['string in array']) print(response['result']) response = foo.patch('string', 123, ['string in array']) print(response['result']) response = foo.delete('string', 123, ['string in array']) print(response['result']) # Bar Tests
import json import os from appwrite.client import Client from appwrite.services.storage import Storage # Setup appwrite client client = Client() client.set_endpoint( os.environ["APPWRITE_ENDPOINT"]) # PRIVATE IP OF YOUR APPWRITE CONTAINER client.set_project(os.environ["APPWRITE_PROJECT"]) # YOUR PROJECT ID client.set_key(os.environ["APPWRITE_SECRET"]) storage = Storage(client) # result = storage.get_file(os.environ["APPWRITE_FILEID"]) print(os.environ["APPWRITE_FUNCTION_ID"]) print(os.environ["APPWRITE_FUNCTION_NAME"]) print(os.environ["APPWRITE_FUNCTION_TAG"]) print(os.environ["APPWRITE_FUNCTION_TRIGGER"]) print(os.environ["APPWRITE_FUNCTION_ENV_NAME"]) print(os.environ["APPWRITE_FUNCTION_ENV_VERSION"]) # print(result["$id"]) print(os.environ["APPWRITE_FUNCTION_EVENT"]) print(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"])
#Importing the required libraries import os import json import requests from appwrite.client import Client #Initialise the Appwrite Client SDK for Python client = Client() (client.set_endpoint(os.environ.get('APPWRITE_ENDPOINT')) #Your API Endpoint .set_project(os.environ.get( 'APPWRITE_FUNCTION_PROJECT_ID')) #Your Project ID available by default .set_key(os.environ.get('APPWRITE_API_KEY')) #Your secret API Key ) # #Initialise the Sendgrid Client SDK # sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) #Your Sendgrid API Key # Get the name and email of the new user from Appwrite's Environment variables payload = json.loads(os.environ.get('APPWRITE_FUNCTION_DATA')) recipient_id = payload['email'] print('recipient id: ', recipient_id) list_id = os.environ.get( 'SENDGRID_LIST_ID' ) # The Newsletter ID to which the new user has to be added print('list id: ', list_id) url = "https://api.sendgrid.com/v3/marketing/contacts" data = { "list_ids": [list_id],
# general imports import os from datetime import datetime, timedelta # dependencies from appwrite.client import Client from appwrite.services.storage import Storage # Setup appwrite client client = Client() client.set_endpoint(os.environ['APPWRITE_ENDPOINT']) client.set_project(os.environ['APPWRITE_PROJECT_ID']) client.set_key(os.environ['APPWRITE_API_KEY']) # storage object for given client storage = Storage(client) # gather all files available in given storage result = storage.list_files(limit=100) # datetime objects to compare with time of files days = int(os.environ['DAYS_TO_EXPIRE']) delete_at = datetime.now() - timedelta(days=days) deleted_files = 0 # iterating over files in storage and deleting according constraints for each in result['files']: if each['dateCreated'] < delete_at.timestamp(): storage.delete_file(each['$id']) deleted_files += 1
# -*- coding: utf-8 -*- """ Created on Fri Apr 23 12:35:22 2021 @author: danip """ from appwrite.client import Client from appwrite.services.users import Users from appwrite.services.avatars import Avatars from appwrite.services.teams import Teams client = Client() (client .set_endpoint('https://45.79.197.196/v1') # Your API Endpoint .set_project('60826fd53aa70') # Your project ID .set_key('0c8ea3659859b3c3c23e5b35644d4c07240f5356182c50acd37571c3144a1f91a55e4b541a8860734662238050a457f22cf803d721eb457352026f215e50234fe246975811ac03de59863128bb23c7153cdee01b7c2ed348f0e3c208faf22fac69777a54bdb2e60f77824dfa07d8f41c6f87355abe392c3938629de780a15f71') # Your secret API key ) teams = Teams(client) result = teams.list() result = teams.create_membership('608278d80a78b', '*****@*****.**', [], 'https://example.com') result result = teams.create('testestet') result = teams.get('608278d80a78b')
@author: danip """ from flask import render_template, redirect, url_for, flash, request, send_file, Flask, make_response, abort, jsonify, current_app from itsdangerous import URLSafeTimedSerializer # from db_operations import db, update_db_user_info, database from sentry_sdk.integrations.flask import FlaskIntegration from flask_cors import CORS, cross_origin from appwrite.client import Client from appwrite.services.users import Users from appwrite.services.avatars import Avatars from appwrite.services.teams import Teams client = Client() (client.set_endpoint('https://localhost:5858/v1') # Your API Endpoint .set_project('60826fd53aa70') # Your project ID .set_key( '0c8ea3659859b3c3c23e5b35644d4c07240f5356182c50acd37571c3144a1f91a55e4b541a8860734662238050a457f22cf803d721eb457352026f215e50234fe246975811ac03de59863128bb23c7153cdee01b7c2ed348f0e3c208faf22fac69777a54bdb2e60f77824dfa07d8f41c6f87355abe392c3938629de780a15f71' ) # Your secret API key ) teams = Teams(client) users = Users(client) app = Flask(__name__) cors = CORS(app)
print(err.user_message_text) sys.exit() else: print(err) sys.exit() # Add OAuth2 access token here. # You can generate one for yourself in the App Console. # See <https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/> TOKEN = os.environ['DROPBOX_KEY'] FILENAME = 'my-file.txt' BACKUPPATH = '/my-file.txt' # Setup the appwrite SDK client = Client() client.set_endpoint('http://192.168.1.6/v1') # Your API Endpoint client.set_project('5fca866c65afc') # Your project ID client.set_key(os.environ["APPWRITE_KEY"]) # Your secret API key # Get the ID of the uploaded file from the environment variable set by appwrite. payload = json.loads(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"]) fileID = payload["$id"] # Create an instance of Appwrite's Storage API storage = Storage(client) result = storage.get_file_download(fileID) # Save the file to the container with open(FILENAME, "wb") as newFile: newFile.write(result)
from appwrite.client import Client from appwrite.services.storage import Storage import io import PIL.Image as Image from secret_key import SECRET_KEY from project_data import PROJECT_ID, ENDPOINT_URL, FILE_ID client = Client() (client.set_endpoint(ENDPOINT_URL) # Your API Endpoint .set_project(PROJECT_ID) # Your project ID .set_key(SECRET_KEY) # Your secret API key ) storage = Storage(client) result = storage.get_file(FILE_ID) result = storage.get_file_download(FILE_ID) print(type(result)) if (isinstance(result, bytes)): image = Image.open(io.BytesIO(result)) image.save("./image.png")