Giter Club home page Giter Club logo

Comments (3)

ijoosong avatar ijoosong commented on August 15, 2024

Here's a quick snippet that might help that uses the Gremlin API from Python Functions:
in init.py
`import logging
import azure.functions as func
import ast
from ..shared_code import config
from gremlin_python.driver import client, serializer

def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

if req.method == "POST":
    byte_body = req.get_body()
    logging.info(thi)
    dict_body = ast.literal_eval(byte_body.decode("UTF-8"))

    f_p = dict_body['fp']
    s_p = dict_body['sp']

    try:
        x = client.Client('wss://' + config.endpoint + ':443/', 'g',
                            username='/dbs/' + config.database + '/colls/' + config.collection,
                            password=config.password,
                            message_serializer=serializer.GraphSONSerializersV2d0()
                            )
        
        query = f"g.V('{f_p}').addE('knows').to(g.V('{s_p}'))"
        logging.info("\tRunning this Grem query:\n\t{0}\n".format(query))

        callback = x.submitAsync(query)
        if callback.result() is not None:
            logging.info("\tInserted this edge: \n\t{0}\n".format(callback.result().one()))
        else:
            logging.info("Something went wrong")
    except Exception as e:
        logging.info("there was an exception: {0}".format(e))
    return func.HttpResponse(f"Hello {f_p}")

`

my function.json looks like this:
{ "scriptFile": "__init__.py", "bindings": [ { "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req", "methods": [ "get", "post" ] }, { "type": "http", "direction": "out", "name": "$return" } ] }

and then take a look here: https://github.com/Azure-Samples/azure-cosmos-db-graph-python-getting-started/blob/master/connect.py

Hope this helps!

from azure-functions-python-library.

stefanushinardi avatar stefanushinardi commented on August 15, 2024

Will route this VS Code Extension

from azure-functions-python-library.

shreyabatra4 avatar shreyabatra4 commented on August 15, 2024

Routed to VS Code asks

from azure-functions-python-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.